I have two scripts. One is :
Code:
#!/bin/bash
if [ $1 = 1 ]; then
dir=mydir-1.6_
else
dir=mydir
fi
cd ~/code/${dir}$2
echo $(pwd)
The above script changes directories even though there are several posts that say that since a script is run in a sub-shell it should have no effect on the executing shell.
Now I have another script:
Code:
#!/bin/bash
dir=/WORK/temp/$1
mkdir -p $dir
cd $dir
wget http://somurl.com/archive.zip
unzip archive.zip
The above script unzips the file in the expected directory but leaves the calling shell in the same directory. What is the difference when cd is called in both scripts?
Bookmarks