I used 'change directory' in my shell script (bash)
#!/bin/bash alias mycd='cd some_place' mycd pwd
pwd
prints some_place
correctly, but after the script finished my current working directory doesn't change.
Is it possible to change my path by script?
Trying to use cd inside the shell script does not work because the shell script runs in the subshell and once the script is over it returns to the parent shell, which is why the current directory does not change.
CONT'D (an abbreviation for continued) should be written next to the character's name to indicate that their speech is continued.
You need to source the file as:
. myfile.sh
or
source myfile.sh
Without sourcing the changes will happen in the sub-shell and not in the parent shell which is invoking the script. But when you source a file the lines in the file are executed as if they were typed at the command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With