.sh files requires `sh app.sh` even with `#!/bin/bash` line
First you need to make sure the file is executable:
chmod +x file.sh
And then to run it, you either need to put it in your PATH, i.e., one of the directories of files the OS searches when looking for files to run, which you can find with echo $PATH
, or else you need to type in:
./file.sh
Rather than just type file.sh
.
You can just type file.sh
, if it's in your PATH, which I recommend. A good place is in ~/bin
. Create that folder if it's not there, and under Ubuntu, it'll get added to your path when you log in.
You need to start it with ./file.sh, because the current dir is not in the PATH.
If this isn't sufficient, becaused you missed, what frabjous suggests, to chmod a+x
, you should start programs beginning with a shebang #!/bin/bash
with
bash file.sh
not
sh file.sh
even if sh is a symbolic link to /bin/bash.
The shell checks how it was invoked, and can be invoked as sh
to act in a compatible mode, therefore it can fail to handle some bashisms, which would work if invoked as bash file.sh
.
That was not your problem, but might become one, if you don't know these subtle distinction.