# weird return code processing changes

**URL:** <https://community.unix.com/t/weird-return-code-processing-changes/219992>\
**Category:** Shell Programming and Scripting\
**Created:** [November 10, 2008, 4:26pm UTC](https://community.unix.com/t/weird-return-code-processing-changes/219992 "2008-11-10T16:26:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sblanton](https://community.unix.com/user_avatar/community.unix.com/sblanton/32/4593_2.png) [@sblanton](https://community.unix.com/u/sblanton)\
**Post date:** [November 10, 2008, 4:26pm UTC](https://community.unix.com/t/weird-return-code-processing-changes/219992/1 "2008-11-10T16:26:44Z")

</div>

My problem is my AIX ksh script works as expected from the shell prompt, but when the same script is executed by a daemon, it fails to acknowledge any non-zero return codes for programs it executes.

I have one ksh script the calls another. The calling one is /tmp/harn.ksh:

```nohighlight
#!/bin/ksh

/tmp/sc1.ksh
rc=$?
if [[$rc -ne 0]]; then
 exit $rc
fi

echo "No errors"
exit 0

```

And a second one, "/tmp/sc1.ksh" which doesn't matter what it is as long as it exits with a non-zero return code:

```nohighlight
#!/usr/bin/ksh
echo Running step1
echo Something went wrong
exit 1

```

This works as expected from the shell prompt:

```nohighlight
$ /tmp/harn.ksh
Running step1
Something went wrong
$ echo $?
1
$ 

```

Now when it is executed by our daemon (long story, but shouldn't be anything funny), I get this:

```nohighlight
Running step1
Something went wrong
No errors

```

Other info:

- It is happening entirely within the ksh and that's why I don't think the daemon matters.
- If I convert /tmp/harn.ksh to Perl, it works perfectly. That would be my solution, but this is for a customer and it's not an option.
- /tmp/sc1.ksh can be replaced by any program creating an error and will lead to the same results.
- I Googled and Googled and tried dozens of ways to change how the return code is captured and processed all with the same results.
- I thought maybe the difference was due to not having a tty attached to the script executed by the daemon. I slipped a tty command at the beginning of each script and got /dev/pts/3 for both instead of /dev/pts/2 at the shell prompt (honestly, i don't fully understand that - looks like it attached a pseudo-terminal or something)

Thanks

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [November 10, 2008, 6:07pm UTC](https://community.unix.com/t/weird-return-code-processing-changes/219992/2 "2008-11-10T18:07:39Z")

</div>

I suspect that you did not copy the script correctly, becuase there is a syntax error in the one you posted.

What happens with this script:

```nohighlight
/tmp/sc1.ksh || exit

echo "No errors"
exit 0

```

---

<div class="post-metadata">

**Author:** ![sblanton](https://community.unix.com/user_avatar/community.unix.com/sblanton/32/4593_2.png) [@sblanton](https://community.unix.com/u/sblanton)\
**Post date:** [November 10, 2008, 6:27pm UTC](https://community.unix.com/t/weird-return-code-processing-changes/219992/3 "2008-11-10T18:27:48Z")

</div>

Uhh..yes, a space after the zero is required...:o Thanks for the suggestion, but same problem.

I was thinking maybe to try executing through ssh, but don't have that on this box. Yep, low tech, like not being able to copy and paste correctly!

```nohighlight
#!/bin/ksh

/tmp/sc1.ksh
rc=$?
if [[$rc -ne 0]]; then
 exit $rc
fi

echo "No errors"
exit 0

```

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [November 10, 2008, 6:42pm UTC](https://community.unix.com/t/weird-return-code-processing-changes/219992/4 "2008-11-10T18:42:25Z")

</div>

Are you sure that /tmp/sc1.ksh fails?

Try replacing it with false.
