[X-Unix] A little shell scripting help

Larry Helms lhelms at sonic.net
Tue Oct 4 09:54:20 PDT 2005


> 
> At 02:35 -0700 10/4/05, Philip J Robar wrote:
>> '[' has been a built-in in all modern shells that use it for years.  The '['
>> in /bin is just there for compatibility.
> 
> Most interesting. Why then is the space still required?

Spaces are delimiters.  It helps the parsing mechanism understand where to
break things up... As stated before 'test' requires a space after it...
[ = test 

Essentially you should think of your script as being written like this:

    if test $retry > 1 then

If you leave out the space... It becomes syntactically incorrect:

    if test$retry > 1 then

Because the shell will do THIS

    if test1 > 1 then

before processing the line (because retry=1)... THAT is why the spaces are
necessary.

PLUS SPACES make your script more readable.

> 
>> You should read <http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/>  if you
>> haven't already.
> 
> Been there and done that. It still makes no mention of the Debian tcsh. And no
> shell wars please. Susan Anthony's God wants me to use tcsh, but thank God
> others can, even in AppleScript, use what they like.

WHO is Susan Anthony???  I would suggest sending her to read that link.

Please understand... That you CAN write scripts in shells that are NOT the
default login shell.  It is best to use a shell that best meets your
requirements.  Remember... Just because we can do a thing (write in tcsh)
doesn't mean we should do a thing.



More information about the X-Unix mailing list