Subject: Re: cd success?
To: Jan Danielsson <jan.m.danielsson@gmail.com>
From: Chavdar Ivanov <ci4ic4@gmail.com>
List: netbsd-users
Date: 01/26/2007 08:12:56
On 1/26/07, Jan Danielsson <jan.m.danielsson@gmail.com> wrote:
> Hello all,
>
> I have a script which contains the line:
>
> rm -Rf *
>
> As you might imagine, I'm somewhat afraid that script might run amok.
> It shouldn't, obviously, but Just In Case... Is there any way to
> determine if a "cd" was successful or unsuccessful?
>
> The script does this:
>
> cd ~/backup/foo
> rm -Rf *
>
> Currently, if the cd-command fails, I will have to kill myself. I
> don't want to do that. If I remember correctly, there's a variable,
> something like $? which gets set to the return code. Is that set for
> internal shell commands as well?
>
> Or should I use some:
>
> if [ `pwd` == "~/backup/foo" ] ; then
> echo "Phew!...
> fi
>
> ..instead?
Just
$ cd /nonexistent && echo BAH
ksh: cd: /nonexistent - No such file or directory
$ cd /tmp && echo BAH
BAH
>
> --
> Kind regards,
> Jan Danielsson
>
>
>
>
>
Chavdar