Korn shell behaviour in AIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Korn shell behaviour in AIX
# 1  
Old 11-08-2012
Korn shell behaviour in AIX

Hi,

Consider the code snippet below:

Code:
 
fun()
{
while read x
do
echo $x
done < somefile_that_does_not_exists
}
 
fun
echo I am here

Korn shell on HPUX prints the message "I am here", while the behaviour is different on AIX korn shell. We do not get the message on AIX. Any clues on how to get a similar behaviour.

Thanks in Advance.
# 2  
Old 11-08-2012
It works for me if I execute it this way:
Code:
./testcode

This was done on AIX 5.2
# 3  
Old 11-08-2012
Yes, well I have it running on HP-UX with a file not found error then the "I am here" bit, but on AIX 6.1, AIX 5.1 (please don't laugh yet) and ...... AIX 4.3.3 Smilie I just get the file not found error and the script aborts.

I also inserted
Code:
 #!/bin/ksh

as the first line to be sure, but no change. I presume that this is suddenly a good reason to use cat!!!

If I write this in my natural style as
Code:
#!/bin/ksh
fun()
{
cat some_file_that_does_not_exist | while read x
do
echo $x
done 
}

fun
echo I am here

...it works fine on AIX too.


Can anyone explain the mismatch?


.... and here's me battling my instincts to avoid a useless use of cat such as cat $file | while code. Smilie



Robin
Liverpool/Blackburn
UK
# 4  
Old 11-08-2012
Seems a bit sloppy to me. Wouldn't it just be better to check if the file exists first?
# 5  
Old 11-08-2012
"cat" must not be letting ksh exit if the file is not found. But with the file redirected to a while loop, the shell exits in AIX.

Any ideas if a flag/set option with ksh works on AIX?
# 6  
Old 11-08-2012
I would do what Scott suggested and check to see if the file exist. If it does then perform your commands if not then exit the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Strange behaviour in AIX

Can someone please explain the strange behaviour.. I was just trying a few things to learn awk.. in the below code when I start the braces in the same line, the output is as expected, when I start at next line, output is displayed twice. Please see the file, code I tried and output below. ... (2 Replies)
Discussion started by: Kulasekar
2 Replies

2. Shell Programming and Scripting

Inconsistent behaviour of sed - UNIX AIX 5.3

Hi there. I'm facing a strange & an intriguing behaviour with sed while replacing the tab character with a space reading from a file. It randomly works sometimes but mostly doesn't work. Below is what's happening- <tab> here is the actual literal tab. user1> cat temp2 1<tab>2<tab>3 4... (2 Replies)
Discussion started by: Deepak.Dhami
2 Replies

3. Shell Programming and Scripting

Command substitution inside of a variable expression (AIX, KORN)

Hello all. This is my first post/question on this site. I’m a new Systems Analyst with previous experience with BASH. Although now I'm using AIX, and I’m trying to get a feel for the Korn shell (for those of you that don’t know AIX only uses the KORN shell). I hope I put this into the correct... (10 Replies)
Discussion started by: sydox
10 Replies

4. Shell Programming and Scripting

Help when using Typeset in AIX Korn Shell

Guys, please help! I am currently using an AIX server however whenever I tried to use the typeset -F3, the variable is resulting with a "#". In the given example below, I declared x to be a decimal holding 3 decimal places = 1.455. However whenever I tried to echo the $x, the resulting value... (9 Replies)
Discussion started by: zzavilz
9 Replies

5. UNIX for Dummies Questions & Answers

List of 'if -f' options - AIX / Korn Shell

Hi all, Can someone point me in the right direction for a manual on the various statement options for 'if'. Basically I have a piece of code which says: if ] and I wondered what the -f was. I know the '!' means not equal.. As usual any help much appreciated.. (5 Replies)
Discussion started by: Grueben
5 Replies

6. UNIX for Dummies Questions & Answers

shell: reconcile language and sort behaviour

Hi Don't know if this is a dummy question, but let's give it a try. I yesterday had a problem with undefined behaviour in the sort shell command (I'm using bash), leading to different sort orders without apparent reasons. I resolved this by typing export LC_ALL="C" export LC_COLLATE="C"... (5 Replies)
Discussion started by: jossojjos
5 Replies

7. Shell Programming and Scripting

AIX Korn shell sed -s problem

In a Korn shell script I have, cat ../header | sed -e 's/flag1/$cnumb/g' > header.txt The header is short {{Company flag1}} But the result in header.txt is {{Company $cnumb}} The value of $cnumb is 120. I am trying to get the value of $cnumb into the header. I have tried /'$cnumb'/g,... (10 Replies)
Discussion started by: jcarrott
10 Replies

8. Shell Programming and Scripting

Spaces behaviour in shell

Hello, I am a bit puzzled by the way my shell treats spaces in filenames. An example will be way clearer than any explanation I can make: $ ls test\ file\ with\ spaces test file with spaces $ var="test\ file\ with\ spaces" $ echo $var test\ file\ with\ spaces $ ls $var ls: cannot... (4 Replies)
Discussion started by: SDelroen
4 Replies

9. AIX

AIX 4.2 Korn shell and grep question

Ho do I find out the verion of the Kron shell on my client`s system ? There is no one to ask. They are not knowledged enough (hard to believe but yes). Also, on that AIX 4.2, I am trying to figure out how to do a grep using a search patter like below but does not seam to work. The '*' do... (11 Replies)
Discussion started by: Browser_ice
11 Replies

10. Shell Programming and Scripting

any explanation for thsi shell script behaviour

hello whats the difference between excuting a shell script as a)sh myscript.sh b). ./myscript.sh i noticed that my shell script works fine when i run it as . ./myscript .sh but fails when i run it as sh myscript.sh could anybody explain why. the shell script is very simple ... (9 Replies)
Discussion started by: xiamin
9 Replies
Login or Register to Ask a Question