I know what I can make a shell procedure or source the script instead of running it to cd the shell I am using. What I want to know is there any way to cd the parent shell (not sure if that is the correct phrase).#!/bin/sh# This is script.shcd $1pwdHere's some output. (Note: this isn't the exact output, I just shortened it by stripping out unnecessary details. Lines that are my input into the shell begin with >.)> mkdir foo> ./script.sh foo/home/myName/foo> pwd/home/myNameThis is expected behavior as I understand. Here is if I source the script.> . ./script.sh foo/home/myName/foo> pwd/home/myName/fooWithout sourcing the script and without making this a shell procedure, is there any way to type ./script.sh foo result in the shell I am using be in the directory /home/myName/foo?
Change dir from script without a shell procedure or sourcing the script
bash;shell script;cd command
No, because when you invoke a script as ./script.sh foo, it starts a subshell to run the script in for you. When that subshell exits, you're placed back in to the directory you were in when you started that script. You can counterfeit this behavior, though, by using a script that does something like this:#!/bin/bashcd $1bashThis will put you into a subshell after changing directories, which you then have to exit to get back to your original shell.If you instead make the last line:exec bashYou will not have to exit the new shell, because the new shell will replace the old shell. Doing this does, however, remain an ugly hack (IMHO).