Matt Matt - 1 year ago 73
Bash Question

Need to check if .gz files exist in a directory

I have a prompt in my shell script where the user can choose a directory. I am trying to make it so that if a .gz file exists in that directory, they exit the loop, and if not, the user is asked again to choose a directory, but it just isn't working. Here's what I have so far:

ls -d */
while :
echo "Which Directory do you want to access?"
read input_variable1
cd $input_variable1
if [ CHECK FOR .gz ]
ls -d */
echo "no .gz files to unzip. Try again."

Answer Source

Test supports using wildcards, so [ -f *.gz ] will be true if there are any files matching *.gz (and false otherwise).