Menu
Linux · 05 Topic · 2 steps

Shells and Shell Scripting

“Customizing the shell environment and writing your own Bash scripts.”

Topic 105 is the first topic of the LPIC-1 102-500 exam. It’s about the shell you spend your day in: how Bash sets itself up when it starts, and how to turn the commands you type into scripts that run on their own.

You’ll start with the startup files, variables, PATH, aliases and functions, then write real scripts with tests, loops and exit codes that can warn root when something goes wrong.

You’ll learn:

  • Which startup files Bash reads for login and non-login shells, and how Debian and Red Hat chain them
  • The difference between shell variables and environment variables, and how to set PATH safely
  • How to write aliases and functions, and give new users default files through /etc/skel
  • How to write scripts with a shebang, test, if, case, for, while, read and seq
  • How to use exit codes, &&, ||, command substitution and exec, mail root, and install scripts with the right owner and permissions

You’ll need: a Linux machine, a virtual machine or a container such as docker run -it --rm debian or docker run -it --rm ubuntu. Most examples work as a normal user. Editing /etc/skel, creating users and installing scripts into /usr/local/sbin need root or sudo (in a container you’re already root).

Start reading →
Byte card for Shells and Shell Scripting: Login shells read /etc/profile, then the first of ~/.bash_profile, ~/.bash_login, ~/.profile. Interactive shells read ~/.bashrc: the home of your aliases and functions. export puts a variable in the environment, so child processes inherit it. Exit status 0 means success: && runs on success, || on failure. A script needs a #! line, read and execute rights, and Linux ignores SUID on it.

Byte card

The whole topic on one card

  1. Login shells read /etc/profile, then the first of ~/.bash_profile, ~/.bash_login, ~/.profile.
  2. Interactive shells read ~/.bashrc: the home of your aliases and functions.
  3. export puts a variable in the environment, so child processes inherit it.
  4. Exit status 0 means success: && runs on success, || on failure.
  5. A script needs a #! line, read and execute rights, and Linux ignores SUID on it.

Save it as a cheat sheet, or share it with someone who's learning this too.

Search posts and bytes

Optional account

Keep your progress everywhere

Everything on AminBytes is free to read, with or without an account. Sign in only if you want your commits, streak and merged topics saved, on every device.

or

We keep only your name, avatar and which bytes you finished, and you can delete it all anytime. Privacy