I have this script
#!/bin/sh
if [ $# -ne 3 ] ; then
echo "param 1, param2, and A or B "
exit 1;
elif [ $# -eq 3 ]; then
if [$3 = "A"] ; then
echo "A"
elif [$3 = "B"]; then
echo "B"
fi
fi
It is basically checking if param 3 is A or B, and do echo. But it returns:
./test.sh: line 6: [A: command not found
./test.sh: line 8: [A: command not found
I tried to use -eq
for comparison, but it still does not work. How can I fix this problem?
When you're trying to run a command (with or without sudo ) and get an error message that reads "Command not found," this means the script or file you're trying to execute doesn't exist in the location specified by your PATH variable.
If the specified package or command is not installed on your system, then you will get the output shown in the image below. Through this output, you can verify that the said package or command is not installed on your system, and because of this, you might be receiving the Bash Command Not Found error.
bash is sh, but with more features and better syntax. Bash is “Bourne Again SHell”, and is an improvement of the sh (original Bourne shell). Shell scripting is scripting in any shell, whereas Bash scripting is scripting specifically for Bash. sh is a shell command-line interpreter of Unix/Unix-like operating systems.
You can check the equality and inequality of two strings in bash by using if statement. “==” is used to check equality and “!= ” is used to check inequality of the strings. You can partially compare the values of two strings also in bash.
I'm sure this has come up before, but -- [
is actually a command. You need a space after the [
in order for the shell to find it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With