[techtalk] BASH command return value
Mandi
mandi at linuxchick.org
Fri Aug 4 11:38:49 EST 2000
when you change \u to `whoami`, you get the 0 value because you are
executing `whoami` everytime you get a prompt, i think. `whoami` has an
exit code of 0, successful, so that's what goes into $?. \u, \h, \w, \W,
etc aren't executed, they're properties of the shell at that time.
that's the way i understand it, anyway. you can get some weird stuff in
there. I have old bash laying around, and all $? gives me is the exit
code of the export PS1... command, and it never changes.
-mandi
On Fri, 4 Aug 2000, Subba Rao wrote:
>
> 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
>
>
> _______________________________________________
> techtalk mailing list
> techtalk at linuxchix.org
> http://www.linux.org.uk/mailman/listinfo/techtalk
>
More information about the Techtalk
mailing list