Re: [SLUG] BASH command return value

2000-08-04 Thread Andrew Reilly

On Fri, Aug 04, 2000 at 11:31:13AM -0400, Subba Rao wrote:
> 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.

Well, that's just the way shells work.  When you write a shell
script, you never care whether you put a few blank lines between
the command that you're testing.

Now, as you've found, you can override that behaviour by
executing a command that returns true (0) _after_ the $? value
has been displayed, but before the next command is accepted.
You chose whois, but that's a real executable, so you have to
fork an extra time for each prompt.  If you use a shell builtin
like $(exit 0), to reset the result value, and keep using \u for
your user name, then (a) your shell might run a bit more
quickly, but (b) you can't actually use $? yourself, on the
command line.  Well you can in multi-statement lines, I guess.

Aesthetics aside, better to have learned this lesson, leave the
prompt as you originally had it (not resetting the result), and
reset it manually if you feel strongly about it.

It actually sounds like a bloody good idea.  Think I'll try it
myself for a while.

Thanks,

-- 
Andrew


--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug



Re: [SLUG] BASH command return value

2000-08-04 Thread ken

> When I change the PS1 sring to,
> 
> PS1='($?)`whoami`@\h:\w =>'
> 
> The return value for $? is immediately displayed in the next prompt. 
> 
> (0)subb3@myhost:~ =>
> (0)subb3@myhost:~ => lssdfh
> (258)subb3@myhost:~ => 
> (0)subb3@myhost:~ => 
> (0)subb3@myhost:~ => ls
>   
> (0)subb3@myhost:~ => ls o
> ls: o: No such file or directory
> (1)subb3@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.

Because you are running a whoami command inside the prompt? To convince yourself
that the next number displayed is the result of the command inside the `s,
substitute exit 123 for whoami.

--
This mail sent via NLC WebMail: http://www.nlc.net.au/


--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug



[SLUG] BASH command return value

2000-08-04 Thread Subba Rao


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@myhost:~ =>
(0)subb3@myhost:~ => lssdfh  <== This is no command
(258)subb3@myhost:~ => 
(258)subb3@myhost:~ => 
(258)subb3@myhost:~ => 
(258)subb3@myhost:~ => ls
  
(0)subb3@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@myhost:~ =>
(0)subb3@myhost:~ => lssdfh
(258)subb3@myhost:~ => 
(0)subb3@myhost:~ => 
(0)subb3@myhost:~ => ls
  
(0)subb3@myhost:~ => ls o
ls: o: No such file or directory
(1)subb3@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
[EMAIL PROTECTED]
http://pws.prserv.net/truemax/

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


--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug