changing dir inside shell
Ian Kluft
kluft at hpcupt1.HP.COM
Wed Jul 27 05:50:18 AEST 1988
bianco at 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 at hpda.hp.com Cupertino, CA
------------------------------------------------------------------
More information about the Comp.unix.questions
mailing list