Problem with Korn Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with Korn Shell
# 1  
Old 04-07-2008
Problem with Korn Shell

My Korn shell script below is giving me the following error: ./test.ksh[6]: 0403-057 syntax error at line 7 : 'then' is not matched.

Can anyone provide a quick solution as to why the error is occurring? Thanks.

#!/usr/bin/ksh
typeset -i RecCount
typeset -i RecCount2
RecCount=`db2 -x "select count(*) from schema.table"`
RecCount2='db2 -x "select count(*) from schema.table2"`
if [[ ${RecCount} -ne 0 && ${RecCount2} -ne 0 ]]
then
print $RecCount
print $RecCount2
fi

Last edited by DukeNuke2; 04-07-2008 at 06:32 PM..
# 2  
Old 04-07-2008
You can't have && inside [[...]]. I believe -a is what you are looking for.

(Caveat: bash bigot here.)

Last edited by era; 04-07-2008 at 04:14 PM.. Reason: Forum software didn't like "[[ ]]"
# 3  
Old 04-07-2008
Making the change you suggested resulted in the following error:

./test.ksh[6]: 0403-057 syntax error at line 6: '-a' is not expected.
# 4  
Old 04-07-2008
Quote:
Originally Posted by era
You can't have && inside [wiki]...[/wiki]. I believe -a is what you are looking for.

(Caveat: bash bigot here.)
Should not be the problem:

[Chapter 5] Flow Control

What is the output of the SQL statements?

Regards
# 5  
Old 04-07-2008
Quote:
Originally Posted by era
You can't have && inside [[...]]. I believe -a is what you are looking for.

(Caveat: bash bigot here.)
In ksh you can have && inside of double brackets.

There might be non-printing characters embedded in your shell script. Run it thru od to see if there are any control characters in it.

Code:
od -c shell_script

# 6  
Old 04-07-2008
I just ran my script through od -c shell_script, and did not see any control characters.
# 7  
Old 04-07-2008
My two sql statements give me results of:3500000 and 5578000 respectively.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

self-learning! my korn shell problem

i am a beginner i m learning shell by myself i have problem writing a korn shell that takes an absolute pathname to directory and display all ordinary files in the directory ordered by their length. i was thinking use grep ls sort and sed. maybe, i m wrong! can someone tell me? (2 Replies)
Discussion started by: babuda0059
2 Replies

2. Shell Programming and Scripting

korn shell display lenght problem!!! i got stuck on this

Using the KSH, write a shell script called display_by_length, which takes an absolute pathname to a directory and displays all ordinary files in the directory ordered by their length; for each file listed, display the name of the file and its length - nothing else. Extend this script to take an... (1 Reply)
Discussion started by: babuda0059
1 Replies

3. Shell Programming and Scripting

unix korn shell leap years problem

Write a function called dateToDays that takes three parameters -a month string such as Sep, a day number such as 18, and a year number such as 1962-and return s the number of days from January 1, 1900, to the date. Notes: I am asking you to account for leap years. my script is not... (0 Replies)
Discussion started by: babuda0059
0 Replies

4. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

5. 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

6. Shell Programming and Scripting

korn shell automation problem!

I got the task writting Korn Shell script to automate the tuxedo login so that users neednot have to enter options manually. I have done that using expect tool from the Unix but my manger told me its not secure so you have to do that using Kornshell without using Expect. Here is the way to login to... (0 Replies)
Discussion started by: pareshan
0 Replies

7. UNIX for Dummies Questions & Answers

problem extracting substring in korn shell

hi all, I have read similiar topics in this board, but i didn' t find the posting which is the same with the problem i face.. I try to extract string from the end. i try to do this: num=abcdefghij num2=${num:-5} echo $num2 #this should print the last 5 characters (fghij) but it doesn;t... (3 Replies)
Discussion started by: nashrul
3 Replies

8. Shell Programming and Scripting

problem with set command in korn shell

I have to copy an array to a temp variable and back after doing some functions. I am trying to see if it is possible to do without while loops.My closest try was set -A temp ${THE_ARRAY} # restore array after some actions set -A THE_ARRAY ${temp} The problem with above is that, the new... (1 Reply)
Discussion started by: vijay1985
1 Replies

9. Shell Programming and Scripting

how to convert from korn shell to normal shell with this code?

well i have this code here..and it works fine in kornshell.. #!/bin/ksh home=c:/..../ input=$1 sed '1,3d' $input > $1.out line="" cat $1.out | while read a do line="$line $a" done echo $line > $1 rm $1.out however...now i want it just in normal sh mode..how to convert this?... (21 Replies)
Discussion started by: forevercalz
21 Replies

10. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question