Problem with Korn Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with Korn Shell
# 15  
Old 04-08-2008
Code:
!#/usr/bin/ksh
RecCount=`db2 -x "select count(*) from schema.table"`
RecCount2=`db2 -x "select count(*) from schema.table2"`
if [[ ${RecCount} == "0" && ${RecCount2} == "0" ]]
then
print $RecCount
print $RecCount2
fi

exit 0

# 16  
Old 04-08-2008
sorry... should have explained.

if [ ${RecCount} == "0" && ${RecCount2} == "0" ]
&& will not work in the [......] construct. therefore, you need [[ $condition1 && $condition2 ]]

if [ ${RecCount} == "0" -a ${RecCount2} == "0" ]
this will work.
# 17  
Old 04-08-2008
almost there.....

My script almost works. Now, I'm not getting any errors, but the values for RecCount and RecCount2 are not printing. I tried running the following commands outside of the shell and got results of 3000000 and 5000000, so I know that the tables contain data:

>db2 -x "select count(*) from schema.table"
>db2 -x "select count(*) from schema.table2"
# 18  
Old 04-08-2008
ok i see what went wrong here.

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

exit 0

you can also use echo instead of print. its up to you. however, it was not printing to screen because the condition was failing. it was doing what it was supposed to do.

Last edited by pupp; 04-08-2008 at 09:42 PM..
# 19  
Old 04-09-2008
In RED in the code ...

Quote:
Originally Posted by sasaliasim
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.

Code:
#!/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"` # Changed ' to `
if [ ${RecCount} -ne 0 ] && [ ${RecCount2} -ne 0 ]
then
    print $RecCount
    print $RecCount2
fi

# 20  
Old 04-09-2008
Code:
#!/usr/bin/ksh

# 21  
Old 04-09-2008
Thanks, pupp! Your solution worked!
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