changing dir inside shell
Root Boy Jim
rbj at nav.icst.nbs.gov
Thu Jul 28 03:35:51 AEST 1988
? From: bianco at uxe.cso.uiuc.edu
? I have the following in a file called 'mover':
? cp *.me /usr/tmp
? cd /usr/tmp
? Upon entering 'sh mover' the files are copied, and the directory is
? changed, however the shell is then exited and the current directory
? is changed back to my home directory. How can I cause the shell to exit
? in the directory I changed to ?
The bad news is that you can't, at least not the way you are doing it.
The good news is that you can, if you do it in other ways.
The problem is that `mover' is being executed by a subshell, and when it
goes away, the parent's working directory is unchanged. Solutions:
1) If `sh' or `ksh' is your parent shell, type ". mover".
You may also use shell functions, or even aliases if you prefer.
2) If `csh' is your parent shell, type "source mover".
You may also use aliases here.
Note that sourcing a file is less flexible, as you cannot pass any
parameters ($1, $2, etc) to it. With shell functions and aliases you can.
? -nick bianco at uiuc.uxe.cso.edu or bianco at uiucvmd.cso.uiuc.edu
(Root Boy) Jim Cottrell <rbj at icst-cmr.arpa>
National Bureau of Standards
Flamer's Hotline: (301) 975-5688
The opinions expressed are solely my own
and do not reflect NBS policy or agreement
Careful with that VAX Eugene!
More information about the Comp.unix.questions
mailing list