Re: stupid shell tricks again

Top Page
Attachments:
Message as email
+ (text/plain)
+ (application/pgp-signature)
Delete this message
Reply to this message
Author: Bill Jonas
Date:  
To: plug-discuss
Subject: Re: stupid shell tricks again
On Mon, Mar 22, 2004 at 09:45:17PM -0700, Craig White wrote:
> specific reference to the delimiter. Apparently, the result of the
> command that 'echo string' | cut somehow modifies the tab where it isn't
> identified as a tab - that was sort of clear when Bill Jonas made the
> delimiter suggestion and it worked.


It seems to be whether or not du can determine that the output is a
terminal or not.

$ uname; uname -r
Linux
2.6.3-gentoo-r1
$ echo $BASH_VERSION 
2.05b.0(1)-release
$ mkdir foo
$ du foo
4       foo
$ du foo |od -c
0000000   4  \t   f   o   o  \n
0000006
$ du foo |head -n 1 |od -c
0000000   4  \t   f   o   o  \n
0000006
$ i=`du foo`; echo $i
4 foo
$ i=`du foo`; echo $i |od -c
0000000   4       f   o   o  \n
0000006
$ echo `du foo` |od -c
0000000   4       f   o   o  \n
0000006
$ echo "`du foo`" |od -c
0000000   4  \t   f   o   o  \n
0000006
$ i="`du foo`"; echo $i |od -c
0000000   4       f   o   o  \n
0000006
$ du foo |while read line; do echo "$line" |od -c; done
0000000   4  \t   f   o   o  \n
0000006
$ du foo |while read line; do echo $line |od -c; done
0000000   4       f   o   o  \n
0000006


I unfortunately don't have a BSD box set up, so I can't test it there,
but I do have access to a machine running another Unix:

$ uname; uname -r
SunOS
4.1.4
$ echo $BASH_VERSION 
1.14.0(1)
$ mkdir foo
$ du foo
1       foo
$ du foo |od -c
0000000    1  \t   f   o   o  \n
0000006
$ du foo |head -1 |od -c
0000000    1  \t   f   o   o  \n
0000006
$ i=`du foo`; echo $i
1 foo
$ i=`du foo`; echo $i |od -c
0000000    1       f   o   o  \n
0000006
$ echo `du foo` |od -c
0000000    1       f   o   o  \n
0000006
$ echo "`du foo`" |od -c 
0000000    1  \t   f   o   o  \n
0000006
$ i="`du foo`"; echo $i |od -c
0000000    1       f   o   o  \n
0000006
$ du foo |while read line; do echo "$line" |od -c; done
0000000    1  \t   f   o   o  \n
0000006
$ du foo |while read line; do echo $line |od -c; done
0000000    1       f   o   o  \n
0000006


Seems that echo(1), without double-quotes, is substituting a space for
any of the values of $IFS, although I'm still puzzled by the variable
assignment issue. At least the behavior seems to be fairly consistent
across Unices.

-- 
Bill Jonas    *        *    http://www.billjonas.com/
"It's a dangerous business, Frodo, going out your front door.  You step
into the Road,  and if you don't keep your feet,  there  is  no knowing
where you might be swept off to."  --  Bilbo Baggins