How to write a shell script to untar files?

I'd like to write a shell script that untars files within a directory.

I tried the code below, but get an "unexpected token" error.
#!/bin/bash
file=ls ./*.tar.gz
do tar -xvzf $file
done

Open in new window

n00b0101Asked:
Who is Participating?
 
omarfaridConnect With a Mentor Commented:
try

#!/bin/bash
for file in *.tar.gz
do
     tar -xvzf $file
done
0
 
n00b0101Author Commented:
thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.