You could cheat a little:
CHDIR=/usr/newFolder
echo “cd ${CHDIR}” > ./changeEnv
. ./changeEnv
Bill Corcoran
On Oct 21, 2019, at 6:52 AM,
"jason-tuhs(a)shalott.net" <jason-tuhs(a)shalott.net> wrote:
> % pwd
> /usr/ken
> % cd /tmp
> % pwd
> /usr/ken
>
> Aha!
I'm old and slow, had to think about that
one. Aha indeed!
I've actually been asking this (or, as a variation, how a child can set environment
in its parent) as an interview question for unix sysadmins for the past fifteen or so
years. Maybe one in three gets it.
The answer that I'm secretly hoping for, no one has ever yet given me:
hashbrown/home/jason-112719: /bin/pwd
/home/jason
hashbrown/home/jason-112720: ./cd.sh /tmp
hashbrown/home/jason-112721: /bin/pwd
/tmp
hashbrown/home/jason-112722: cat cd.sh
cat: cd.sh: No such file or directory
hashbrown/home/jason-112723: cat ~/cd.sh
#!/bin/sh
test -n "$1" && TARGET=$1 || TARGET=$HOME
( echo "call (int) chdir(\"$TARGET\")" ; echo detach ; echo quit ) |
gdb -q -p $PPID >/dev/null 2>&1 &
"With ptrace(2) all things are possible."
-Jason