Re: help, help scripting masters

From: Arthur Corliss <acorliss@nevaeh-linux.org>
Date: Mon Mar 22 2004 - 11:32:23 AKST

On Mon, 22 Mar 2004, David J. Weller-Fahy wrote:

> And, after reading all that again, I just realized that my problems (way
> back when) were probably caused by the lack of double quotes, not by the
> lack of braces. So it's very likely that the use of braces is a red
> herring in this case.

In terms of the previous embedded whitespace issue, that is correct, braces
have no impact on that. The problem lies in the order of operations within
the script engine. The reason why this doesn't work:

  foo="bar bar"
  mv $foo $foo.bak

is that variable interpolation occurs before actual command is executed. In
terms of C the command is executed by the system() command by the interpreter,
not forked & execv()'ed with each variable's value handed to the call as an
array member. So, the above command is translated as:

  mv bar bar bar bar.bak

and handed as a string to the subshell, which uses the field separator (white
space) to delimit the arguments. Adding the double quotes around the variable
tells the subshell to ignore field separators within the quoted space and
treat the entire string as one argument.

I suppose that one could make the case that this method of handling is less
intuitive, but then, there are many common cases in which you'd want the field
separator to be recognised, such as:

  FILES="foo bar"
  mv $FILES archived/

        --Arthur Corliss
          Bolverk's Lair -- http://arthur.corlissfamily.org/
          Digital Mages -- http://www.digitalmages.com/
          "Live Free or Die, the Only Way to Live" -- NH State Motto
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Mon Mar 22 11:31:57 2004

This archive was generated by hypermail 2.1.8 : Mon Mar 22 2004 - 11:31:57 AKST