What I'm trying to do:
write a script that will list all the directories in a given location. Ask the user to enter a number corresponding to the location of the directory in the list, and then moving into that directory.
I have written a script to do this, but it only works when I run it as:
<user>$program_name
and the script runs in a sub-shell. But, when it is run in a sub-shell, the changes made by the script go away after the script ends.
When I run it as:
<user>$. program_name
and the script runs in the current source shell, I get an error:
bash: cd: /home/dev/Project/dirname: No such file of directory
does anyone have any ideas how to get this done??
Code:
IFS='
' read -d '' -a ArrName < <(ls ~/Projects)
read filenumber
cd $HOME/Projects/${ArrName[$filenumber]}