I'm trying to do a simple script that unzips a zip file which has an exclamation mark in its name:#!/bin/bashUNZIP='/usr/bin/unzip'CUT=/usr/bin/cutGREP=/usr/bin/grepFILENAME=testFILE=/usr/local/var/www/htdocs/$FILENAME\!3.zipUNZIPPEDFOLDER=$($UNZIP ${FILE} | $GREP -m1 'creating:' | $CUT -d' ' -f5-)echo $UNZIPPEDFOLDERbut when script is being executed, unzip returns:unzip:  cannot find or open /usr/local/var/www/htdocs/test\!3.zip, /usr/local/var/www/htdocs/test\!3.zip.zip or /usr/local/var/www/htdocs/test\!3.zip.ZIP.It works fine when there is no ! sign in filename, but to make some of my work automated, I need to stay with original file names.
Unzipping file with exclamation mark from command line in bash script
bash;shell script;osx
In general you don't have to escape and quote anything. The secure way to write this would be:FILE=/usr/local/var/www/htdocs/${FILENAME}!3.zipUNZIPPEDFOLDER=$($UNZIP $FILE | $GREP -m1 'creating:' | $CUT -d' ' -f5-)echo $UNZIPPEDFOLDER