Reputation: 45
I am trying to write an if statement where it will go to the next iteration of the for loop if i
is the variable or if i
is a directory. I am struggling with the directory part which would go after the -o
for i in *
if [ "$i" = VARIABLE -o ]
then
continue
fi
Upvotes: 0
Views: 188
Reputation: 30831
You can use test -d
:
if [ "$i" = VARIABLE ] || ! [ -d "$i" ]
then continue
fi
Or more succinctly:
[ "$i" != VARIABLE ] && [ -d "$i" ] || continue
Or as separate tests:
[ "$i" != VARIABLE ] || continue
[ -d "$i" ] || continue
Upvotes: 0
Reputation: 212248
I don't fully understand the question, but a common idiom is:
for i in *; do
if test -d "$i"; then continue; fi
...
done
If you also want to compare against a particular value, you really shouldn't use -o
. It's been deprecated for a long time. Instead, use:
if test -d "$i" || test "$i" = VARIABLE; then ...
Upvotes: 1