Newsgroups: comp.unix.questions Path: utzoo!utgpu!utfyzx!sq!lee From: lee@sq.sq.com (Liam R. E. Quin) Subject: Re: Using \"cd\" in a bourne shell script Message-ID: <1989Nov11.053512.20361@sq.sq.com> Reply-To: lee@sq.com (Liam R. E. Quin) Organization: Unixsys (UK) Ltd References: <21381@adm.BRL.MIL> Date: Sat, 11 Nov 89 05:35:12 GMT John Gayman wrote: >> I'm trying to use "cd" in a bourne shell script >> [...] I end up in the same directory I started from. danl@midget.towson.edu writes: >you could execute it as: > $ . script_name If you are using the System V shell (or SunOS /bin/sh these days), you could also define a shell function: start(){ date who cd /users } Put this -- and any others you invent -- in a standard place, such as /usr/local/lib/sh-functions, make it executable with chmod +x, and add if [ -x /usr/local/lib/sh-functions ] then . /usr/local/lib/sh-functions fi into either /etc/profile (at the end) or the users' own .profiles. Then they don't need to type the dot. This question seems to come up a lot, but this particular (somewhat pragmatic) solution seems not to be suggested often, so I have posted it here. Lee -- Liam R. Quin, Unixsys (UK) Ltd [note: not an employee of "sq" - a visitor!] lee@sq.com (Whilst visiting Canada from England) lee@anduk.co.uk (Upon my return to England at Christmas)