![]() |
|
|
|
|
|||||||
| 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 |
| awk Shell Script error : "Syntax Error : `Split' unexpected | Herry | UNIX for Dummies Questions & Answers | 2 | 03-17-2008 08:16 AM |
| syntax error, need to redo one line in script :( | mr_manny | Shell Programming and Scripting | 4 | 01-10-2008 10:20 AM |
| Syntax error in script | KindHead | Shell Programming and Scripting | 2 | 12-12-2006 07:28 PM |
| syntax error in script !! | uuser | Shell Programming and Scripting | 13 | 02-15-2006 11:58 AM |
| problem with script and syntax error message | ReV | Shell Programming and Scripting | 5 | 01-20-2006 03:50 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Syntax error in a script...
Hi All,
I have been fighting with a syntax error for the last 2 days, still haven't got the solution. Could you please help me, your help will be greatly appreciated. In my script I am getting a error in a for loop, its similar to the one as is below. for v_id in v1 v2 v3 v4 do v_flag=`sqlplus -s orauser/passwd@oracle_sid << oratest set feedback off set heading off select 'Y' from mytable where myid = $v_id; exit 5 oratest` if [ $v_flag ] then update the o/p file fi done If the condition fails in the query the v_flag is null, then its giving the error "for not matched" Can't I use the if condition which will be null inside the for loop? Thanks in Advance Raju |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I can's see any reason why not - are you sure that's the problem?
I'd echo out the value of $v_flag for each iteration and see what it actually contains. It may be that it has some unexpected value as a result of the query (such as apostrophe's or quotes) that are throwing the script. |
|
#3
|
|||
|
|||
|
when the query returns nothing then only its giving the error
|
|
#4
|
|||
|
|||
|
Well I'm still not convinced it's because the query's returning nothing. It sounds more like it's returning something the query can't handle, but why not try putting quotes around the variable in the test, ie:-
if [ "$v_flag" ] |
|
#5
|
|||
|
|||
|
You really should add a proper test flag to the if [ $v_flag ] .. as well as putting quotes round the variable as grasper suggests.
Without any arguments the test just checks if the string contains any characters or not. If this is the test you want then write it like: if [ -n "$v_flag" ] The reason you have to put quotes round it is because if the string doesn't contain any characters then the command that gets run is if [ ] which is illegal. As opposed to if [ "" ] Which is what you want to be running. |
|
#6
|
|||
|
|||
|
Thanks for your immediate response.
But its still giving the same error. If I comment the for loop and executing the for a single variable then its fine, but for the "for loop" its giving the error, am checking for the alternatives if any. Regards, Raju |
|
#7
|
|||
|
|||
|
Ok, run the script for each possible value of v_id and echo out the values of $v_flag.
Or alternatively, add the loop back, but edit it each time to run only one of the potential values of v_id and again see what the values of $v_flag are. Cut and paste them in your reply if you can. |
|||
| Google The UNIX and Linux Forums |