ksh incompatabilities in HP-UX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh incompatabilities in HP-UX
# 1  
Old 06-03-2009
Question ksh incompatabilities in HP-UX

I have a number of Korn scripts I've used successfully for years in AIX (4.3 and 5.x) and Solaris (9 and 10). Recently I've had to start porting them to HP-UX (11i V3) and run into a few unexpected incompatabilities. For one, the "!" operator does not seem to work reliably (as in "if (! command) ..."), nor does the "==" operator.

I've researched this a bit, and from what I've seen it appears that HP's version of ksh is rather old (11/16/88c). Does anyone know of a list of differences between HP's ksh and more modern ones, perhaps with ideas on how to program around them? In a few cases, it's gotten messy enought that I simply gave up and changed the calling shell to bash, which works reasonably well, but there are enough differences there that that's not a one-size-fits-all solution, either.

Thanks,
Steve
# 2  
Old 06-04-2009
Quote:
Originally Posted by SteveB23
I have a number of Korn scripts I've used successfully for years in AIX (4.3 and 5.x) and Solaris (9 and 10). Recently I've had to start porting them to HP-UX (11i V3) and run into a few unexpected incompatabilities. For one, the "!" operator does not seem to work reliably (as in "if (! command) ..."), nor does the "==" operator.

You have illustrated the reasons for using only POSIX syntax in scripts.
Quote:
I've researched this a bit, and from what I've seen it appears that HP's version of ksh is rather old (11/16/88c). Does anyone know of a list of differences between HP's ksh and more modern ones, perhaps with ideas on how to program around them? In a few cases, it's gotten messy enought that I simply gave up and changed the calling shell to bash, which works reasonably well, but there are enough differences there that that's not a one-size-fits-all solution, either.

The man pages for ksh88 and ksh93 are at: KornShell Documentation.
# 3  
Old 06-04-2009
The POSIX shell on HP-UX is /usr/bin/sh .
See "man sh" for an explanation of the various shells.
BTW. The syntax you describe looks more like "csh" than "ksh". An "if" test in "ksh" would have square brackets not round brackets. Also the "==" is valid in "csh".
# 4  
Old 06-04-2009
man sh-posix for information on the POSIX shell.
# 5  
Old 06-04-2009
Quote:
Originally Posted by cfajohnson
You have illustrated the reasons for using only POSIX syntax in scripts.
While I agree, I'm not sure I see your point. O'Reilly's "Learning the Korn Shell" makes no mention of POSIX concerns with either of my examples. (In fact, page 143 of the 2nd edition specifically states that the "!" keyword was introduced in POSIX.) I'm certainly no POSIX guru, though, so perhaps I've misunderstood your intent.

In any case, if HP's ksh is as old as it appears, it's probably not POSIX-compliant to start with, and using POSIX syntax may be the cause of the problem, not the solution. So my original question stands - does there exist a list of version incompatabilities between HP's ksh and more modern ones?

Quote:
Originally Posted by cfajohnson
The man pages for ksh88 and ksh93 are at: KornShell Documentation.
Believe it or not, I browse those pages often when I'm developing new scripts, and they recently went offline (again).

Quote:
Originally Posted by methyl
The POSIX shell on HP-UX is /usr/bin/sh
The script I'm currently working on contains the following:
Code:
# Check for debug mode switch
if [[ $1 == "-d" ]]
then
        # Set up debug mode
        debug=true
        shift
fi

On HP-UX 11i V3, both /bin/ksh and /usr/bin/sh choke with a syntax error (`==' unexpected). The original script runs fine on Solaris and AIX. What about this statement is non-POSIX? If I drop the test to single braces and change the "==" to "-eq" both ksh and sh are happy.

Last edited by DukeNuke2; 06-04-2009 at 03:41 PM..
# 6  
Old 06-04-2009
Quote:
Originally Posted by SteveB23
The script I'm currently working on contains the following:
Code:
# Check for debug mode switch
if [[ $1 == "-d" ]]
then
        # Set up debug mode
        debug=true
        shift
fi

On HP-UX 11i V3, both /bin/ksh and /usr/bin/sh choke with a syntax error (`==' unexpected). The original script runs fine on Solaris and AIX. What about this statement is non-POSIX? If I drop the test to single braces and change the "==" to "-eq" both ksh and sh are happy.

You're lucky, then. The -eq operator is for comparing integers, not strings.

The correct test (in any Bourne-type shell) is:

Code:
if [ "$1" = "-d" ]

But for parsing options, you should use getopts.
# 7  
Old 06-04-2009
Quote:
Originally Posted by cfajohnson
You're lucky, then. The -eq operator is for comparing integers, not strings.
The correct test (in any Bourne-type shell) is:
Code:
if [ "$1" = "-d" ]

Correction noted. My point was that the "==" works on the other platforms I use and had no reason to think it would not work here. Is the "==" operator non-POSIX?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help with ksh

I have the following file: one two three four man women yes no place togo bad sleep I need to move all lines that have only two words(columns) in a separate file and the rest in a separate file... I used : for $linecont in $(cat $filename); do echo $linecont > temp line1='cat... (7 Replies)
Discussion started by: daimne
7 Replies

2. Shell Programming and Scripting

ksh help

Hi, I have command like this with ooutput : unix>tnsping abc TNS Ping Utility for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Production on 17-AUG-2011 17:06:11 Copyright (c) 1997, 2007, Oracle. All rights reserved. Used parameter files: /opt/oracle/network/admin/sqlnet.ora ... (19 Replies)
Discussion started by: talashil
19 Replies

3. Shell Programming and Scripting

different behaviour for ksh and ksh -x

I'm getting different behaviour when executing below script in debug option. $ cat ss.ksh ff=$(pwd) echo " ff : $ff" $ ksh ss.ksh ff : /tmp $ ksh -x ss.ksh + + pwd ff= + echo ff : ff : I was getting this behaviour in my actuall script i'm able to reproduce this in simple script... (4 Replies)
Discussion started by: luckybalaji
4 Replies

4. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

5. Shell Programming and Scripting

ksh using `` or $()

In csh I use opt=` echo $arg | awk 'BEGIN {FS="="} {print $1}' ` I am wondering what I should use when using ksh opt=$(print -R $arg | awk 'BEGIN {FS="="} {print $1}') or opt=` print -R $arg | awk 'BEGIN {FS="="} {print $1}' ` (31 Replies)
Discussion started by: kristinu
31 Replies

6. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

7. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

8. Shell Programming and Scripting

tracing a ksh script within a ksh script

I normally trace a script with the ksh -x <script name> and redirect strderr to file. But if you have a script like the examble below...... vi hairy bear=`grep bear animals` if then ksh more_animals fi If I ksh -x hairy it won't trace "more_animals" unless I put a -x in it. Is... (1 Reply)
Discussion started by: shorty
1 Replies

9. Shell Programming and Scripting

executing a ksh script from another ksh script

Hi, I'm new to unix scripting.How can i call a script from another script. I have a.ksh and b.ksh .I have to call b.ksh from a.ksh after it is successfully exceuted. I tried using #!/bin/ksh -x in a.ksh and at the end i have used /path/b.ksh My problem is it is executing only a.ksh.it... (6 Replies)
Discussion started by: ammu
6 Replies

10. Shell Programming and Scripting

Not another ksh!

Hi there, I've coded a script to create a menu system on an AIX machine. When user selects an item of the menu I perform a program using " nohup somepgm &" The reason I do that is because usually the scripts behind the menu items are very time-consuming and users logout and log back in... (2 Replies)
Discussion started by: Shaz
2 Replies
Login or Register to Ask a Question