6 added 25 characters in body
source | link

Following piece of code is just an example from a script, but requesting you to understand the final outcome of the code.


GENERIC SCRIPT $> cat test12.ksh ## Assigning a text value in retval (bad path scenario) retval="ERROR" if [ $retval -eq 7 ] then echo "I am in " $retval fi exit $retval

## Assigning a text value in retval (bad path scenario)_
retval="ERROR"
if [ $retval -eq 7 ]
then
     echo "I am in " $retval
fi
exit $retval

LINUX $> ksh --version version sh (AT&T Research) 93u+ 2012-08-01 LINUX $> ksh -x test12.ksh + retval=ERROR + [ ERROR -eq 7 ] + exit ERROR tpl06429dat05::edwprod::/home/edwprod >echo $? 0 # look here return code of above executed script is 0

LINUX $> ksh --version
version         sh (AT&T Research) 93u+ 2012-08-01
LINUX $> ksh -x test12.ksh
+ retval=ERROR
+ [ ERROR -eq 7 ]
+ exit ERROR
tpl06429dat05::edwprod::/home/edwprod >echo $?
0
# look here return code of above executed script is 0_

UNIX $> uname -a HP-UX ipeip06 B.11.23 U ia64 ******** unlimited-user license UNIX $> strings /bin/ksh | grep Version | tail -2 @(#)Version 11/16/88 UNIX $> ksh -x test12.ksh + retval=ERROR + [ ERROR -eq 7 ] test12.ksh[3]: ERROR: bad number + exit ERROR test12.ksh[8]: ERROR: bad number UNIX $> echo $? 1 _# Look here, return code of above executed code is 1

UNIX $> uname -a
HP-UX ipeip06 B.11.23 U ia64 ******** unlimited-user license
UNIX $> strings /bin/ksh | grep Version | tail -2
@(#)Version 11/16/88
UNIX $> ksh -x test12.ksh
+ retval=ERROR
+ [ ERROR -eq 7 ]
test12.ksh[3]: ERROR: bad number
+ exit ERROR
test12.ksh[8]: ERROR: bad number
UNIX $> echo $?
1
# Look here, return code of above executed code is 1


  In Linux, "exit" command is not executed at all as I have passes wrong parameter (string), but in HP-UX there is no problem - "exit" command with wrong parameter has been executed and tells us that it's a wrong command (echo $?) in that script. And this return code is very important as based on this return code ($?), we decide whether a script has been executed successfully (0) or not.

Following piece of code is just an example from a script, but requesting you to understand the final outcome of the code.


GENERIC SCRIPT $> cat test12.ksh ## Assigning a text value in retval (bad path scenario) retval="ERROR" if [ $retval -eq 7 ] then echo "I am in " $retval fi exit $retval

LINUX $> ksh --version version sh (AT&T Research) 93u+ 2012-08-01 LINUX $> ksh -x test12.ksh + retval=ERROR + [ ERROR -eq 7 ] + exit ERROR tpl06429dat05::edwprod::/home/edwprod >echo $? 0 # look here return code of above executed script is 0

UNIX $> uname -a HP-UX ipeip06 B.11.23 U ia64 ******** unlimited-user license UNIX $> strings /bin/ksh | grep Version | tail -2 @(#)Version 11/16/88 UNIX $> ksh -x test12.ksh + retval=ERROR + [ ERROR -eq 7 ] test12.ksh[3]: ERROR: bad number + exit ERROR test12.ksh[8]: ERROR: bad number UNIX $> echo $? 1 _# Look here, return code of above executed code is 1


  In Linux, "exit" command is not executed at all as I have passes wrong parameter (string), but in HP-UX there is no problem - "exit" command with wrong parameter has been executed and tells us that it's a wrong command (echo $?) in that script. And this return code is very important as based on this return code ($?), we decide whether a script has been executed successfully (0) or not.

Following piece of code is just an example from a script, but requesting you to understand the final outcome of the code.

## Assigning a text value in retval (bad path scenario)_
retval="ERROR"
if [ $retval -eq 7 ]
then
     echo "I am in " $retval
fi
exit $retval
LINUX $> ksh --version
version         sh (AT&T Research) 93u+ 2012-08-01
LINUX $> ksh -x test12.ksh
+ retval=ERROR
+ [ ERROR -eq 7 ]
+ exit ERROR
tpl06429dat05::edwprod::/home/edwprod >echo $?
0
# look here return code of above executed script is 0_
UNIX $> uname -a
HP-UX ipeip06 B.11.23 U ia64 ******** unlimited-user license
UNIX $> strings /bin/ksh | grep Version | tail -2
@(#)Version 11/16/88
UNIX $> ksh -x test12.ksh
+ retval=ERROR
+ [ ERROR -eq 7 ]
test12.ksh[3]: ERROR: bad number
+ exit ERROR
test12.ksh[8]: ERROR: bad number
UNIX $> echo $?
1
# Look here, return code of above executed code is 1

In Linux, "exit" command is not executed at all as I have passes wrong parameter (string), but in HP-UX there is no problem - "exit" command with wrong parameter has been executed and tells us that it's a wrong command (echo $?) in that script. And this return code is very important as based on this return code ($?), we decide whether a script has been executed successfully (0) or not.

    Post Reopened by Anthon, don_crissti, Jeff Schaller, Archemar, Eric Renouf
5 Clarifies most of the raised questions...
source | link

exit command behaves differently in Linux and UnixHP-UX

SCRIPT $> cat test12.ksh
retval="ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE"
if [ $retval -eq 7 ]
then
    echo "I am in " $retval
elif [ $retval -eq 8 ]
then
    echo "I am in " $retval
fi
exit $retval

I am working in HP-UX (B.11.23) to LINUX (Red Hat Enterprise Linux Server release 6.5 - Santiago) migration project. There were several occurrences where HP-UX commands were not working properly in Linux. But, in following situation - I am facing some difficulties to find out an alternate solution.

Following piece of code is just an example from a script, but requesting you to understand the final outcome of the code.


GENERIC SCRIPT $> cat test12.ksh ## Assigning a text value in retval (bad path scenario) retval="ERROR" if [ $retval -eq 7 ] then echo "I am in " $retval fi exit $retval

Executing this code in LINUX...

LINUX $> ksh -x test12.ksh
+ retval='ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE'
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 7 ]
test12.ksh[3]: [: ORA-03114:: unknown operator
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 8 ]
test12.ksh[6]: [: ORA-03114:: unknown operator
+ exit ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
$ echo $?
0

LINUX $> ksh --version version sh (AT&T Research) 93u+ 2012-08-01 LINUX $> ksh -x test12.ksh + retval=ERROR + [ ERROR -eq 7 ] + exit ERROR tpl06429dat05::edwprod::/home/edwprod >echo $? 0 # look here return code of above executed script is 0

Same script provide us different outputNow, have executed same code in UNIXHP_UX

UNIX $> ksh -x test12.ksh
+ retval=ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 7 ]
test12.ksh[3]: ORA-03114:: unknown test operator
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 8 ]
test12.ksh[6]: ORA-03114:: unknown test operator
+ exit ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
test12.ksh[11]: ERROR:: bad number
$ echo $?
1

UNIX $> uname -a HP-UX ipeip06 B.11.23 U ia64 ******** unlimited-user license UNIX $> strings /bin/ksh | grep Version | tail -2 @(#)Version 11/16/88 UNIX $> ksh -x test12.ksh + retval=ERROR + [ ERROR -eq 7 ] test12.ksh[3]: ERROR: bad number + exit ERROR test12.ksh[8]: ERROR: bad number UNIX $> echo $? 1 _# Look here, return code of above executed code is 1

If you look closely


In Linux, LINUX does"exit" command is not execute exitexecuted at all as I have passes wrong parameter (string), but in HP-UX there is no problem - "exit" command with bad argument whereas UNIX doeswrong parameter has been executed and tells us that it's a wrong command (echo $?) in that script. Is there any way out to get same outputAnd this return code is very important as UNIXbased on this return code (which is correct$?) in LINUX, we decide whether a script has been executed successfully (0) or not. 

I don't want to changeunderstand, if we tweak the script for that. Becausecode, there are too manythen problem can be resolved. But that's bit difficult here as I am dealing with almost 15K or more such scripts which follow above syntaxare written in HP_UX. Is there any possibility to change something at OS level (changing packages/parameters).. What kind of system level changes needed?

On a different note, ksh versions are different and behaves differently. So, it's better if you avoid this answer.

exit command behaves differently in Linux and Unix

SCRIPT $> cat test12.ksh
retval="ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE"
if [ $retval -eq 7 ]
then
    echo "I am in " $retval
elif [ $retval -eq 8 ]
then
    echo "I am in " $retval
fi
exit $retval

Executing in LINUX...

LINUX $> ksh -x test12.ksh
+ retval='ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE'
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 7 ]
test12.ksh[3]: [: ORA-03114:: unknown operator
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 8 ]
test12.ksh[6]: [: ORA-03114:: unknown operator
+ exit ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
$ echo $?
0

Same script provide us different output in UNIX

UNIX $> ksh -x test12.ksh
+ retval=ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 7 ]
test12.ksh[3]: ORA-03114:: unknown test operator
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 8 ]
test12.ksh[6]: ORA-03114:: unknown test operator
+ exit ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
test12.ksh[11]: ERROR:: bad number
$ echo $?
1

If you look closely, LINUX does not execute exit command with bad argument whereas UNIX does. Is there any way out to get same output as UNIX (which is correct) in LINUX. I don't want to change the script for that. Because, there are too many scripts which follow above syntax. What kind of system level changes needed?

exit command behaves differently in Linux and HP-UX

I am working in HP-UX (B.11.23) to LINUX (Red Hat Enterprise Linux Server release 6.5 - Santiago) migration project. There were several occurrences where HP-UX commands were not working properly in Linux. But, in following situation - I am facing some difficulties to find out an alternate solution.

Following piece of code is just an example from a script, but requesting you to understand the final outcome of the code.


GENERIC SCRIPT $> cat test12.ksh ## Assigning a text value in retval (bad path scenario) retval="ERROR" if [ $retval -eq 7 ] then echo "I am in " $retval fi exit $retval

Executing this code in LINUX...

LINUX $> ksh --version version sh (AT&T Research) 93u+ 2012-08-01 LINUX $> ksh -x test12.ksh + retval=ERROR + [ ERROR -eq 7 ] + exit ERROR tpl06429dat05::edwprod::/home/edwprod >echo $? 0 # look here return code of above executed script is 0

Now, have executed same code in HP_UX

UNIX $> uname -a HP-UX ipeip06 B.11.23 U ia64 ******** unlimited-user license UNIX $> strings /bin/ksh | grep Version | tail -2 @(#)Version 11/16/88 UNIX $> ksh -x test12.ksh + retval=ERROR + [ ERROR -eq 7 ] test12.ksh[3]: ERROR: bad number + exit ERROR test12.ksh[8]: ERROR: bad number UNIX $> echo $? 1 _# Look here, return code of above executed code is 1


In Linux, "exit" command is not executed at all as I have passes wrong parameter (string), but in HP-UX there is no problem - "exit" command with wrong parameter has been executed and tells us that it's a wrong command (echo $?) in that script. And this return code is very important as based on this return code ($?), we decide whether a script has been executed successfully (0) or not. 

I understand, if we tweak the code, then problem can be resolved. But that's bit difficult here as I am dealing with almost 15K or more such scripts which are written in HP_UX. Is there any possibility to change something at OS level (changing packages/parameters).. What kind of system level changes needed?

On a different note, ksh versions are different and behaves differently. So, it's better if you avoid this answer.

    Post Closed as "unclear what you're asking" by mdpc, Jeff Schaller, don_crissti, sam, Julie Pelletier
4 better formatting, added tag; remove errant **s
source | link
**SCRIPTSCRIPT $> cat test12.ksh**ksh
retval="ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE"
if [ $retval -eq 7 ]
then
    echo "I am in " $retval
elif [ $retval -eq 8 ]
then
    echo "I am in " $retval
fi
exit $retval

Executing in LINUX...

**LINUXLINUX $> ksh -x test12.ksh**ksh
+ retval='ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE'
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 7 ]
test12.ksh[3]: [: ORA-03114:: unknown operator
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 8 ]
test12.ksh[6]: [: ORA-03114:: unknown operator
+ exit ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
**$$ echo $?**
0

Same script provide us different output in UNIX

**UNIXUNIX $> ksh -x test12.ksh**ksh
+ retval=ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 7 ]
test12.ksh[3]: ORA-03114:: unknown test operator
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 8 ]
test12.ksh[6]: ORA-03114:: unknown test operator
+ exit ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
test12.ksh[11]: ERROR:: bad number
**$$ echo $?**
1

If you look closely, LINUX does not execute exit command with bad argument whereas UNIX does. Is there any way out to get same output as UNIX (which is correct) in LINUX. I don't want to change the script for that. Because, there are too many scripts which follow above syntax. What kind of system level changes needed?

**SCRIPT $> cat test12.ksh**
retval="ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE"
if [ $retval -eq 7 ]
then
    echo "I am in " $retval
elif [ $retval -eq 8 ]
then
    echo "I am in " $retval
fi
exit $retval

Executing in LINUX...

**LINUX $> ksh -x test12.ksh**
+ retval='ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE'
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 7 ]
test12.ksh[3]: [: ORA-03114:: unknown operator
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 8 ]
test12.ksh[6]: [: ORA-03114:: unknown operator
+ exit ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
**$ echo $?**
0

Same script provide us different output in UNIX

**UNIX $> ksh -x test12.ksh**
+ retval=ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 7 ]
test12.ksh[3]: ORA-03114:: unknown test operator
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 8 ]
test12.ksh[6]: ORA-03114:: unknown test operator
+ exit ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
test12.ksh[11]: ERROR:: bad number
**$ echo $?**
1

If you look closely, LINUX does not execute exit command with bad argument whereas UNIX does. Is there any way out to get same output as UNIX (which is correct) in LINUX. I don't want to change the script for that. Because, there are too many scripts which follow above syntax. What kind of system level changes needed?

SCRIPT $> cat test12.ksh
retval="ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE"
if [ $retval -eq 7 ]
then
    echo "I am in " $retval
elif [ $retval -eq 8 ]
then
    echo "I am in " $retval
fi
exit $retval

Executing in LINUX...

LINUX $> ksh -x test12.ksh
+ retval='ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE'
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 7 ]
test12.ksh[3]: [: ORA-03114:: unknown operator
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 8 ]
test12.ksh[6]: [: ORA-03114:: unknown operator
+ exit ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
$ echo $?
0

Same script provide us different output in UNIX

UNIX $> ksh -x test12.ksh
+ retval=ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 7 ]
test12.ksh[3]: ORA-03114:: unknown test operator
+ [ ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE -eq 8 ]
test12.ksh[6]: ORA-03114:: unknown test operator
+ exit ERROR: ORA-03114: not connected to ORACLE ERROR: ORA-03114: not connected to ORACLE
test12.ksh[11]: ERROR:: bad number
$ echo $?
1

If you look closely, LINUX does not execute exit command with bad argument whereas UNIX does. Is there any way out to get same output as UNIX (which is correct) in LINUX. I don't want to change the script for that. Because, there are too many scripts which follow above syntax. What kind of system level changes needed?

3 better formatting, added tag
source | link
2 remove unrelated tag
| link
1
source | link