[techtalk] BASH command return value

Subba Rao subb3 at attglobal.net
Fri Aug 4 11:34:07 EST 2000


My PS1 prompt has the following string,

PS1='($?)\u@\h:\w =>'

In this case, when my command fails the BASH variable $? value is displayed
in my prompt. What is happening is that a command return value stays there
until an new command is issued. A newline for the shell will still return the
previous $? value. $? value is never reset until a new command is issued.

(0)subb3 at myhost:~ =>
(0)subb3 at myhost:~ => lssdfh  <== This is no command
(258)subb3 at myhost:~ => 
(258)subb3 at myhost:~ => 
(258)subb3 at myhost:~ => 
(258)subb3 at myhost:~ => ls
     <file listing> 
(0)subb3 at myhost:~ =>

When I change the PS1 sring to,

PS1='($?)`whoami`@\h:\w =>'

The return value for $? is immediately displayed in the next prompt. 

(0)subb3 at myhost:~ =>
(0)subb3 at myhost:~ => lssdfh
(258)subb3 at myhost:~ => 
(0)subb3 at myhost:~ => 
(0)subb3 at myhost:~ => ls
     <file listing> 
(0)subb3 at myhost:~ => ls o
ls: o: No such file or directory
(1)subb3 at myhost:~ => 

In BASH, why does the "\u" and "whoami" make a big difference for the $? value in
PS1 string? The BASH version is 2.04.

-- 

Subba Rao
subb3 at attglobal.net
http://pws.prserv.net/truemax/

 => Time is relative. Here is a new way to look at time. <=
http://www.smcinnovations.com





More information about the Techtalk mailing list