Coding for All
Lesson 1: Your First Script
Your First Script Put two lines in a file and make the computer run them.
1#!/bin/bash
2echo "Hello from a script!"
Terminal
$ chmod +x greet.sh
$ ./greet.sh
Hello from a script!
Every line, explained
#!/bin/bash
This first line is called the shebang (from "hash bang", the # and ! it starts with). It is not a comment: it tells the computer which program should read the rest of the file. #!/bin/bash means "run this with bash". Every bash script starts with this exact line.
echo "Hello from a script!"
An ordinary echo, exactly as you would type it at the prompt. That is the big secret of shell scripts: they are just commands, saved in a file, run one after another from top to bottom.