Operating System - HP-UX
1820541 Members
3749 Online
109626 Solutions
New Discussion юеВ

Re: Script Works On Solaris, but not on HP-UX. Why?

 
Daniel Navarro
Occasional Contributor

Script Works On Solaris, but not on HP-UX. Why?

All,

I have a strange problem. I have a script that works fine when I use it on Solaris, but fails to work on HP-UX. The script checks to see the version of an application, by querying a table called "MASTER_DB_VERSION". The table has one column that holds the current version of a table. If the version is old or not in sequence with the current patch version, then the script aborts. In other words, if I am trying to run a patch script called 1.5.0.0 then the current version of the app. had better be "1.4.x.x.". If it is anything else (i.e. 1.1, 1.2 1.3) then the script should abort. For some reason my script never runs, but always aborts because it can't evaluate the current version from MASTER_DB_VERSION. My code follows:

sqlplus ECC/ECC @versionTest.sql
currentVersion=`2.7`
verTest=`cat LOGS/versionTest.LST|grep Version|awk {'print $2'}`

if [ "$verTest" = "2.7" ];
then
/* DO THE INSTALL */
else
/* DO NOT DO THE INSTALL AND WARN USER SCRIPT ABORTED */
fi

The version test should find 2.7.0.1, and proceed with the install, but it fails . As I said before, this scripts works for Solaris, but not HP. Can someone please help.

Thanks,
Daniel N.
6 REPLIES 6
Sridhar Bhaskarla
Honored Contributor

Re: Script Works On Solaris, but not on HP-UX. Why?

You need to change `2.7` to either '2.7'
or "2.7" while setting currentversion
like

currentversion="2.7"

-Sri
You may be disappointed if you fail, but you are doomed if you don't try

Re: Script Works On Solaris, but not on HP-UX. Why?

What shell are you using? - /usr/bin/sh on Solaris is the Bourne shell, /usr/bin/sh on HP-UX is the POSIX shell.

I am an HPE Employee
Accept or Kudo
James R. Ferguson
Acclaimed Contributor

Re: Script Works On Solaris, but not on HP-UX. Why?

Hi Daniel:

With regard to Duncan's comments, the behavior of the Bourne and Posix shells is different when testing two strings. Consider:

#!/usr/old/bin/sh
verTest="2.7.0.1"
if [ "$verTest" -eq "2.7" ]
then
echo ok
else
echo not_ok
fi
#.end

This is the Bourne shell (/usr/old/bin/sh) and will echo "ok".

If you use the Posix shell (/usr/bin/sh) the test will be false, returning "not_ok".

Regards!

...JRF...
John Palmer
Honored Contributor

Re: Script Works On Solaris, but not on HP-UX. Why?

Hi Daniel,

I would question why it actually works on Solaris!

The following test:
if [ "$verTest" = "2.7" ]
does a string comparison between "2.7.0.1" and "2.7". This should always fail.

You could try matching the strings, something like:-
currentVersion="2.7"
verTest=...

if [[ ${verTest} = ${currentVersion}* ]];
then...

Note that this will only work if the strings are NOT quoted. It is matching your extracted version (2.7.0.1) with 2.7.


Jim, your example is actually doing a numeric comparison not string (-eq rather than =). It looks as though the old bourne shell evaluates each argument as an integer stopping at a non-numeric character. Thus 2.7 equates to 2.7.0.1. because both arguments are converted to the integer 2 first. The POSIX shell is much more precise than this.

Regards,
John
James R. Ferguson
Acclaimed Contributor

Re: Script Works On Solaris, but not on HP-UX. Why?

Hi John:

Oops. Yes, I agree. My first thought when I read this post was that the string comparison was perhaps evaluated for the shorter operand's length. While obviously not the case, when I found that the algebraic comparsion was different for Bourne vs. Posix, I posted that but referred to "string comparison"

Well, I bungled! Thanks for the correction. Glad to see you here -- it's been too long.

With warm regards, Jim.

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Script Works On Solaris, but not on HP-UX. Why?

Hi:

I don't think this puppy really works on Solaris. I suspect that the version string really is "2.7" on that platform (or 2.7 0.1)
so that awk's $2 picks up "2.7". Solaris's shell isn't bad enough for this to work.

Clay
If it ain't broke, I can fix that.