AIX UNIX (kshell) to Linux Shell Script Migration.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AIX UNIX (kshell) to Linux Shell Script Migration.
# 8  
Old 06-18-2014
Quote:
Originally Posted by Kibou
- Variables in AIX inside a test can be without a preceding "$". (This won't work in Linux, so you have to insert a "$" before each variable in a test. Another solution is duplicate "[[" instead of leaving "[ ]" for your test.)
Ahem, this won't work in AIX either. The only place where you can skip the "$" and have the variable expanded anyway is inside double-brackets:

Code:
var=1
(( var = var + 1 ))
print - $var

This is standard ksh and it will definitely work in Linux-ksh as well as in AIX-ksh.


Quote:
Originally Posted by Kibou
- Depends on the code, in my case I have found lots of variables comparing strings without being between double quotes, so we have decided to put double quotes for all variables comparing strings.
The rule is: the comparison will work, regardless if the variable is quoted or not. The problem one avoids with quoting variables is this: if the variable contains whitespace, the expanded variable will lead to a syntax error once it is expanded, because the shell treats the resulting expanded value as two (or more words):

Code:
typeset var="abc"
if [ $var == abc ] ; then         # this is first expanded to
if [ abc == abc ]  ; then         # which is a legal statement

typeset var="abc def"
if [ $var == abc ] ; then                 # this is first expanded to
if [ abc def == abc ]  ; then             # which is NOT a legal statement, but
if [ "$var" == "abc" ] ; then             # this is first expanded to
if [ "abc def" == "abc" ]  ; then         # which is legal again


Quote:
Originally Posted by Kibou
- You have to change the extension of your scripts that are .ksh into .sh.
You might want to do that because otherwise it would be misleading, but it is not required at all. The OS only cares for the shebang and the executable flag and whcih extension the file has doesn't matter at all.

Quote:
Originally Posted by Kibou
- You have to change the path for commands like, I had something like this in AIX:

/usr/bin/fuser

and now it has to be changed into

/bin/fuser
In AIX "/bin" is a link to "/usr/bin". This is one of my 7.1.3-testsystems:

Code:
# ls -l /bin
lrwxrwxrwx    1 bin      bin               8 Feb  5 09:27 /bin -> /usr/bin


Quote:
Originally Posted by Kibou
- tail -n +2 but without -n doesn't work in Linux.
According to the POSIX documents this ("-n <number>") is the modern and suggested form and should be used anyway. If at all the old syntax is only supported for backwards compatibility purposes.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 9  
Old 06-18-2014
I got hit with my ksh scripts just going from RedHat 5 to RedHat 6. Yes, they changed the behavior of the builtin echo command. But they added a "-e" flag to get the old behavior. This means that a script can easily test whih echo is in operation. Just do a "echo -e" and capture the output. If you get "-e" you have the old echo. If you get no characters, you have the new echo.

If I have the old echo, I'm good. My scripts will work the way I want. But if I have the new echo, I'm in trouble. I need to arrange to add the "-e" flag to all of my echo commands. It sounds like a big deal when I explain it, but I really just add a few lines of code to each script near the top (and certainly before any echo statements)...
Code:
function myecho
{
        ''echo -e ${1:+"$@"}
        return $?
}
echo=$(echo -e)
((${#echo})) || alias echo=myecho
unset echo

This User Gave Thanks to Perderabo For This Post:
# 10  
Old 06-18-2014
Quote:
Originally Posted by bakunin
Ahem, this won't work in AIX either. The only place where you can skip the "$" and have the variable expanded anyway is inside double-brackets:

Code:
var=1
(( var = var + 1 ))
print - $var

This is standard ksh and it will definitely work in Linux-ksh as well as in AIX-ksh.
Bakunin, it has just been tested: variables without a preceding $ work in AIX. It works with simple [ ].

We were really surprised about this because we never saw it before. But I am talking about hundreds of scripts written like this for a bank.

At the beginning we thouhgt those scripts didn't work, but after realising that there were hundreds we started to suspect that they actually worked that way.

This is part of the intricacies of the test command, and its peculiar ways.

Quote:
Originally Posted by bakunin
The rule is: the comparison will work, regardless if the variable is quoted or not. The problem one avoids with quoting variables is this: if the variable contains whitespace, the expanded variable will lead to a syntax error once it is expanded, because the shell treats the resulting expanded value as two (or more words):

Code:
typeset var="abc"
if [ $var == abc ] ; then         # this is first expanded to
if [ abc == abc ]  ; then         # which is a legal statement

typeset var="abc def"
if [ $var == abc ] ; then                 # this is first expanded to
if [ abc def == abc ]  ; then             # which is NOT a legal statement, but
if [ "$var" == "abc" ] ; then             # this is first expanded to
if [ "abc def" == "abc" ]  ; then         # which is legal again

You might want to do that because otherwise it would be misleading, but it is not required at all. The OS only cares for the shebang and the executable flag and whcih extension the file has doesn't matter at all.
I know that the only important thing is the shebang. Although it is only a visual matter, to me it looks like something unproperlly finished.. Anyone that sees those scripts without opening them will think that is ksh.
This is my point of view and I explain it like this: if I tell you that I have a friend and my friend's name is Pamela, what would you think? Is it a woman or a man? With the information you have, the name, you suppose that is a girl. I am sure you can "investigate" more and maybe is a boy, but someone with that name looks at first, a girl.

This case is the same, the name is information that could be used to make our life easier, to avoid the need to open the file if the name is self-explicative.

I understand your point though, but I would change the name as well.

I know it is going to be more difficult for the rest of the programs when they have to call the scripts...

Quote:
Originally Posted by bakunin
In AIX "/bin" is a link to "/usr/bin". This is one of my 7.1.3-testsystems:

Code:
# ls -l /bin
lrwxrwxrwx    1 bin      bin               8 Feb  5 09:27 /bin -> /usr/bin

The problem here is that in the scripts from AIX they used something like

Code:
/usr/bin/fuser

so I had to change it into

Code:
/bin/fuser


Quote:
Originally Posted by bakunin
According to the POSIX documents this ("-n <number>") is the modern and suggested form and should be used anyway. If at all the old syntax is only supported for backwards compatibility purposes.

I hope this helps.

bakunin
In the latest version of RHEL it doesn't work without the -n option. I tested it myself.

Regards.
# 11  
Old 06-18-2014
Quote:
Originally Posted by Perderabo
I got hit with my ksh scripts just going from RedHat 5 to RedHat 6. Yes, they changed the behavior of the builtin echo command.
I always preferred the equally builtin "print" over "echo". It has a lot of advantages (the "-u" switch which "echo" lacks, the "-p", ...) and no disadvantages that i know of. Original versions of the Korn shell didn't have the "echo" built in but use the external "/usr/bin/echo", which is why i started the habit of using "print" instead.

Quote:
Bakunin, it has just been tested: variables without a preceding $ work in AIX. It works with simple [ ] .

We were really surprised about this because we never saw it before. But I am talking about hundreds of scripts written like this for a bank.
Could you please post such a script part? I administrate AIX systems for the last 25 years now (started with 3.2.3 on a RS/6000 model 32H) and i never came across such a behavior. To be honest i can't believe that.

Quote:
Although it is only a visual matter, to me it looks like something unproperlly finished.. Anyone that sees those scripts without opening them will think that is ksh .
You are right and i would change that too, no matter what. It still is not a requirement, though, and i wanted to exmphasize that difference.

bakunin

Last edited by bakunin; 06-18-2014 at 04:46 PM..
# 12  
Old 06-19-2014
Quote:
Originally Posted by bakunin
I always preferred the equally builtin "print" over "echo". It has a lot of advantages (the "-u" switch which "echo" lacks, the "-p", ...) and no disadvantages that i know of. Original versions of the Korn shell didn't have the "echo" built in but use the external "/usr/bin/echo", which is why i started the habit of using "print" instead.



Could you please post such a script part? I administrate AIX systems for the last 25 years now (started with 3.2.3 on a RS/6000 model 32H) and i never came across such a behavior. To be honest i can't believe that.



You are right and i would change that too, no matter what. It still is not a requirement, though, and i wanted to exmphasize that difference.

bakunin
The only way is testing it on an AIX machine. Do you have access yourself to an AIX machine so you can test this simple thing?

Code:
cont=1
if [ cont -eq 1 ]
then
  echo "It works"
fi

# 13  
Old 06-19-2014
Quote:
Originally Posted by Kibou
Do you have access yourself to an AIX machine so you can test this simple thing?
I have access to the 300+ AIX systems i am in charge of, ranging from the two 5.3-systems we need to keep at that level to the latest 7.1.3 SP3 and anything in between. Today is my day off, but i will report here what i find out tomorrow.

bakunin
# 14  
Old 06-19-2014
Today is bank holiday in my country so I am not at work either...

300 AIX is a lot ^^ I just need one!

I haven't got as much experience with AIX as you have, but there's a workmate working with me that has been working with AIX for many years as well and he was shocked after testing this code.

I'll wait, no problem. Enjoy your day off!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

AIX 6.1 to Linux 7.2 migration

Hi, recently we have migrated our current AIX server to Linux, we have lot of shell script, few of them are FTP scripts. we have copied the complete AIX file system to linux 7.2 as it is. could you please highlight what are the things we need to look into it . in AIX we are using .netrc to... (3 Replies)
Discussion started by: Riverstone
3 Replies

2. AIX

AIX - FC Switch migration, SAN Migration question!

I'm New to AIX / VIOS We're doing a FC switch cutover on an ibm device, connected via SAN. How do I tell if one path to my remote disk is lost? (aix lvm) How do I tell when my link is down on my HBA port? Appreciate your help, very much! (4 Replies)
Discussion started by: BG_JrAdmin
4 Replies

3. Shell Programming and Scripting

UNIX to Linux Migration

We have certain number of scripts that run on AIX server using ksh. Now that we migrate these scripts to Linux servers. We need to know what are the changes that we have to perform in script to make it compatible to run on Linux. Say like in our Unix -AIX "print" command worked. But that did... (6 Replies)
Discussion started by: SIva81
6 Replies

4. Shell Programming and Scripting

Shell scripts migration from HP-Unix 11 to Red Hat Linux

We are changing our OS from HP-Unix 11 to Linux Red Hat. We have few k- shell, c - shell and sql scripts which are currently running under HP-Unix 11. Will these scripts work on LINUX as it is? or we need to do any code changes?IS there anyone who have done this kind of migration before?Thanks for... (2 Replies)
Discussion started by: Phoenix2
2 Replies

5. Red Hat

Print server Migration from AIX to Linux

Hi, Can anyone help me on migration the print server from AIX to RHEL 4? Appreciate your help? (1 Reply)
Discussion started by: brby07
1 Replies

6. Programming

Migration of C Apps from AIX to LINUX

Hi All, I am currently facing new problem of migrating C(c language) application from AIX machine to Linux machine. We are using GCC to compile the source code.. But facing with the compilation issues, with lot of GCC C libs differing between AIX box to Linux box... Pls help me... (1 Reply)
Discussion started by: karthikc
1 Replies

7. UNIX for Advanced & Expert Users

Migration of C Apps from AIX to LINUX

Hi All, I am currently facing new problem of migrating C(c language) application from AIX machine to Linux machine. We are using GCC to compile the source code.. But facing with the compilation issues, with lot of GCC C libs differing between AIX box to Linux box... Pls help me... (1 Reply)
Discussion started by: karthikc
1 Replies

8. UNIX for Advanced & Expert Users

script migration from HP-UX to AIX

Dear All, What points should i keep in mind while migrating scripts from HP-UX to AIX. Are there any notes available for this? cheers, vishal (1 Reply)
Discussion started by: vishal_ranjan
1 Replies

9. Shell Programming and Scripting

callint Kshell script from bash default shell

I am trying to set some environment variables in a shell script which is written in Kshell. I am invoking this script in .profile. The problem is envirnment variables are set within the script but after exiting the script those are gone. I don't have any problem with If I have Kshell as my default... (0 Replies)
Discussion started by: roopla
0 Replies

10. Shell Programming and Scripting

SCO UNIX to Linux migration

hi all i m working in a company ...and i have to migrate a C application running on SCO-UNIX to Red hat linux. can anybody tell me what is the difference between C commands and shell scripting on SCO-UNIX and LINUX. best regards harsh (3 Replies)
Discussion started by: vickey
3 Replies
Login or Register to Ask a Question