Re: help, help scripting masters

From: Arthur Corliss <acorliss@nevaeh-linux.org>
Date: Mon Mar 22 2004 - 22:50:04 AKST

On Mon, 22 Mar 2004 bryan@ak.net wrote:

> You know what, I can help you with this one.
> The problem is in this line:
>
> > FOLDER=`echo $2`
>
> The phrase enclosed in `` gets replaced with the output of the
> command inside. The echo command spits out what's on its command
> line. So, if $2 has the value "folder with spaces" (no quotes),
> then
>
> FOLDER=`echo $2`
>
> will be replaced with
>
> FOLDER=folder with spaces
>
> Note that the spaces are no longer quoted or otherwise included in
> the string. The shell will make the assignment FOLDER=folder, and
> then try to execute the "with" command.

I don't mean to be disagreeable, but I have to disagree with this. Even in
this case the back-ticks should preserve atomicity. Keep in mind that
back-ticks are not executed in the same manner as variable interpolation, in
this case back ticks capture the entire STDOUT of the subshell and assign it
to the variable. Try something slightly more verbose as a test:

  acorliss@bifrost:~/test$ ls -l
  total 4
  drwxr-xr-x 2 acorliss corliss 18 Mar 22 22:30 foo
  drwxr-xr-x 2 acorliss corliss 19 Mar 22 22:30 foo bar
  -rwxr-xr-x 1 acorliss corliss 127 Mar 22 22:21 test.sh
  acorliss@bifrost:~/test$ OUT=`ls -l`
  acorliss@bifrost:~/test$ echo $OUT
  total 4 drwxr-xr-x 2 acorliss corliss 18 Mar 22 22:30 foo drwxr-xr-x 2
  acorliss corliss 19 Mar 22 22:30 foo bar -rwxr-xr-x 1 acorliss corliss 127 Mar
  22 22:21 test.sh

As you can see record separators in this case are handled much the same as
field separators, but that's the only weirdness that should be exhibited
(which is due to the fact that the shell won't try to handle unquoted newlines
as an argument since they clearly terminate the list of args to begin with).

If, for whatever reason, his shell actually does act in the way that you're
describing above I would have to suggest that it's a bug in the shell, and
should be reported.

        --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 22:49:39 2004

This archive was generated by hypermail 2.1.8 : Mon Mar 22 2004 - 22:49:39 AKST