Results 1 to 5 of 5
Hello,
We are in the process of converting from HP Unix to Linux (bash), and one of our shell scripts is giving an error on the first line of the ...
- 10-27-2011 #1Just Joined!
- Join Date
- Oct 2011
- Location
- Pittsburgh, PA, USA
- Posts
- 2
Batch scripting error after Linux conversion
Hello,
We are in the process of converting from HP Unix to Linux (bash), and one of our shell scripts is giving an error on the first line of the code below.
Where FILENAM is the first script parameter.Code:if [ ! -f ${FILENAM}* ] then error_out "${FILENAM} is not found" 1 $LINENO fi
Here is the error we're getting:
Do you know how the if-clause needs to be rewritten to avoid the error? I tried searching online, but have not found a satisfactory solution.line 42: [: too many arguments
Thank you,
Art
- 10-28-2011 #2CheersCode:
if [ ! -f ${FILENAM}* ]; then error_out "${FILENAM} is not found" 1 $LINENO fi
- 10-28-2011 #3
It looks to me like Kloscussel's solution simply adds a semicolon to the end of your if statement. I do not believe that is the problem.
The problem is that you are using a glob in the if. Let us imagine that $FILENAM contains the value "foo". If you are running this script in a directory that contains files "foo", "foobar", and "foobaz", then this line:
gets expanded by Bash into:Code:if [ ! -f ${FILENAM}* ]
And this is invalid Bash code, because "-f" can only check a single file.Code:if [ ! -f foo foobar foobaz ]
I don't know what you're trying to do here, but if $FILENAM contains the exact file and should not be globbed, you can just do this:
Code:if [ ! -f "$FILENAM" ]
DISTRO=Arch
Registered Linux User #388732
- 10-28-2011 #4
Oh. Looks like I did not read the first message long enough to see the error, sorry.

If it would have to be really a <file>*, then something like this should work around the symptom:
CheersCode:for i in ${FILENAM}*; do if [ ! -f "$i" ]; then error_out "$i is not found" 1 $LINENO fi done;
- 10-28-2011 #5Just Joined!
- Join Date
- Oct 2011
- Location
- Pittsburgh, PA, USA
- Posts
- 2
That worked! Thanks a lot!


Reply With Quote