Ac3_DeXt3R Ac3_DeXt3R - 3 months ago 14
Bash Question

Behaviour of 'ECHO' in csh and bash

I was writing few scripts and suddenly stroke me to think the following commands in CSH and BASH shells.

In csh shell

$ echo $?BASH
0
$ echo $?HOME
1
$ echo $? home
0 home


In bash shell

$ echo $?BASH
0BASH
$ echo $?HOME
0HOME
$ echo $? home
0 home


Someone explain the above behaviour. I know the echo $? prints the exit status of the last command but if added with some string then how its working?

Answer

If you review the documentation csh indicates:

$?name 
${?name} 
Substitutes the string 1 if the variable name is set, 0 if it is not.

$?0 
Substitutes 1 if the current input file name is known, 0 if it is not.

http://www.mkssoftware.com/docs/man1/csh.1.asp

be careful, $? is diferent to $?name

Comments