BASH [ expr ] -a -o

| | Comments (0)

expr1 -a expr2
True if both expr1 and expr2 are true.
expr1 -o expr2
True if either expr1 or expr2 is true.

-a (AND) operation first, then -o (OR) operation

e.g.
there're 3 files, a, c, d
#!/bin/sh
[ -f a -o -f b -o -f c -o -f d ] && echo 0
[ -f a -o -f b -o -f c -a -f d ] && echo 1
[ -f a -o -f b -a -f c -o -f d ] && echo 2
[ -f a -o -f b -a -f c -a -f d ] && echo 3
[ -f a -a -f b -o -f c -o -f d ] && echo 4
[ -f a -a -f b -o -f c -a -f d ] && echo 5
[ -f a -a -f b -a -f c -o -f d ] && echo 6
[ -f a -a -f b -a -f c -a -f d ] && echo 7
result is...

0
1
2
3
4
5
6

Leave a comment

March 2009

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

About this Entry

This page contains a single entry by Pank published on December 30, 2004 11:41 PM.

Everything2 Dictionary was the previous entry in this blog.

Netcraft Toolbar is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.