On 02/19/2017 07:22 AM, Mike Wright wrote:
Hi all,
My brain cell ran away from home. I have an incredibly simple script that doesn't do
what I expect. I use "mkdir DIR; cd DIR" a lot so I'm trying to put it in a
script: "~/bin/mdcd".
After checking that $1 exists:
dir="$1"
mkdir -p "$dir"
cd "$dir" <------ never executes
The script runs in a child process. It changes its _own_ working directory and then exits,
leaving the parent shell exactly where it was before. Scripts like that need to be
_sourced_, not simply executed. It probably makes sense to set up an alias to do that:
alias mkdirp=". mkdirp.sh"
Then you can type "mkdirp /wherever/whatever" and it will run ". mkdirp.sh
/wherever/whatever".
--
Bob Nichols "NOSPAM" is really part of my email address.
Do NOT delete it.