Results 1 to 10 of 17
Hi, i wonder if someone could help me. I'm new to shell scripts and i've tried to write this script, the aim of it is to check if the $4, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-21-2005 #1Just Joined!
- Join Date
- Nov 2005
- Location
- University of Bath, UK
- Posts
- 8
Problems with my automation script
Hi, i wonder if someone could help me. I'm new to shell scripts and i've tried to write this script, the aim of it is to check if the $4, $5 etc variables are empty to avoid annoying errors when the program it calls tries to process an non existant file with no name
I'm running fedora core 4 if that makes any difference.
I have two main problems
ONE
++++++++++++++++++
the #!/bin/bash line as causes this error:
: bad interpreter: No such file or directory
the script (in an earlier simpler form) ran fine without it so i left it out for the time being
TWO
In it's new form the script keeps exiting with:
subst.codon: line 42: syntax error: unexpected end of file
Code:1 if ["$4" -ne ""] 2 then 3 subst -n $1 -p 1 -i "$4" $3 > ../output/$2/subst.codon/$4.1.txt; 4 subst -n $1 -p 2 -i "$4" $3 > ../output/$2/subst.codon/$4.2.txt; 5 subst -n $1 -p 3 -i "$4" $3 > ../output/$2/subst.codon/$4.3.txt; 6 elseif ["$5" -ne ""] 7 then 8 subst -n $1 -p 1 -i "$5" $3 > ../output/$2/subst.codon/$5.1.txt; 9 subst -n $1 -p 2 -i "$5" $3 > ../output/$2/subst.codon/$5.2.txt; 10 subst -n $1 -p 3 -i "$5" $3 > ../output/$2/subst.codon/$5.3.txt; 11 elseif ["$6" -ne ""] 12 then 13 subst -n $1 -p 1 -i "$6" $3 > ../output/$2/subst.codon/$6.1.txt; 14 subst -n $1 -p 2 -i "$6" $3 > ../output/$2/subst.codon/$6.2.txt; 15 subst -n $1 -p 3 -i "$6" $3 > ../output/$2/subst.codon/$6.3.txt; 16 elseif ["$7" -ne ""] 17 then 18 subst -n $1 -p 1 -i "$7" $3 > ../output/$2/subst.codon/$7.1.txt; 19 subst -n $1 -p 2 -i "$7" $3 > ../output/$2/subst.codon/$7.2.txt; 20 subst -n $1 -p 3 -i "$7" $3 > ../output/$2/subst.codon/$7.3.txt; 21 elseif 22 if ["$8" -ne ""] 23 then 24 subst -n $1 -p 1 -i "$8" $3 > ../output/$2/subst.codon/$8.1.txt; 25 subst -n $1 -p 2 -i "$8" $3 > ../output/$2/subst.codon/$8.2.txt; 26 subst -n $1 -p 3 -i "$8" $3 > ../output/$2/subst.codon/$8.3.txt; 27 elseif ["$9" -ne ""] 28 then 29 subst -n $1 -p 1 -i "$9" $3 > ../output/$2/subst.codon/$9.1.txt; 30 subst -n $1 -p 2 -i "$9" $3 > ../output/$2/subst.codon/$9.2.txt; 31 subst -n $1 -p 3 -i "$9" $3 > ../output/$2/subst.codon/$9.3.txt; 32 elseif ["$10" -ne ""] 33 then 34 subst -n $1 -p 1 -i "$10" $3 > ../output/$2/subst.codon/$10.1.txt; 35 subst -n $1 -p 2 -i "$10" $3 > ../output/$2/subst.codon/$10.2.txt; 36 subst -n $1 -p 3 -i "$10" $3 > ../output/$2/subst.codon/$10.3.txt; 37 else 38 exit; 39 endif 40 echo "All Done!"; 41 exit 0;
I've tried it with and without exit 0 at the end and that made no difference
Thanks for any help
Kev
- 11-21-2005 #2
1. Try changing it to:
2. Please post the entire script inside [code] tagsCode:#!/usr/bin/bash
- 11-22-2005 #3Just Joined!
- Join Date
- Nov 2005
- Location
- University of Bath, UK
- Posts
- 8
Thanks for the speedy reply
Anywho i've tried changing the first line as you suggested and that had no effect. I still get the same error message even with
however the script will run without that line so i'm not too bothered by it my main issue is the rest of my script and the unexpected end of file problem.Code:#!/usr/bin/bash
Unless of course the issue with the first line is a symptom of a bigger problem as it happens with my perl scripts as well even when the path is correct.
- 11-22-2005 #4Linux User
- Join Date
- Aug 2005
- Location
- Italy
- Posts
- 401
Shell program
The very first line indicates wich program can handle the following script... so if you specify #!/bin/bash, /bin/bash must exists and must executable. I suggest to put /bin/sh, wich should be a soft link to the default sheel of the system.
About your error... you should numer all lines (cat can do it for you!
).
When using Windows, have you ever told "Ehi... do your business?"
Linux user #396597 (http://counter.li.org)
- 11-23-2005 #5Just Joined!
- Join Date
- Nov 2005
- Location
- University of Bath, UK
- Posts
- 8
Thanks burnit but, I've tried all versions of the first line and bash is def in my /bin folder and executable. even #!/bin/sh doesn't work
Any ideas why #! line isn't working in any of my scripts (including perl)
Also i've modified my first post to include line numbers, hopefully that helps.
- 11-23-2005 #6
Please remove the line numbers, it is very hard to read.
- 11-23-2005 #7Just Joined!
- Join Date
- Nov 2005
- Location
- University of Bath, UK
- Posts
- 8
burnit recommended adding the line numbers, which i tend to agree with as it makes it easier to identify which lines the errors are referring to.
It should be fairly easy to read the code with the line numbers, as they're fairly well separated.
- 11-23-2005 #8
First, confirm that your bash is where it should be, which, if it's your default shell is /bin/bash
then be sure to invoke your script with an explicit pathname if it's not in a directory covered by your normal path (ie, use "./" if it's in your current directory)Code:which bash
As for the rest, well, it doesn't look like a bash script to me. What are you using for a reference?Code:./scriptname
For example, I'd expect to see if/elif/fi rather than if/elseif/endif and no semicolons as line terminators in a bash script.noobus in perpetuum
- 11-25-2005 #9Just Joined!
- Join Date
- Nov 2005
- Location
- University of Bath, UK
- Posts
- 8
my bash is definately where it should be, /bin/bash
so i'm not sure why it's having issues, if i add a switch to the line eg
then it recognises bash as the interpreter but givesCode:#!/bin/bash --debug
and then the bash switch list:invalid option
i'm running the script from /bin
I can't remember the website is used for reference. I removed all the semicolons and switched everything to if/elif/fi and it gave the following error:
I also tried changing the endif to fi and elseif to elsif, which fixes the above problem but that still makes no difference to the 'unexpected end of file' error.Code:/bin/subst2.codon: line 6: syntax error near unexpected token `elif' 'bin/subst2.codon: line 6: `elif ["$5" -ne ""]
- 11-26-2005 #10Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
You need whitspace after the [ of the if conditions:
The [ must be whitespace separated because it's a synonym for the "test" command, and the trailing ] must be seen as an argument in its own right - tagging onto the "" will hide it from the shell, resulting in your unexpected end of file error.Code:if [ "$4" -ne "" ]


Reply With Quote
