syntax error in ksh script
Hi all,
I am new to shell scripting and currently stuck at one place and not able to execute my script. Plz help me out below is my script Code:
#/usr/bin/ksh but after executing above script I am getting error "" ./startMissingFile.ksh: line 52: syntax error near unexpected token `then' ./startMissingFile.ksh: line 52: `if[[ $Day != 0000 ]]; then' Plzzzz help me Thanks, Barkha |
You missed a space between the word if and the square brackets:
Code:
if [[ $Day != 0000 ]] |
thanks Colucix
I have added space between if and square brackets. But now getting another error as below ./startMissingFile.ksh: line 126: syntax error: unexpected end of file Plz let me know now what is going wrong |
You put an extra if two lines after the previous one. Furthermore there is no fi anywhere to close the conditional statement, hence the unexpected end of file.
|
thank you so much Colucix
It worked :) |
Quote:
|
Quote:
Instead, one of the more common mistakes in an if statement is the misuse of the relational operator. If you don't put spaces around the == sign, the shell interprets the whole expression as a single string and it evaluates always as true: Code:
$ a=2 # note: no spaces in assignments |
Quote:
|
Instead of simply asking others to proofread your script, try to understand what the shell is already telling you:
"syntax error" This means that you didn't type a command properly. And that means that you have to go back through the script and find the incorrect command. Usually it will give you a line number or other hint as to where to look. Check the mentioned location carefully. In addition, when it also says "unexpected end of file", that generally means you're missing a closing argument of some kind, a quotation mark, an "fi", or similar. It reached the the end of the script without finding the closing character or string. Unfortunately, the given line numbers in EOF errors may not match the actual location of the mistake. The script will pair up whatever quotation marks it finds, for example, and will only give an error when the last unpaired quotation mark is found. Unmatched quotes can be some of the hardest errors to find. Now if you've gone though you script with a fine-toothed comb and still can't spot the error, then it's ok to ask others to help you. But you should at least make some effort to debug it yourself first. |
One very useful cmd to help debug (if you can't work it out) is
Code:
set -xv http://ss64.com/bash/set.html |
Hi Guys,
I again need ur help. This time I need to send multiple values as paramater. how can I achieve this. eg: In my shell script I accept Region parameter as below if [[ $Region != 0 ]]; then ActualRegion=$Region else ActualRegion='1','2','3' fi Now when the user send Region = 0 in this case I want ActualRegion to be set as '1','2','3' which then I would use in my sql as select * from vendor_table where region in ($ActualRegion) which should be replaced by parameter as below Select * from vendor_table where region in ('1','2','3') Thanks in advance Barkha |
As you should already know, the single quotes are special characters used by the shell to protect strings from shell expansion. If you want to protect the single quote itself, you can either enclose it in double quotes or escape it using bacslashes. In the first case your assignment would be:
Code:
ActualRegion="'1','2','3'" Code:
select * from vendor_table where region in ("$ActualRegion") |
yes thanks it worked :)
|
All times are GMT -5. The time now is 08:13 AM. |