Nikita
Nikita

Reputation: 53

what does flags -o and -L means in bash

I have such part of bash script

if [ ! -e $f -o -L $f ] ; then

where $f is filename

I know that -e means "exist" but I cannot find what -o and -L means

Upvotes: 5

Views: 5352

Answers (3)

l0b0
l0b0

Reputation: 58908

Translated to programmer English, it's "if the file ($f) does not exist (-e) or (-o) the file ($f) is a symbolic link (-L), then ..."

man bash has more details.

Upvotes: 5

Paŭlo Ebermann
Paŭlo Ebermann

Reputation: 74790

Hmm, this is interesting. We have first the definition of the [ builtin:

`EXPR1 -o EXPR2'
      True if either EXPR1 or EXPR2 is true.

... and then we have the definition of Conditional expression which are used for this builtin:

`-o OPTNAME'
     True if the shell option OPTNAME is enabled.  The list of options
     appears in the description of the `-o' option to the `set' builtin
     (*note The Set Builtin::).

Obviously here the intended meaning is the first one (if the file does not exist or is a link), but I'm not sure why this works.

Upvotes: 1

Ed Manet
Ed Manet

Reputation: 3178

-o : True if shell option "OPTIONNAME" is enabled.

-L : True if FILE exists and is a symbolic link.

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

Upvotes: 1

Related Questions