![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare two dates using Shell Programming | dave_nithis | Shell Programming and Scripting | 4 | 01-04-2008 02:18 AM |
| how to compare text value in shell | reply2soumya | UNIX for Advanced & Expert Users | 2 | 06-19-2007 10:03 AM |
| How to recognize that the server is currently unavailable? | munna_dude | High Level Programming | 2 | 03-09-2007 09:16 PM |
| How to compare the dates in shell script | vaji | Shell Programming and Scripting | 9 | 02-27-2007 09:34 PM |
| Doesn't recognize the mv command | zoolz | Shell Programming and Scripting | 2 | 11-14-2005 07:20 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
shell script cant recognize if else compare
hi
I face the problem the if else statement dint return correct result for me my script as below: #!/bin/ksh sqlplus -s /nolog <<EOF connect databaseuser/password column num new_value num format 9999 set head off select count(*) num from table1; exit num EOF if [ $? -gt 10 ]; then echo "$?" else echo "stop" fi ----- How I know $? is integer? Is it because both is not integer so cant go the compare?? Any one please help , Thanks and regards, Jase |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
what exactly your if is returning?
|
|
#3
|
|||
|
|||
|
What are you actually trying to compare with 10? If it is the output of the query i.e. (count(*) ) that you are trying to compare with 10 then you can use the following code.
#!/bin/ksh RESULT=`sqlplus -s /nolog <<EOF connect databaseuser/password set head off select count(*) from table1; EOF` if [ $RESULT -gt 10 ]; then echo $RESULT else echo "stop" fi |
|
#4
|
|||
|
|||
|
Thanks for your reply
Yes, I need to compare the result from the query, if the count(*) > 10 then some action I need to take...but it seem like the result is not integer..so it cant be compare with number.. got any way to convert it to integer.. sowjanya.addala I had try this before but the RESULT cant go to proceed the sql statement inside. The value of the RESULT is just capture the SQL statement not the output query. any way appreciate your help. regards, Jase Last edited by jaseloh; 12-05-2005 at 05:46 PM. |
|
#5
|
|||
|
|||
|
look at this
#!/bin/ksh RESULT=`sqlplus -s /nolog <<EOF connect databaseuser/password set head off spool log; select count(*) from table1; EOF` RESULT=`head log.lst` if [ $RESULT -gt 10 ]; then echo $RESULT else echo "stop" fi |
|
#6
|
||||
|
||||
|
Things are being unnecessarily complicated here. Try this:
Code:
#!/usr/bin/ksh count=$(sqlplus -s /nolog << !|egrep -v "^$|Connected" conn user/passwd; set head off feed off; select count(*) from some_table; quit; !) echo $count |
|
#7
|
|||
|
|||
|
Problem solve
Hi all,
Thanks for your help. my problem solve. I jst change the #!/bin/ksh to #!/bin/sh, then it can work properly. But I dont know why.... regards, Jase |
|||
| Google The UNIX and Linux Forums |