I have a simple script /root/bin/mupdt
which contains the following:
#This script will print the date plus a comment
#to the file called $MAINT_FILE.
echo "" >> $MAINT_FILE
echo "[$(date +%d)$(date +%b)$(date +%y) $(date +%H:%M:%S)] $1" >> $MAINT_FILE
I have the following environment variable declared:
me@mycomputer:~$ env | grep MAINT_FILE
I've tried to run this script from my non-root account by typing:
me@mycomputer:~$ sudo /root/bin/mupdt "this is a test"
but I get the error:
/root/bin/mupdt: line 6: $MAINT_FILE: ambiguous redirect
/root/bin/mupdt: line 7: $MAINT_FILE: ambiguous redirect
If I run the script as root there's no problem:
root@mycomputer# /root/bin/mupdt "this is a test"
root@mycomputer# cat $MAINT_FILE | tail -n 1
[31May07 04:53:23] this is a test
What is it that becomes ambiguous when I run it as a normal user? How can I make it so that it's no longer ambiguous?