The above if
statements could also be written as:
cd mytmp && rm *
The double &, will only go onto the second statement if the first one was able to succeed. More if later.
Assuming you run a command like:
aa && bb && cc
bb will only run if aa executed successfully (remember the status code)
cc will ony run if both aa and bb executed successfully.
Note that:
a & b & c
Is totally different and will cause a and b to run in the background.
Similar to double &, but this one, the rhs runs if the lhs fails
cmd || printf "%b" "cmd failed. You're on your own\n"
These are different:
cmd || printf "%b" "FAILED.\n" ; exit 1 #always exits
cmd || { printf "%b" "FAILED.\n" ; exit 1 ; } #exits on failure
Can save a program as a variable
f=myfile.txt
p=cat
$p $f
More on variables later.