[plug] bash, echo and tabs

Steve Boak sboak at westnet.com.au
Wed Aug 6 12:58:18 WST 2008


Thanks Matt and Lucas

Both useful suggestions. I think I'll go with the printf solution below,
much cleaner and more flexible for what I want to do.

Steve

> 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
>
> _______________________________________________
> PLUG discussion list: plug at plug.org.au
> http://www.plug.org.au/mailman/listinfo/plug
> Committee e-mail: committee at plug.linux.org.au
>


-- 
Steve Boak, (08) 9756 0662, P.O. Box 240, Nannup, WA 6275
Nannup Telecentre IT support, ph (08) 9756 3022
Engin (VoIP) number (08)64616187 (Local number in Perth)




More information about the plug mailing list