subshell return code

( exit 1 )
echo $?
Subshells always return 0.
This isn’t right is it ?


Using M2, Opera’s revolutionary e-mail client: http://www.opera.com/m2/

Simon Casady wrote:

( exit 1 )
echo $?
Subshells always return 0.
This isn’t right is it ?

#!/bin/sh
( exit 1 )


Then run:
#./myshell.sh

echo $?

1

Seems to work for me.

Even if you do:

sh

exit 1

echo $?

1

sh

exit 2

echo $?

2

Works here too…


Cheers,
Adam

QNX Software Systems
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

On Wed, 06 Apr 2005 13:28:03 -0400, Adam Mallory <amallory@qnx.com> wrote:

Simon Casady wrote:
( exit 1 )
echo $?
Subshells always return 0.
This isn’t right is it ?


#!/bin/sh
( exit 1 )


Then run:
#./myshell.sh

echo $?

1

Seems to work for me.

Even if you do:

sh

exit 1

echo $?

1

sh

exit 2

echo $?

2

Works here too…

sh

(exit 1)

echo $?

0

If you use () to group commands $? seems to always return 0
I bring this up because configure (shudder) always does this.


Using M2, Opera’s revolutionary e-mail client: http://www.opera.com/m2/

Simon Casady wrote:

If you use () to group commands $? seems to always return 0
I bring this up because configure (shudder) always does this.

On the command line:

sh

(ls FILETHATDOESNOTEXIST)

ls: No such file or directory (FILETHATDOESNOTEXIST)

echo $?

1

Seems to still work. If you group commands where the last one passes,
then sure it will return 0:

sh

(ls FILETHATDOESNOTEXIST; echo “Foo”)

ls: No such file or directory (FILETHATDOESNOTEXIST)
Foo

echo $?

0



Do you have a shell script example that shows the issue - I think we’re
missing something in the communications here.


BTW, I get the same behaviour under FreeBSD and Neutrino.


Cheers,
Adam

QNX Software Systems
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

Adam Mallory <amallory@qnx.com> wrote:

Simon Casady wrote:

If you use () to group commands $? seems to always return 0
I bring this up because configure (shudder) always does this.

On the command line:

sh

(ls FILETHATDOESNOTEXIST)

ls: No such file or directory (FILETHATDOESNOTEXIST)

echo $?

1

Seems to still work. If you group commands where the last one passes,
then sure it will return 0:

sh

(ls FILETHATDOESNOTEXIST; echo “Foo”)

ls: No such file or directory (FILETHATDOESNOTEXIST)
Foo

echo $?

0



Do you have a shell script example that shows the issue - I think we’re
missing something in the communications here.



BTW, I get the same behaviour under FreeBSD and Neutrino.

I get the zero:

[1@ttyp1] which -al sh
-rwxrwxr-x 1 root root 103248 Jul 20 1998 /bin/sh
[1@ttyp1] cksum /bin/sh
3711776061 103248 /bin/sh
[1@ttyp1] /bin/sh
[1@ttyp1] (exit 1)
[1@ttyp1] echo $?
0
[1@ttyp1] uname -a
QNX 1 L 425 PCI 32
[1@ttyp1] sin in
Node CPU Machine Speed Memory Ticksize Display Flags
1 686/687 PCI 19117 330M/392M 10.0ms VGA Color -3P±---------8P

Heapp Heapf Heapl Heapn Hands Names Sessions Procs Timers Nodes Virtual
0 0 22120 0 64 100 64 500 125 401 269M/ 411M

Boot from Hard at Feb 06 16:41 Locators: 1

Cheers,
-RK

Adam Mallory wrote:

Do you have a shell script example that shows the issue - I think we’re
missing something in the communications here.


BTW, I get the same behaviour under FreeBSD and Neutrino.

Sorry! - I’m using a newer version of ksh on my qnx4 box. My release
system shows that same issue. Looks like it’s not propagating the $?
through properly.

Go grab ftp://ftp.qnx.com/usr/free/qnx4/os/shells/pdksh-5.2.3-bin.tgz
and that should address that issue (it seems to :wink: ).


Cheers,
Adam

QNX Software Systems
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

On Wed, 06 Apr 2005 16:07:04 -0400, Adam Mallory <amallory@qnx.com> wrote:
done, thanks


Adam Mallory wrote:
Do you have a shell script example that shows the issue - I think we’re
missing something in the communications here.
BTW, I get the same behaviour under FreeBSD and Neutrino.

Sorry! - I’m using a newer version of ksh on my qnx4 box. My release
system shows that same issue. Looks like it’s not propagating the $?
through properly.

Go grab > ftp://ftp.qnx.com/usr/free/qnx4/os/shells/pdksh-5.2.3-bin.tgz
and that should address that issue (it seems to > :wink: > ).


Using M2, Opera’s revolutionary e-mail client: http://www.opera.com/m2/

On Wed, 06 Apr 2005 16:07:04 -0400, Adam Mallory <amallory@qnx.com> wrote:

grab > ftp://ftp.qnx.com/usr/free/qnx4/os/shells/pdksh-5.2.3-bin.tgz
If I try pdksh v5.2.3 - I see a big difference in the behaviour:

  1. “export” reports the variables by names only, omitting the values set.
  2. the command line history is not accessible with ArrowUp- ArrowDown-keys.

Is pdksh v5.2.3 a decent replacement for, say, ported BASH v2.02?
Currently I use BASH when I try porting things to QNX4.

What is your version of /bin/ksh?
If the next QNX4 patch gets released - will it be included there?

Tony.