I have the bash script below:
#!/bin/bash
#
[ $# -eq 1 -a $1 = "--help" -o $# -eq 0 ] && {
echo Help will come here
}
When I run it:
$ ./script
./script: line 3: [: too many arguments
$ ./script --help
Help will come here
As you can see, when I don't pass parameters ( $# -eq 0 ) it fails with "too many arguments". So, I tested it directly in terminal:
$ a=1;b=2;c=3
$ [ $a -eq 1 -a $b -eq 2 -o $c -eq 3 ] && echo ok
ok
$ [ $a -eq 0 -a $b -eq 2 -o $c -eq 3 ] && echo ok
ok
$ [ $a -eq 0 -a $b -eq 0 -o $c -eq 3 ] && echo ok
ok
$ [ $a -eq 0 -a $b -eq 0 -o $c -eq 0 ] && echo ok
$ [ $a -eq 0 -a $b -eq 2 -o $c -eq 0 ] && echo ok
$ [ $a -eq 1 -a $b -eq 2 -o $c -eq 0 ] && echo ok
ok
So, if it works perfectly in terminal why doesn't it work passing parameters?
Thanks,