using cd command in a file

David Sandberg dts at quad.sialis.com
Tue May 28 07:26:12 AEST 1991


In article <1991May27.170005.12870 at xzaphod.uucp> michael at xzaphod.UUCP (Michael R. Miller) writes:
>A script won't work because "cd" is a "built in" command in every shell
>I've heard of.

Whether cd is builtin or not has nothing to do with the reason a
"cd script" won't work.  Rather, it's because each process has
it's own idea of what is the current working directory.  New
processes inherit the current working directory from their parent
process, but not visa versa.

I also have to wonder why you made the above statement when, in
the very next paragraph, you described why a "cd script" doesn't
work in an essentially correct fashion.  But then you got screwed
up again and closed your article with the following:

>A modification to the script command could be:
>
>#!/bin/sh
>exec $SHELL -c "cd /me/A/B/C/D"

Huh?  I hate to tell you this, but your modified script won't
work any better than the original, since you're still running the
cd command in a subshell.  In fact, your suggested change makes
it worse if anything... it accomplishes the same thing as the
other (nothing, that is) and takes more processes to do it.

>If your shell supports aliases (/bin/ksh, /bin/csh, /bin/zsh), use it.

Agreed.  I said as much a week ago via email to the original
person who posed the question, thinking that it was too obvious
of a question to post a public reply to.  Heh... I should've
known better, I guess.

-- 
 \*=-      David Sandberg, dts at quad.sialis.com    ,=,       ,=,        -=*\
  \*=-   "like words whispered by waking ghosts   | |uadric `=,ystems   -=*\
   \*=-   that in my ears muttered" - Torhthelm   `=\       `='          -=*\



More information about the Comp.unix.questions mailing list