Reusuable sets of bash terminal commands can be created using bash scripts. Bash scripts can run any command that can be run in a terminal.
Bash script files start with
#!/bin/bash. This special line tells the computer to use bash as the intepreter.
Bash script variables
Variables in a bash script can be set using the
= sign, and accessed using
Bash script comparison operators
In bash scripting, strings are compared using the
== (Equal) and
!= (Not equal) operators.
read command can be used to prompt the user for input. It will continue to read user input until the Enter key is pressed.
Some prompt text can also be specified using
-p with the
Bash Script Arguments
Arguments can be added to a bash script after the the script’s name. Once provided they can be accessed by using
$(position in the argument list). For example, the first argument can be accessed with
$1, the second with
$2, the third with
Aliases can be created using the keyword
alias. They are used to create shorter commands for calling bash scripts. They can also be used to call bash scripts with certain arguments.