Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the options in if conditions of shell [duplicate]

Tags:

bash

shell

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?

like image 830
John Avatar asked Jun 13 '12 04:06

John


People also ask

What is $? == 0 in shell script?

$? 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.

What is if [[ ]] in Linux?

The [[ ... ]] part allows to test a condition using operators. Think of it as an if statement.

Can we use grep in if condition in shell script?

The if condition is fulfilled if grep returns with exit code 0 (which means a match). The ! exclamation mark will negate this.


1 Answers

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.

like image 96
Dennis Williamson Avatar answered Sep 29 '22 21:09

Dennis Williamson