105.2 Let’s Learn Linux: Customize or write simple scripts — Lesson 1

Livestream date: 2026-05-31

Weight 4

Key knowledge areas

  • Use standard sh syntax (loops, tests).
  • Use command substitution.
  • Test return values for success or failure or other information provided by a command.
  • Execute chained commands.
  • Perform conditional mailing to the superuser.
  • Correctly select the script interpreter through the shebang (#!) line.
  • Manage the location, ownership, execution and suid-rights of scripts.

Homework 1

After trying to run a newly created Bash script, a user receives the following error message:

bash: ./script.sh: Permission denied

Considering that the file ./script.sh was created by the same user, what would be the
probable cause of this error?

Homework 2

Suppose a script file named do.sh is executable and the symbolic link named undo.sh points
to it. From within the script, how could you identify if the calling filename was do.sh or
undo.sh?

Homework 3

In a system with a properly configured email service, the command mail -s “Maintenance
Error” root <<<“Scheduled task error” sends the notice email message to the root user.
Such a command could be used in unattended tasks, like cronjobs, to inform the system
administrator about an unexpected issue. Write an if construct that will execute the
aforementioned mail command if the exit status of the previous command — whatever it
was — is unsuccessful.

  1. probebly that the script file do not have execute permission would probebly work with chmod +x script.sh
  2. dont know maby, ln -v do.sh
  3. if [ $? -gt 0]; then printf(mail -s “Maintenance
    Error” root <<<“Scheduled task error”)
    fi
  1. You probably misunderstood the question. do.sh already exists, undo.sh is a symlink to it. The question is, how can one determine which file was used for calling the script from inside that script.
  2. Where did printf come from?

oh must have mixed languages together ment echo XD

Alright, in this case — where did echo come from? :winking_face_with_tongue:

echo doesn’t execute commands, it only prints text.

oh i see i shuld just let the line start with mail command and all of it would execute?

Of course! That is how scripts work: they are just lines which are executed one by one.

1 Like