Bash Scripting Flashcards
What do you put at the beginning of bash scripts?
!/bin/bash
Where should you place a script if you want it to be executable from anywhere?
/home/user/bin
What do you have to do to the script myscript before you can run it?
chmod u+x myscript
myvar = $1
Will assign the value of the first argument to myvar
$#
Refers to the total number of arguments
How to do a numerical comparison with an if statement in a bash script
if (( $var == 0 ))
What does an if block end with?
fi
if test -f file
Tests if $file is a file
if [ -f $file ]
Tests if $file is a file
if [ -z “$string” ]
Checks if $string is empty
if statement flag for greater than
-gt
if statement flag for less than
-lt
if statement flag for greater than or equal
-ge
if statement flag for less than or equal
-le
if statement flag for equal
-eq