Every morning, someone at the shop types the same two commands. Put them in a file, and one command runs both. A file of commands is a script: bash runs its lines from top to bottom, as if you typed them.
learner@reef:~$ cat stock.sh
# What the shop has left. ← a comment: bash skips a line that starts with #
grep milk ~/shop/stock.txt
grep flour ~/shop/stock.txt
learner@reef:~$ bash stock.sh ← you type this
milk 4 ← grep milk
flour 12 ← grep flour1. Write it. Run nano ~/morning.sh. Type these two lines, then click Save:
| Line | What it shows |
|---|---|
cat ~/shop/shifts.txt | Who works which day |
grep -c ERROR ~/logs/register.log | How many errors the cash register logged |
Saving doesn't run anything: a script runs only when you ask.
2. Run it. For now, run scripts with bash: type bash and the file's name, bash ~/morning.sh, and press Enter.
3. Say what it's for. Add a comment as the first line, then save again.
Objectives
- Write
~/morning.shwith the two commands. - Run it with
bash. - Add a comment as line 1 that says what the script is for.