I am under the impression that if I include the line
#!/bin/bash
at the start of my file, it will be recognized as a bash script that I can run just by
file.sh
instead of
sh file.sh
But in my case, file.sh
gives something like test.sh
gives test.sh: command not found
. Why is that?
UPDATE
I notice I need to use ./
. But I thought it will look in the current directory anyway?
./test.sh
\#!/bin/bash
in your file as you write? There shouldn't be a backslash in the beginning..
, but it is not recommended.sh file.sh
and./file.sh
are not equal if the first line is#!/bin/bash
! The correct way to execute bash scripts is by usingbash file.sh
. Also, using the.sh
extension is discouraged because of the confusion ("it says .sh, so I must usesh file.sh
right?")