Just an illustration: first cd /usr/liband run for x in $(ls);do if [ $x == *.a ];then echo $x;fi;doneWhat I want to do is to select files with extension .a and print them. I know there are much simpler way of doing this, but that is not my intention here. The problem is that the command above doesn't work. I don't know why. I learn this from this postI also tried [ $x == *.a ]    bash: [: too many arguments[ $x = *.a ]    shows nothing[ $x = *.a ]    bash: [: too many argumentsI know [[ $x == *.a ]] works, but I want to know what is the correct way to write [ test in this case?
How to correctly test file's extension in if statement?
test
for x in ./*; do   case $x in      *.a ) echo $x;;   esacdoneThe [ construct  is not exactly suited for this. But if you insist, we may do it like as follows: [ '.a'  =  .${x##*.} ]ExplanationSay $x contains: my.file.testing.a Then ${x##*.} will , starting from the left, strip away as much as it can till the last . it manages to see in $x. IOW, we end up dropping everything and bringing the extension viz, a to the fore. So now we have the extension we just computed to compare against what we think it better be(.a) for success.