[techtalk] BASH command return value

joey tsai joeytsai at cc.gatech.edu
Fri Aug 4 18:05:52 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.
> 
> When I change the PS1 sring to,
> 
> PS1='($?)`whoami`@\h:\w =>'
> 
> The return value for $? is immediately displayed in the next prompt. 
> 
> In BASH, why does the "\u" and "whoami" make a big difference for the $?
> value in PS1 string? The BASH version is 2.04.

I'm willing to bet that BASH figures out your name once with the \u call,
while putting commands into your PS1 prompt will cause that command to be
executed with each prompt you ask for.  Because the the "whoami" command
executed properly, it is actually the command returning the 0.

But that's just a guess.

	// joey tsai






More information about the Techtalk mailing list