Your First Script
Commands in a file.
A shell script is just a text file, full of commands. Instead of typing them one by one, you save them once, and run the whole file whenever you like. It's how Linux users automate everything.

- A text file of commands
- Save once, run any time
- Automate everything
hello.sh in nano
Here's our first script, open in nano. The first line, hash bang, bin bash, says which program should run this file. Lines starting with a hash are comments, notes for humans. Then come normal commands, exactly as you'd type them.
#!/bin/bash
# My first script
echo "Hello, $USER!"
echo "Today is $(date +%A)."
echo "You are in $PWD"Running it
Bash, then the file name, runs the script. To run it on its own, like a real command, give it execute permission with CH mod plus X, and start it with dot slash. Every command in the file runs, from top to bottom.
bash hello.sh Hello, sam! Today is Monday. You are in /home/sam chmod +x hello.sh ./hello.sh Hello, sam! Today is Monday. You are in /home/sam
The shebang line
That first line is called the shebang, from hash and bang. Without it, Linux has to guess which shell should run the file. Always put it first, with nothing before it. And end your script names with dot SH, so people know what they are.
| key | value |
|---|---|
| #!/bin/bash | run me with bash |
| # comment | ignored by bash |
| chmod +x | make it runnable |
| ./hello.sh | run it |
Summary
A script is a file of commands, starting with the shebang. CH mod plus X makes it runnable, and dot slash runs it. Next, giving scripts information, with arguments.
Key takeaways- #!/bin/bash
- chmod +x script.sh
- ./script.sh