Six Flashcards
locate the binary file of a command
whereis command
short description of a command
whatis command
to repeat most recent command
!!
to turn on a environmental variable
set -o variable_name
set +o variable_name will turn it off
shopt -s optionName : enable it
shopt -u optionName: disable it
what is the if expression
if condition then elif condition then else fi
grep format
grep pattern file
date
date +Format
positional parameters
$0 is the script itself $1 is the first argument $2 the second . after $9 it must be written as ${} $# is the total number of inputs
[ -z “string” ]
the length of the string is nonzero
case expression
case $var in var1) ;; var2) ;; *) ;; esac
translate string
tr [option] set1 set2
another way to avoid using tr
case $input in
[Ss][Oo])…….
Third way to turn on case-insensitiveness
shopt -s nocasematch
case $opt in
shopt -u nocasematch
for loop
for var in item1 item2
do
….
done
for loop (C heritage)
for (( EXP1; EXP2; EXP3))
do
done
command substitution
$(command)
this store the command output to a string or a variable
while loop
while condition
do
done
how to define a function in Bash
function function_name () { statement }
function in a single line
function function_name () {; ; ;} the last statement must have a semicolon.
The limitation of the function
it must be defined before the first call
A function cannot be empty
even if it has comments in it, it is empty. It shouldn’t be empty.
command: basename
basename strips directory information and suffixes from filenames
-a –multiple : support multiple arguments and treat
what does backtick mean
backtick ` runs the contents of the enclosed command and take the output as a string
Leading dollar sign before single quotes
it causes escape sequences to be interpreted.