Re: Short script which worked in Lenny but does not in Squeeze.
On 2013-07-24 19:44 +0200, Ken Heard 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.
This happens because /bin/sh points to dash in squeeze, and dash does
not set HOSTNAME because POSIX does not require that.[1]
Either use /bin/bash as interpreter or make sure that HOSTNAME is set
before using it, e.g. with "HOSTNAME=${HOSTNAME:-$(hostname)}".
Cheers,
Sven
1. https://bugs.launchpad.net/ubuntu/+source/dash/+bug/64184
Reply to: