Bash Tutorials

Articles about bash (.sh) scripting in Linux; learn how to use bash scripting to automate repetitive actions and save time.

  1. How to read user input from shell scripts using the read command.
  2. How to use the tilde character in bash scripts, having it point to the users home directory as expected.
  3. Article trying to explain why you may not want to use bash for larger scripting work.
  4. How to make a simple bash script that watches files for changes.
  5. How to generate, and compare hashes from terminal using bash and PHP scripts in Linux.

About Bash

Bash (an abbreviation of Bourne-Again Shell) is a shell used in various UNIX and GNU/Linux systems, but is also commonly used when referring to shell scripting.

The tutorials in this category are primarily focused on shell scripting.

Shell scripts may or may not have the .sh extension. It can sometimes be a good idea to include a (.sh) file extension, as this might help users identify the type of script more easily.

A script may include the following shebang as the first line in the file:

#!/usr/bin/env bash

A shebang tells which interpreter the system should use to run the script.

For consistency, and unless you specifically need to use something other than bash, it is recommended to use #!/usr/bin/env bash when writing scripts. The #!/usr/bin/env part makes the script more portable for systems where bash is not located in /usr/bin/bash; the location of env should always be the same.