Ken Heard grabbed a keyboard and wrote:
> My amateur's attempt at scripting has come to grief. The script in
> question reads as follows:
>
> #!/bin/sh
> # Shell script to create a tgz file for the contents of the
> # /usr/local/bin directory.
> # Start by creating a variable with the current directory.
> CURPWD=$PWD
> # Change directory to /.
> cd /
> # Create a variable for the name of the tgz file.
> ULB="$HOSTNAME"usrlocalbin.tgz
> # Create the tgz file in the specified directory.
> tar -czf /media/zd/$ULB usr/local/bin
> # Return to the original directory.
> #cd $CURPWD
>
> In both Lenny and Squeeze the $HOSTNAME value is BDS; the script
> consequently created in Lenny the tarball BDSusrlocalbin.tgz located
> in a Zip750 disk mounted at /media/zd. (Yes, the disk was properly
> mounted.) In Squeeze however the tarball is created but without the
> $HOSTNAME added at the beginning of the file name.
>
> What I find strange is that in Squeeze each command line in the script
> run independently in succession achieves the desired result. After
> doing so running "echo $ULB" returns the assigned value. Eliminating
> the creation of $ULB and entering "$HOSTNAME"uslocalbin.tgz directly
> into the tar command in the script also does not produce the desired
> result.
>
> So something must be happening to prevent the tar command from using
> the $ULB variable. Is there for example something different in
> Squeeze which does not permit scripts written for Lenny to work in
> Squeeze? Comment, suggestions, anyone?
The problem is that as of Squeeze, /bin/sh is no longer a link to bash,
it's a link to dash. Change the first line to !#/bin/bash - that should
fix your problem. (dash doesn't expand those variables)
--Dave
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature