[SLUG] bash shell script question

From: Jan Mason (td376@mail.anonymizer.com)
Date: Sun Sep 15 2002 - 00:08:50 EDT


In test case 1, when a "~" is passed in as a parameter it is substituted
for $HOME and the script works.

In test case 2, when no parameter is passed and the "~" is assigned to
the var $directory using the read command, $HOME is not substituted for
"~" and the script does not work.

How do I get test case 2 to work?

bash shell script named green:

     directory=$1
     if [[ $directory = "" ]]
     then
         echo -n "prompt for dir: "
         read directory
     fi
     echo "dir = "$directory
     pwd
     cd $directory
     pwd

Test case 1 output:

$ green ~
dir = /home/jan
/home/jan/bin
/home/jan

Test case 2 output:

$ green
prompt for dir: ~
dir = ~
/home/jan/bin
/home/jan/bin/green: cd: ~: No such file or directory
/home/jan/bin

-- 
Jan Mason
td376@mail.anonymizer.com



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:34:30 EDT