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.
# 15  
Old 06-20-2014
Quote:
Originally Posted by Kibou
Code:
cont=1
if [ cont -eq 1 ]
then
  echo "It works"
fi


I first tried it on my NIM-Server, which happens to be also my script development system. Its version is basically 7.1 SP2. The first try is with the system shell (which is a ksh88), the second with the ksh93:

Code:
# lslpp -l bos.rte
  Fileset                      Level  State      Description         
  ----------------------------------------------------------------------------
Path: /usr/lib/objrepos
  bos.rte                   7.1.2.15  COMMITTED  Base Operating System Runtime

Path: /etc/objrepos
  bos.rte                   7.1.2.15  COMMITTED  Base Operating System Runtime
# instfix -i | grep ML
    All filesets for 7.1.0.0_AIX_ML were found.
    All filesets for 7100-00_AIX_ML were found.
    All filesets for 7100-01_AIX_ML were found.
    All filesets for 7100-02_AIX_ML were found.

# Version M-11/16/88f
# cont=1
# if [ cont -eq 1 ]
>then
>  echo "It works"
>fi
It works

# ksh93
# print - ${.sh.version}
Version M 93t+ 2009-05-01
# if [ cont -eq 1 ]
>then
>  echo "It works"
>fi
It works

To be honest, i'm dumbfounded. I would have never expected that to run. Btw., this only works with integers, not with strings:

Code:
foo="abc"
if [ foo == abc ] ; then
     print - "It works"
fi

will work as expected - which is: not work at all.

I got adventurous and tried to make the datatype more "stringy" and less "integerly":

Code:
typeset -RZ3 foo=1
# typeset -RZ3 foo="01"

print - $foo
if [ foo -eq 1 ] ; then
     print - "It works"
fi

both of which works too - "foo" gets expanded.

The next thing i wondered was: is this specific to the AIX-ksh? In fact it is not. My colleague from the Linux-team tried it on a couple of our SLES11-servers and the ksh93 there worked the same. As it seems this is no specific feature of the AIX-shell but a common treat of the Korn shell.

I hope this helps.

bakunin

Last edited by bakunin; 06-20-2014 at 05:45 AM.. Reason: typo
These 2 Users Gave Thanks to bakunin For This Post:
# 16  
Old 06-20-2014
Quote:
Originally Posted by bakunin
I first tried it on my NIM-Server, which happens to be also my script development system. Its version is basically 7.1 SP2. The first try is with the system shell (which is a ksh88), the second with the ksh93:

Code:
# lslpp -l bos.rte
  Fileset                      Level  State      Description         
  ----------------------------------------------------------------------------
Path: /usr/lib/objrepos
  bos.rte                   7.1.2.15  COMMITTED  Base Operating System Runtime

Path: /etc/objrepos
  bos.rte                   7.1.2.15  COMMITTED  Base Operating System Runtime
# instfix -i | grep ML
    All filesets for 7.1.0.0_AIX_ML were found.
    All filesets for 7100-00_AIX_ML were found.
    All filesets for 7100-01_AIX_ML were found.
    All filesets for 7100-02_AIX_ML were found.

# Version M-11/16/88f
# cont=1
# if [ cont -eq 1 ]
>then
>  echo "It works"
>fi
It works

# ksh93
# print - ${.sh.version}
Version M 93t+ 2009-05-01
# if [ cont -eq 1 ]
>then
>  echo "It works"
>fi
It works

To be honest, i'm dumbfounded. I would have never expected that to run. Btw., this only works with integers, not with strings:

Code:
foo="abc"
if [ foo == abc ] ; then
     print - "It works"
fi

will work as expected - which is: not work at all.

I got adventurous and tried to make the datatype more "stringy" and less "integerly":

Code:
typeset -RZ3 foo=1
# typeset -RZ3 foo="01"

print - $foo
if [ foo -eq 1 ] ; then
     print - "It works"
fi

both of which works too - "foo" gets expanded.

The next thing i wondered was: is this specific to the AIX-ksh? In fact it is not. My colleague from the Linux-team tried it on a couple of our SLES11-servers and the ksh93 there worked the same. As it seems this is no specific feature of the AIX-shell but a common treat of the Korn shell.

I hope this helps.

bakunin
Thanks! wow so it's a korn shell issue and it behaves the same way in Linux. That's another important step..

We were completly shocked as well.

I'd like to share the story. This is what happened:

- First we found out that a lot scripts were "wrong", which is very strange because is a bank..
- We asked the bank, because we are outsourced, about this issue, and they said: you are right, those scripts are wrong. (lol)
- Then we decided we had to fix that so those scripts work properly in RHEL now. But.. wait! if there are a lot of scripts that didn't work for years, if you now make them work.. what will it happen???
So we agreed to fix it only and just only we had the approval of all the people in charge.
The next day we got an email saying: No, don't "fix" anything at the moment and just take notes of when you found something is wrong.
- As we kept going we saw more and more scripts.. hundreds.. so what's going on??
- Then someone saw the light and realised that those scripts actually work. I was so shocked and puzzled I said to my manager: alright! I'm leaving! lol
- So I don't know what kind of mess they have they don't even know about which script is working, etc........
- The thing is that now we haven't got any more time to do those changes manually so we had to think about how to do a massive change tool to change all scripts and make them have the preceding "$" in each case, whithout messing them all up, and messing all the work we had done already. This was a problem, because it seemed kind of easy, just a matter of finding the right regular expression.. but we found out that it didn't work properly and not only worked.. but it messed up some scripts.. so we ended up using a higher level language and, instead of using regular expressions, something far less elegant but more effective: searching for the lines where there were a variable wihtout a "$", filtering it into the unique lines, and then modifiy it manually and make a file with the origin and the target, separated with "@@@" (as an example). We used a higher level language to make the substitution in all scripts and it worked perfectly except for 200 scripts, with just scripts that didn't work.
We have been working monday to sunday lately..

So now I believe in God again lol!
# 17  
Old 06-22-2014
Quote:
Originally Posted by bakunin
I got adventurous and tried to make the datatype more "stringy" and less "integerly":

Code:
typeset -RZ3 foo=1
# typeset -RZ3 foo="01"

print - $foo
if [ foo -eq 1 ] ; then
     print - "It works"
fi

both of which works too - "foo" gets expanded.
Yes, even these seem to work:

Code:
foo=8#14
[ foo -eq 12 ] && print - "It works"

foo=21+3-0x0A
[ foo -eq 14 ] && print - "It works"

# 18  
Old 06-23-2014
Addendum: i got me a Ubuntu system and the code works there too. This seems to be a ksh issue rather than an AIX issue:

Code:
# echo ${.sh.version}
Version JM 93t+ 2010-03-05
# foo=1
# if [ foo -eq 1 ] ; then echo "works" ; fi
works

Systems tested to behave in the described manner so far:

AIX
SLES 11
Ubuntu 10.04 LTS

bakunin
# 19  
Old 06-23-2014
Also Solaris 10:
Code:
$ uname -rs
SunOS 5.10
$ foo=1
$ if [ foo -eq 1 ] ; then echo "works" ; fi
works

# 20  
Old 06-24-2014
Quote:
Originally Posted by Kibou
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

I was asked to take a look at this and comment on what the standards say about this ksh behavior. The standards leave unspecified what happens if both operands of the test -eq, -ne, -lt, -le, -gt, and -ge binary primaries are not integer operands.

The standards allow, but do not require the test expression and [ expression ] utilities to be implemented as shell built-ins (as they are in bash and ksh)). If test and [ ... ] aren't implemented as shell built-ins, there is no way that the behavior shown here would be possible. In ksh (at least ksh on AIX and on OS X), if a variable name is given where a number is needed in these cases, the value of the variable is substituted into the expression even when the $ is not present.

The standards specify this behavior for arithmetic expansions. That is, the sequences:
Code:
n=0
while [ $n -lt 5 ]
do      printf "%d\n" $(($n++))
done

and:
Code:
n=0
while [ $n -lt 5 ]
do      printf "%d\n" $((n++))
done

are required to do the same thing. So, it seems like a logical extension to me to not require the $ in the expression in these test exp ([ exp ]) expressions either.

Obviously, this need not be portable to other shells and might not even be portable to other versions of ksh.

Last edited by Don Cragun; 06-24-2014 at 03:04 AM.. Reason: Add note about portability.
These 3 Users Gave Thanks to Don Cragun For This Post:
# 21  
Old 06-24-2014
Another thing.

If testing something like this (contents of test.sh)
(This code is not inside a loop.)

Code:
var3=1
case $var3 in
  1) var1=1
     break ;;
  2) var1=1
     var2=2
     break ;;
  *) echo "Error" ;;
esac

The thing is that when executing this code with ksh (RHEL 6.5) there's no error message from the shell.

But when executing with bash there's an error message when case has to evaluate a condition with break. When executed with ksh or sh, there's no error message.

Code:
[root@xxxx]# bash test.sh
test.sh: line 5: break: only meaningful in a `for', `while', or `until' loop
[root@xxxx]# ksh test.sh
[root@xxxx]# sh test.sh

As far as I know, break it has sense only when there's a loop. But since there's no error message for ksh and sh it looks like the behaviour for case is different from bash.

case syntax without break works fine in ksh and sh, with no error messages. Same with bash, as expected.

Any thoughts about this behaviour?

This is probably the same behaviour in ksh-AIX but I couldn't access a machine to test it right now.

Last edited by Kibou; 06-24-2014 at 10:15 AM.. Reason: Clarification
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