devs
1
How to compare the file name for "zip" or "ZIP" extension.
I can put one more || condition to check the upper case in the below:
if [[ "`echo ${fileName} | cut -d'.' -f2`" = "zip" ]]; then
Is there any better way to compare using regular expressions.
Thx in advance.
Ygor
2
Try..
case $fileName in
*.ZIP|*.zip) echo true ;;
*) echo false ;;
esac
You can get the suffix from a filename without using an external (i.e., slow) command:
suffix=${filename##*.}
... but it's not necessary to do that.
Use pattern matching (not regular expressions) in a case statement:
case $filename in
*.[zZ][iI][pP]) true ;;
*) false ;;
esac
the below command will chop the extension of a given file and convert it into lowercase.You can put this in a test statement to compare the ext.
echo "${filename##*.}" | tr 'A-Z' 'a-z'