Path: utzoo!utgpu!attcan!uunet!husc6!cmcl2!brl-adm!adm!rbj@nav.icst.nbs.gov From: rbj@nav.icst.nbs.gov (Root Boy Jim) Newsgroups: comp.unix.questions Subject: changing dir inside shell Message-ID: <16654@brl-adm.ARPA> Date: 27 Jul 88 17:35:51 GMT Sender: news@brl-adm.ARPA Lines: 33 ? From: bianco@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@uiuc.uxe.cso.edu or bianco@uiucvmd.cso.uiuc.edu (Root Boy) Jim Cottrell 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!