Reputation: 19967
I'm trying to loop through all HTML
files in a directory.
The following works just fine for that.
for f in *.html; do echo $f; done
But, how can I add an if
condition so that the file name is only echoed if it is not equal to index.html
?
Upvotes: 2
Views: 2250
Reputation: 7499
It's also possible to exclude index.html
from the list entirely with extended globbing:
shopt -s extglob nullglob
for f in !(index).html; do
echo "$f"
done
shopt -s extglob
: enables extended globbingshopt -s nullglob
: makes sure the loop is not executed should there be no matching files!(index).html
: expands to all html
files that are not index.html
Upvotes: 1
Reputation: 39
for f in *.html; do [ "$f" != "index.html" ] && echo "$f"; done
Upvotes: 1
Reputation: 37023
It should be simple like:
for f in *.html
do
if [ "$f" != "index.html" ]
then
echo $f
fi
done
Upvotes: 2