bash open.sh works, but you must remember that it is a bash script. Two things let you run it like any other program:
The shebang
The first line of a script can name the program that must read it. It starts with #!, and its name is the shebang:
#!/bin/bash
echo "the shop is open"When you run the file by its path, the kernel reads this line and starts /bin/bash to run the file. A program that reads and runs a script is an interpreter. Bash is one. Python is another: a Python script starts with #!/usr/bin/python3.
The x permission
To run a file by its path, your set must have x:
learner@tidepool:~$ ./open.sh
bash: ./open.sh: Permission denied
learner@tidepool:~$ chmod u+x open.sh
learner@tidepool:~$ ./open.sh
the shop is openWhy ./
The current directory is not in PATH. So open.sh alone gives command not found. ./open.sh is a path: "the file open.sh in the current directory". The shell runs it with no search.
| Line | Needs x | Needs the shebang |
|---|---|---|
bash open.sh | No | No |
./open.sh | Yes | Yes |