Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!nosc!ucsd!ucsdhub!hp-sdd!hplabs!hpda!hpcupt1!kluft From: kluft@hpcupt1.HP.COM (Ian Kluft) Newsgroups: comp.unix.questions Subject: Re: changing dir inside shell Message-ID: <6060015@hpcupt1.HP.COM> Date: 26 Jul 88 19:50:18 GMT References: <47800013@uxe.cso.uiuc.edu> Organization: HP Systems Technology Div, Cupertino CA Lines: 32 bianco@uxe.cso.uiuc.edu writes: > > 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 ? That depends on which version of the Bourne Shell (assumed from the "sh" in your example) you're using. If you're on System V Release 2 or later (or using the Korn Shell), you're in luck. The solution comes down to one thing: you must do the 'cd' in your interactive shell. You can have it do it for you using shell functions. Put the following example in your .profile: mover() { cp *.me /usr/tmp cd /usr/tmp } If you don't have shell functions, there's still a solution but it's not quite as nice. You can type ". mover" instead of "sh mover" to force it to do the script in your interactive shell. ------------------------------------------------------------------ Ian Kluft RAS Lab UUCP: hplabs!hprasor!kluft HP Systems Technology Division ARPA: kluft@hpda.hp.com Cupertino, CA ------------------------------------------------------------------