I’m very new to bash scripting and am running into an issue when using double brackets. I can’t seem to get them to work at all in Ubuntu Server 11.10. My script below is in if_test.sh.
#!/bin/bash
if [[ "14"=="14" ]]; then
echo "FOO"
fi
When I run this simple shell script the output I get is: if_test.sh: 5: [[: not found
It seems that I’m running GNU bash version 4.2.10 after running bash –version from the terminal. Any help would be greatly appreciated. Thanks!
The problem lies in your script invocation. You’re issuing:
On Ubuntu systems,
/bin/shisdash, notbash, anddashdoes not support the double bracket keyword (or didn’t at the time of this posting, I haven’t double-checked). You can solve your problem by explicitly invokingbashinstead:Alternatively, you can make your script executable and rely on the shebang line:
Also note that, when used between double square brackets,
==is a pattern matching operator, not the equality operator. If you want to test for equality, you can either use-eq:Or double parentheses: