as @chepner says in his comment, you are comparing $ i with a fixed string.
To expand and fix the situation, you must use [[]] with the regex = ~ operator
eg:
for i in $(ls);do if [[ $i =~ .*\.java$ ]];then echo "I want to do something with the file $i" fi done
the regular expression to the right of = ~ is checked for the value of the left operator and should not be quoted (no error will be quoted, but will be compared with a fixed line and, most likely, a failure "
but @chepner's answer above using glob is a much more efficient mechanism.
peteches Jan 24 '13 at 16:42 2013-01-24 16:42
source share