For your 1st question why only [[ ]]
don't work when I read man page for BASH
I see following:
[[…]] [[ expression ]] Return a status of 0 or 1 depending on the
evaluation of the conditional expression expression. Expressions are
composed of the primaries described below in Bash Conditional
Expressions. Word splitting and filename expansion are not performed
on the words between the [[ and ]]; tilde expansion, parameter and
variable expansion, arithmetic expansion, command substitution,
process substitution, and quote removal are performed. Conditional
operators such as ‘-f’ must be unquoted to be recognized as primaries.
Which means it shouldn't be empty.
For your second question difference between [
and [[
is [[
is enhancement of [
here is very useful SO link I found you could go through it too.
What's the difference between [ and [[ in Bash?
EDIT: For checking last command's status a simple check I created is which you could take it as a start too:
if [[ $? -eq 0 ]]
then
echo "Last command ran successfully."
else
echo "Last command status is NOT 0 so could be it did not run properly."
fi
EDIT2: Adding example for ((
too as per OP's question in comments.
Example of use of ((
.
cat script.ksh
echo "Please enter a value:"
read value
if ! ((value % 4)); then
echo "$value is fully divided from 4."
fi
((
from man BASH
:
((expression))
The expression is evaluated according to the rules described below under ARITHMETIC EVALUATION. If the value of the
expression is non-
zero, the return status is 0; otherwise the return status is 1. This is exactly equivalent to let "expression".