Fwd: Re: [Techtalk] Joining commands together in bash

Berenice showercurtain2000 at yahoo.com
Sun May 11 23:58:14 EST 2003


--- Meredydd <meredydd at everybuddy.com> wrote:
> From: Meredydd <meredydd at everybuddy.com>
> To: Berenice <showercurtain2000 at yahoo.com>
> Subject: Re: [Techtalk] Joining commands together in bash
> Date: Sun, 11 May 2003 13:55:42 +0100
> 
> Replying offlist because you sent offlist, but did you mean this to
> be on-list? If so, feel free to forward/publically reply to this
> message.
> 
> OK, this is a combination of a couple of Bourne shell quirks. First
> is the sublime backtic (``) operator. It executes the command 
> inside, and evaluates to its standard output. So, for example,
`echo > hi` is the same as "hi", and `cat /some/file` is the contents
of 
> /some/file. In the example I gave, `file $FILE | grep 'shell script
> text executable'` means the output of that command. Because $FILE
is > the individual file concerned, there will only ever be any
output if > that file is a shell script.
> 
> I then use the "if" command to check whether it is indeed empty.
> The x thing is a work-around for some brain-dead old
implementations > of the Bourne shell, /bin/sh - namely, that they
had no idea of an 
> empty string. In bash, which is 
> sensible, I could do the following:
> 
> if [ $myvar = "" ]; then
> 	do something
> fi
> 
> It's just old, old shells which don't support this, but programming
> defensively is a good habit. This technique puts an extra letter
> onto the beginning (not end, in case the shell might have trouble 
> figuring out whether the variable is "myvar" or "myvarx") of the 
> expression, so instead I have:
> 
> if [ x$myvar = "x" ]; then
> ...
> 
> The "x", of course, is purely arbitrary - just a generic something.
> Unless you want to make shell scripts which should work anywhere at
> all, you will probably never need it.
> 
> Oh yes, one final thing you may or may not know already - the
> bourne shell doesn't regarded quoted and unquoted expressions as 
> different. So,all the following are the same:
> 
> hello
> "hello"
> 'hello'
> 
> You just use quotes when handling weird characters such as spaces, 
> backslashes, etc, but i'm guessing you know all the rules for
> those.
> 
> Meredydd
> 
> On Sunday 11 May 2003 13:15, you wrote:
> > Thanks for the quick reply.  What you've suggested makes sense,
> > but could you explain how the following works:
> > >    x`file $FILE | grep 'shell script text executable'` != x
> >
> > I'm new to bash and this is the first time I've seen this type of
> > statement that checks if output is empty.  What's "x" for and
> > what do those backquotes do?
> >
> > Thanks
> > Berenice
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com


More information about the Techtalk mailing list