I would like to create (and execute) a shell script in my home directory (/home/user).
Have tried the following:
printf "cd /mypath\n" > myShortcut.sh
chmod +x myShortcut.sh
sh myShortcut.sh
where am I going wrong?
(am trying to set up a shortcut to navigate to a different directory)
If you want to execute the script in the current shell (as opposed to in a subshell), use the
source(or.) command:This should then change the directory as expected.
In addition, sourcing also allows you to set and change environment variables in the current shell–a very frequent question in its own right 🙂