We receive files that are sometimes zipped, but the file may not have the .gz or other extention that would indicated that the file is zipped. Is there a unix "test" command that I could use or something similar?
file $1 | grep -i gzip
case $? in
0)
printf "GZ archive is matched \n"
gzip -d $1 ## or whaeva you need to do here
;;
1)
printf "Not matched \n"
## code here
;;
esac
You run the script as ./script.sh <fileforchecking>
Or make it a function in shell and run loops against it.
A simpler way to accomplish that same task is to use the exit status directly in an if statement:
if file "$1" | grep -iq gzip; then
printf "GZ archive is matched \n"
gzip -d "$1" ## or whaeva you need to do here
else
printf "Not matched \n"
## code here
fi