![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error when running make | shashidhara_01 | High Level Programming | 1 | 02-02-2007 06:35 PM |
| Error while running rsh commands !!! | csaha | Shell Programming and Scripting | 3 | 11-08-2006 01:47 AM |
| Error in running on AIX 5.2 | SMISS | AIX | 0 | 06-24-2004 11:06 AM |
| Error while running a script | HarryTellegen | UNIX for Dummies Questions & Answers | 5 | 02-05-2002 02:58 AM |
| Running scripts with condition | Hamid Afsharazad | UNIX for Dummies Questions & Answers | 3 | 01-16-2001 10:57 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
When running if condition, getting the following error
Hi All,
My input file name is 1.sh the contents of file are cat status2.txt | while read filename do echo "$filename" echo "first content of the file is ${filename[0]}" echo "second content of the file is ${filename[0]}" echo "second content of the file is ${filename[0]}" if [ ${filename[0]} -eq 0 -a ${filename[1]} -eq 0 -a ${filename[2]} -eq 0 ] then echo "please execute the step 1, then step 2 and then step3" elif [ ${filename[0]} -eq 0 ] then echo "please execute the step 2 and then step3" elif [ ${filename[0]} -eq 0 -a ${filename[1]} -eq 0 -a ${filename[2]} -ne 0 ] then echo "please execute the last step3" fi done Where status2.txt contains the following contents 0 --> first content is 0 0 --> Second content is 0 --> Third content is the space Now running the 1.sh file i am getting the following output. 0 first content of the file is 0 second content of the file is 0 second content of the file is 0 ./1.sh: [: too many arguments -------> Error please execute the step 2 and then step3 0 first content of the file is 0 second content of the file is 0 second content of the file is 0 ./1.sh: [: too many arguments -------> Error please execute the step 2 and then step3 first content of the file is second content of the file is second content of the file is ./1.sh: [: too many arguments -------> Error ./1.sh: [: -eq: unary operator expected -------> Error ./1.sh: [: too many arguments -------> Error dmadmin SYDUEND01 /tmp/A380_RFS24 can anybody tell me that why i am getting the above error?? It is very urgent, Please response me ASAP. Thanks |
|
||||
|
Presumably ${filename[0]} gets expanded into an empty string, and test isn't able to parse that. Remember that unquoted empty strings will simply disappear. Either quote the strings, or append a character before them (or, to be on the safe side, do both -- that's why you frequently see something like if [ X"$string" = X ])
Code:
vnix$ echo $nosuchvariable vnix$ [ $nosuchvariable -eq 0 -a $nosuchvariable -eq 0 -a $nosuchvariable -eq 0 ] bash: [: too many arguments vnix$ [ "$nosuchvariable" -eq 0 -a "$nosuchvariable" -eq 0 -a "$nosuchvariable" -eq 0 ] bash: [: : integer expression expected Maybe you really mean something like this. Code:
exec <status.txt read file1 read file2 read file3 echo "first content of the file is $file1" echo "second content of the file is $file2" echo "third content of the file is $file3" # or do you really mean to print "second" twice? if [ "$file1" -eq 0 -a "$file2" -eq 0 -a "$file3" -eq 0 ] then echo "please execute the step 1, then step 2 and then step3" elif [ "$file1" -eq 0 ] then echo "please execute the step 2 and then step3" elif [ "$file1" -eq 0 -a "$file2" -eq 0 -a "$file3" -ne 0 ] then echo "please execute the last step3" fi |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|