HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

scripting differences between hpux and linux

 

scripting differences between hpux and linux

A simple test script:

#!/usr/ksh
set -x
DN='"cn=Directory Manager"'
echo $DN

The outcome on HP-UX is what I'm expecting:
home> ./test
+ DN="cn=Directory Manager"
+ echo "cn=Directory Manager"
"cn=Directory Manager"

The outcome on Linux however is very slightly different:

[root]# sh test
+ DN='"cn=Directory Manager"'
+ echo '"cn=Directory' 'Manager"'
"cn=Directory Manager"

Anyone know why it's sticking the single quotes around the variable? When I pass ${DN} to a command later in the script it's failing because it splits it into ""cn=Directory" and "Manager"".
7 REPLIES
Steven E. Protter
Exalted Contributor

Re: scripting differences between hpux and linux

Shalom,

Different shell, minor minor variations in functionality.

http://kornshell.com/
ksh

http://www.gnu.org/software/bash/manual/bashref.html
bash

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Mel Burslan
Honored Contributor

Re: scripting differences between hpux and linux

I noticed, on linux, you have run the command with

sh test

command, which in turn have used the default shell you were using at the time, more than likely bash

does it run the same way if you call the script the same way you did in hpux machine ? I.e :

./test

Variable interpretations of shells are different for different shells.
________________________________
UNIX because I majored in cryptology...
Doug O'Leary
Honored Contributor

Re: scripting differences between hpux and linux

Hey;

As posted, it's almost certainly one more little difference between ksh and bash. Bash is pretty close, but certainly not an exact copy of ksh. Check out array definition for more entertaining differences.

There are ksh rpms for linux. Depending on the distro, it may already be installed. Just switch the shell and you'll be good, I think.

Doug O'Leary

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html

Re: scripting differences between hpux and linux

as others have pointed out, by doing "sh test" you are using a different shell - use the same shell (ksh) and you will get consistent results. I presume the line "#!/usr/ksh" at the top of your script was a typo for "#!/usr/bin/ksh". Here's what I get on my HP-UX/Linux systems:

# uname -sr
HP-UX B.11.31

# cat de.sh

#!/usr/bin/ksh
set -x
DN="'cn=Directory Manager'"
echo "$DN"

# ./de.sh
+ DN='cn=Directory Manager'
+ echo 'cn=Directory Manager'
'cn=Directory Manager'

---------------------------------

# uname -or
2.6.9-42.EL GNU/Linux

# cat de.sh
#!/usr/bin/ksh
set -x
DN="'cn=Directory Manager'"
echo "$DN"

# ./de.sh
+ DN='cn=Directory Manager'
+ echo 'cn=Directory Manager'
'cn=Directory Manager'


As you can see - consistent...

HTH

Duncan

HTH

Duncan
Court Campbell
Honored Contributor

Re: scripting differences between hpux and linux

Once you put this line at the top

#!/usr/ksh

That is what the script is going to run under. If you have pdksh on the linux box, then it will run under the korn shell.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
James R. Ferguson
Acclaimed Contributor

Re: scripting differences between hpux and linux

Hi Pete:

I guess I have to ask why do you care, given that the differences are only in the trace?

Using '/usr/bin/ksh' [or for that matter '/usr/bin/sh'] on an Itanium 11.23 server:

+ DN="cn=Directory Manager"
+ echo "cn=Directory Manager"
"cn=Directory Manager"

Using '/bin/bash' on an OpenSUSE 11 server:

+ DN='"cn=Directory Manager"'
+ echo '"cn=Directory' 'Manager"'
"cn=Directory Manager"

Regards!

...JRF...

Re: scripting differences between hpux and linux

.