[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to make 'cd' errors stop a rule?

From: David Boyce
Subject: Re: How to make 'cd' errors stop a rule?
Date: Sun, 04 Dec 2005 23:46:40 -0500

At 10:13 PM 12/4/2005, Dave Hylands wrote:
HI Tommy,

On 12/4/05, Tommy Nordgren <address@hidden> wrote:
> Splitting into two lines won't work, since that will change how the
> command works


> if the directory exists.
> Instead use:
>         cd bogus-this-is-not-a-real-directory && ls -l

It was on the tip of my tongue to suggest that, but somehow I thought
it would complicate things - Sigh,

The full story is a little more complicated than this, however. Although the OP didn't mention a platform it's presumably Linux, because for complex historical reasons[*] the real Bourne shell treats cd differently from other commands; it NEVER continues past a failed cd whether you use "&&" or ";". See below, on Solaris:

% /bin/sh -c "false; date"
Sun Dec  4 22:38:21 EST 2005

% /bin/sh -c "cd /fgfgfgfg; date"
/bin/sh: /fgfgfgfg: does not exist

So the situation the OP describes is impossible on a traditional Unix system and the provided solution wouldn't help anyway.

I don't have access to a Linux machine at the moment. However, when I take the same Makefile and add SHELL=/bin/bash, both problem and solution are as described. Bash is supposed to behave in a Bourne-compatible manner when invoked as /bin/sh, so as I see it either (a) the OP has set SHELL=/bin/bash in the makefile and not told us or (b) bash is incompatible with Bourne in this way.

-David Boyce

[*] "Complex historical reasons" means that I read about why the shell treats cd specially once but don't remember the details. I believe the basic idea was to protect against the sort of carnage that can be caused by a typo in "cd /tmp; rm -rf *"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]