Bash Scripting

Michael Wittman plug-discuss@lists.plug.phoenix.az.us
Sun, 14 Apr 2002 14:01:48 -0700


On Sun, Apr 14, 2002 at 12:44:10AM -0700, Lynn David Newton wrote:
> 
>   b> Unfortunately, bash doesn't put the executed
>   b> output in the variable, it puts the text itself
>   b> in. Any other ideas?
> 
> I see in later mail you found a solution, but I see a
> problem here. 
> 
>   >> #!/bin/sh
>   >> 
>   >> USER=bryce
>   >> NFSMOUNT=somenfsmount
>   >> FILENAME=somefilename
>   >> COMPUTERNAME=`uname -n`
>   >> DATE=`date +%m-%d-%y`
>   >> DIRECTORYTOBU=somedirectorytobu
>   >> 
>   >> su $USER -c "cd /home/$USER; tar czf \
>   >> $NFSMOUNT/$FILENAME.$COMPUTERNAME.$DATE.tar.gz $DIRECTORYTOBU/"
> 
> Does the last statement get the values set? su runs in
> a subshell. Isn't it necessary to export the variables
> for this to work?

Yes, and no.  When quoting with double quotes, the variables get
replaced by their values before passing the string to the su command.
If you were to quote with single quotes, the variables wouldn't get
replaced by their values and you would have to export them so that
they could get replaced by the shell run by the su command.

-Mike