Shell script throws a not found error when run from a sh file. But if entered manually the commands work
Run the script either as:
bash script.sh
or just:
./script.sh
When bash
is run using the name sh
, it disables most of its extensions, such as the [[
testing operator.
Since you have the #!/bin/bash
shebang line, you don't need to specify the shell interpreter explicitly on the command line. Running the script as a command will use that line to find the shell.