[plug] bash, echo and tabs
Matt Kemner
zombie at penguincare.com.au
Wed Aug 6 12:14:26 WST 2008
Hi Steve
On Wed, 6 Aug 2008, quoth Steve Boak:
> however if I type "echo `df -h /mnt`", I get
> Filesystem Size Used Avail Use% Mounted on /dev/hda3 2.0G 125M 1.9G 7% /
> with all the tabs and the CR replaced by spaces.
Instead of using echo (which replaces those whitespace characters as
you've discovered" try using printf(1) which is designed to format text
exactly how you want it - there are printf() functions or equivalents in
most programming languages, and the command line version works much the
same.
For example try:
printf "%s\n" "`df -h /mnt`"
man 1 printf for more info on the command line program, and
man 3 printf for info on the C function it implements (to see what
formatting flags are available)
- Matt
More information about the plug
mailing list