Nicola Bernardelli wrote:
> 
> GNU bash, version 1.14.7(1)
> su - GNU sh-utils 1.12
> (Debian 1.2.4, going to get room for 1.3.1 soon.)
> 
> VAR=<command options arg> ; export VAR
> 
> Calling su like this
>      echo $VAR | su - <user>
> gives a "stdin: is not a tty" message but does a fine job.
> 
> Calling su in this other way
>      su - <user> -c $VAR
> results in ANYTHING AFTER THE FIRST SPACE CHARACTER to be executed, that
> is only <command>.
> 
> No problems if I _write_ on the command line what had to be taken from
> $VAR:
>      su - <user> -c <command options arg>
> 
> -------------------------- EXAMPLE --------------------------
> nick:~/test# ls -l
> total 3
> -rw-r--r--   1 root     root           20 Sep 10 16:26 file1.cat
> -rw-r--r--   1 root     root           30 Sep 10 16:27 file2.cat
> -rw-r--r--   1 root     root           46 Sep 10 16:27 file3.cat
> nick:~/test# COMMAND='ls -l /root/test' ; export COMMAND
> nick:~/test# echo $COMMAND | su - nbern
> stdin: is not a ttytotal 3
> -rw-r--r--   1 root     root           20 Sep 10 16:26 file1.cat
> -rw-r--r--   1 root     root           30 Sep 10 16:27 file2.cat
> -rw-r--r--   1 root     root           46 Sep 10 16:27 file3.cat
> nick:~/test# su - nbern -c $COMMAND
> --cut--
> --cut--
> 
> <^ Here I get the same as from 'ls' done inside /home/nbern, that is
> COMMAND has been truncated to ls; it does not happen if I explicitly copy
> the content of $COMMAND to the command line: >
> 
> nick:~/test# su - nbern -c 'ls -l /root/test'
> total 3
> -rw-r--r--   1 root     root           20 Sep 10 16:26 file1.cat
> -rw-r--r--   1 root     root           30 Sep 10 16:27 file2.cat
> -rw-r--r--   1 root     root           46 Sep 10 16:27 file3.cat
> nick:~/test#
> -------------------------------------------------------------
> 
>      Am i missing something?

In:

  su - nbern -c 'ls -l /root/test'

this            ^^^^^^^^^^^^^^^^^^ is passed a single parameter. If
you program C or perl, you know what I mean. If instead you typed

  su - nbern -c ls -l /root/test

you'd get the same results as when you do

  su - <user> -c $VAR

This is becuase the variable substition (as well as file globbing and
other stuff) is done *before* chopping the line up into "tokens" or
"parameters" or whatever you wish to call them. The answer to your
problem is to do:

  su - <user> -c "$VAR"

(One reason why we need quotes which both allow and disallow substition)

-- 
Jens B. Jorgensen
[EMAIL PROTECTED]


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
[EMAIL PROTECTED] . 
Trouble?  e-mail to [EMAIL PROTECTED] .

Reply via email to