Re: stupid shell tricks again

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Craig White
Date:  
To: plug-discuss
Subject: Re: stupid shell tricks again
On Tue, 2004-03-23 at 08:23, Bill Jonas wrote:
> 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.

----
and so goes my gremlin from Redmond theory down the drain.

Q. When is a tab not a tab?
A. When a shell script inexplicably substitutes spaces for the tab.

od - octal dump - nice trick - thanks for sharing. I have to file that
away in my brain so it can get lost with other poorly indexed material.
I kept dumping variables to the screen and to files but this makes it
easy to see.

Craig

---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss