ShBash · Lesson 1 of 8
Your First Script
A Bash script is just a text file with commands in it. The magic is in the shebang line at the top, which tells the system which interpreter to use.
The shebang (#!) on line 1 tells the OS what program to use to run the file. #!/bin/bash means "run this with Bash." Make the file executable with chmod +x, then run it with ./filename.sh.
◆ Note
Use #!/usr/bin/env bash instead of #!/bin/bash for better portability — it finds Bash wherever it is in PATH, rather than assuming it's at /bin/bash.
Use #!/usr/bin/env bash instead of #!/bin/bash for better portability — it finds Bash wherever it is in PATH, rather than assuming it's at /bin/bash.