In one of my shell script, I'm seeing
if [[ ! -d directory1 || ! -L directory ]] ; then
What does -d
and -L
option mean here? Where can I find information about the options to use in an if
condition?
$? is the exit status of the most recently-executed command; by convention, 0 means success and anything else indicates failure. That line is testing whether the grep command succeeded. The grep manpage states: The exit status is 0 if selected lines are found, and 1 if not found.
The [[ ... ]] part allows to test a condition using operators. Think of it as an if statement.
The if condition is fulfilled if grep returns with exit code 0 (which means a match). The ! exclamation mark will negate this.
You can do help test
which will show most of the options accepted by the [[
command.
You can also do help [
which will show additional information. You can do help [[
to get information on that type of conditional.
Also see man bash
in the "CONDITIONAL EXPRESSIONS" section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With