Article View: comp.bugs.sys5
Article #634Re: sh bug
From: Simon Brown
Date: Thu, 29 Oct 1987 10:41
Date: Thu, 29 Oct 1987 10:41
33 lines
2157 bytes
2157 bytes
In article <467@virginia.acc.virginia.edu> mer6g@virginia.UUCP (Marc Rouleau) writes:
>On our 3b2, 3b5, and 3b15 AT&T systems running SYSV.2 and SYSV.3, sh does
>something rather unfortunate when certain built-in functions fail. For
>example,
>
> cd nowhere || echo 'cd failure'
>
>where ``nowhere'' is nonexistent does not (as you might expect) cause ``cd
>failure'' to be echoed to the screen. The expected error message is produced
>and then . . . nothing, a new prompt.
>
Dat's 'cos the first cd fails, so the shell interrupts itself (well, sort of),
and jumps straight back to command level - without executing the second part of
the "||". What you'll have to do is force the first component to be executed
in a subshell so it can't effect the second - like
if (cd nowhere) # cd in a subshell
then cd nowhere # it worked, so cd in the main shell
else echo 'cd failure' # otherwise print error message
fi
Of course, you still get the error message from the first cd (if it fails),
unless you redirect it's output elsewhere with
if (cd nowhere) >/dev/null 2>&1
--
----------------------------------
| Simon Brown | UUCP: seismo!mcvax!ukc!{lfcs,its63b}!simon
| LFCS | JANET: simon@uk.ac.ed.{lfcs,its63b}
| Department of Computer Science | ARPA: simon%lfcs.ed.ac.uk@cs.ucl.ac.uk
| University of Edinburgh, | or simon%its63b.ed.ac.uk@cs.ucl.ac.uk
| Scotland, UK. | or simon%cstvax.ed.ac.uk@cs.ucl.ac.uk
----------------------------------
"Life's like that, you know"
Technical Details
Message-ID:
<706@its63b.ed.ac.uk>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!mcvax!ukc!its63b!simonReferences:
<467@virginia.acc.virginia.edu>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!mcvax!ukc!its63b!simon From: simon@its63b.ed.ac.uk (Simon Brown) Newsgroups: comp.bugs.sys5 Subject: Re: sh bug Message-ID: <706@its63b.ed.ac.uk> Date: Thu, 29-Oct-87 05:41:16 EST Article-I.D.: its63b.706 Posted: Thu Oct 29 05:41:16 1987 Date-Received: Wed, 4-Nov-87 04:44:41 EST References: <467@virginia.acc.virginia.edu> Reply-To: simon@its63b.ed.ac.uk (Simon Brown) Organization: Computer Science Department, Edinburgh University Lines: 33