![]() |
Shell Scripting "syntax error : unexpected end of file"
hey
I am very new to shell scripting and keep getting this error message so any advice would be gladly received! I have simplified my code majorly and still get the same error so there's obviously something wrong with my basic syntax. #usr/bin/sh if [$1 -lt $2]; then echo "done" else echo "nope" fi Thanks :) |
Quote:
Code:
#usr/bin/shNormally you need spaces between the if and brackets, ... |
BTW, if you are very new to shell scripting you might like to start off with the habit of using [[ ]] rather than [ ] for reasons explained here.
|
hey
i copied and pasted your code and i still got the same error - i also tried using [[ but still got the same error |
Works for me.
Try runnning 'dos2unix /path/to/your/script' and try the script again. Dave |
The #usr/bin/sh is strange. Try changing it to #!/bin/bash
|
Hi -
Please try this: Code:
#!/bin/sh* On most Linux systems, "/bin/sh" is an alias to "bash" * For portability, I used "sh" syntax (instead of bash extensions) * I checked to make sure we had (at least) two arguments, using "$#" * When using "[ ]" syntax, you need spaces before and after the brackets * The reason is that "[ ]" is itself an alias (an alias for the shell "test" command) * Always use "code blocks" (the little "#" icon on your LQ toolbar) :) 'Hope that helps .. PSM |
hi
PSM - when I ran your code I got an error message saying 'fi' unexpected on line 12 Dave - when I ran the dos2unix command nothing changed either Thanks for the help btw :) |
Hi -
Quote:
Please try again and see what happens. |
Am still getting the end of file unexpected error (it saved in the wrong place before so was still running the old one)
|
Quote:
Quote:
Quote:
1. cd to your "/tmp" directory 2. Create a file called "tmp.sh" 3. Cut and paste the contents of this file EXACTLY 4. Set "execute" permissions (by running "chmod +rx tmp.sh") 5. Run the file ("./tmp.sh") with no arguments 6. Run the file with two numeric arguments ("./tmp.sh 1 2", or "./tmp.sh 10 9") 7. Post back the results 8. When you post back, please be sure to cut/paste YOUR version of the shell script that you executed. Use code blocks (the "#" symbol on the LQ toolbar). Thank you in advance .. PSM |
Thank you so much! That's now working fine. I will continue working that way from now on.
Thanks again for your help :) |
Please mark as SOLVED
|
| All times are GMT -5. The time now is 11:33 AM. |