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.
# 22  
Old 06-24-2014
If there really is no loop to break from, then I suspect that ksh is just ignoring the statement. The end of each case section is the ;; so logically I suppose it all hangs together.

I've had a go on AIX 5.1 & 6.1 and it just ignores the break statement. On RHEL 6 with ksh it is ignored, but the error you find pops up with bash



Robin
# 23  
Old 06-24-2014
So, i take it, this is because "[" is a shell builtin. (Which it is indeed - i had the wrong impression that "[" is external and "[[" is the builtin, but i learned otherwise through experiment. In fact "[" is a builtin and "[[" is a reserved word, according to my system shell on AIX, a ksh88.)

This seems to be in line with the following analogous lines, where "x" and "$x" can be used interchangeably:

Code:
x=5 ; let x=x+1
x=5 ; let "x = x + 1"
x=5 ; (( x += 1 ))
x=5 ; echo $(( x ))

I wonder how the parsing process of the ksh works so that this is only the case for integers (or - for the shell obviously being the same - strings which evaluate to integers). One would think that variables either get expanded or not, but it would not depend on their content if they are.

bakunin
# 24  
Old 06-24-2014
Quote:
Originally Posted by Kibou
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.
The standards say:
Quote:
The break utility shall exit from the smallest enclosing for, while, or until loop, if any; or from
the nth enclosing loop if n is specified.
It looks like bash writes a warning message to stderr (but does not affect the exit status) in this case while ksh behaves as specified by the standards (silently ignoring the fact that your code is issuing a break when there is no enclosing loop).
This User Gave Thanks to Don Cragun For This Post:
# 25  
Old 06-24-2014
Quote:
Originally Posted by bakunin
So, i take it, this is because "[" is a shell builtin. (Which it is indeed - i had the wrong impression that "[" is external and "[[" is the builtin, but i learned otherwise through experiment. In fact "[" is a builtin and "[[" is a reserved word, according to my system shell on AIX, a ksh88.)

This seems to be in line with the following analogous lines, where "x" and "$x" can be used interchangeably:

Code:
x=5 ; let x=x+1
x=5 ; let "x = x + 1"
x=5 ; (( x += 1 ))
x=5 ; echo $(( x ))

I wonder how the parsing process of the ksh works so that this is only the case for integers (or - for the shell obviously being the same - strings which evaluate to integers). One would think that variables either get expanded or not, but it would not depend on their content if they are.

bakunin
I haven't dug into the source of any of these shells, but my impression is not that the shell looks at the contents of the variables, but the context of how the variable is used. In an arithmetic evaluation, when a number is expected and a non-numeric string is seen I would guess that it looks for a variable of that name and substitutes it if it works. Note that let expr, (( expr )), $(( expr )), and [ n1 -eq|-ne|-lt|-le|-ge|-gt n2 ] are all arithmetic evaluations.

PS. Even when test and [ are built-ins, they also have to be available as stand alone utilities (so they can be used with things like find dir -exec test expr \;) like other standard utilities.

Last edited by Don Cragun; 06-24-2014 at 06:31 PM.. Reason: Add postscript.
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