Bash and Scripting
Basics
Use the following to define the interpreter to be used by the shell script (bash in our case):
Arguments variables that are passed to the script. These are also called parameters $0 - the name of the script $1 - first parameter from the script $2 - second parameter from the script and so on
Example Script
See the example script below - script checks the IP with a ping
command:
If Statements*
See the list of available conditions below: ![expression] - the expression is false -n [string] - the length of the string is greater than zero -z [string] - the length of the string is zero string1 = string2 - string is equal to sting2 string1 != string2 - string is not equal to sting2 integer1 -eq integer2 - integer1 is equal integer2 integer1 -gt integer2 - integer1 is greater than integer2 integer1 -lt integer2 - integer1 is less than integer2 -d [file] - the file exists and is a directory -e [file] - the file exists -r [file] - the file exists, and the read permission is granted -s [file] - the file exists, and its size is greater than zero -w [file] - the file exists, and the write permission is granted -x [file] - the file exists, and the execute permission is granted * This section was copied from the Linux Academy course: LPI Linux Essentials Certification created by Michael Christian -- you can find it here.
For Loops
While Loops
Case Statements
Last updated
Was this helpful?