Linux Labs

Bash: text processing and scripts / Stage 4 of 9

A script is a file of commands

Not running Starting usually ~20 s
Leave the lesson

Step 1 of 6 · on a machine · 4 min

A script from a colleague

What you will learn

  • Run a script through an interpreter and as a program, knowing who reads the file.
  • Turn your own script into a command that is found by name from any directory.
  • Keep a path in a variable and expand it in quotes so that a space does not split the path.

A colleague is going on holiday and leaves you a script, backup-notes.sh, which packs the team's notes into an archive. "Just run it," the message says. The script is in ~/script-lab, and there are three ways to run it.

Exercise · look

Run your colleague's script

You are in ~/script-lab. Run backup-notes.sh with the three commands on the card, one after another.

First, predict

backup-notes.sh is yours and sits in the current directory. What will the shell answer to ./backup-notes.sh?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

Why was ./backup-notes.sh refused, even though the file is yours and you can read it?

  • You are already in ~/script-lab — pwd shows it. And the file was found: otherwise the answer would be No such file or directory.

  • student runs programs in a home directory just fine. The problem is the file's own permissions: ls -l backup-notes.sh shows -rw-r--r--, with no x.

  • sh found the error on line 5 once it started reading the file. ./ was refused earlier, before any line was read.

A file can be run as a program only with the x permission, and backup-notes.sh does not have it.

Ubuntu 24.04
Loading…