0

I've been trying to write a script that will search a directory for multiple tar files that are zipped, unzip them, then untar them. However my problem is that everytime I run the script it will execute the first if then statement, but it won't execute the second one. I've ran them both statements in separate scripts and they both work independently, however not when ran in the same script. Do I need to combine them in a if then elseif statement? Here's what I have so far, I appreciate any help.

#!/bin/csh
set x = (`find /Documents/*.gz -print`)
set v = (`find /Documents/*.tar -print`)

if ("$x" != "") 
then 
gunzip *
else
echo "No zip files found."
endif

if ("$v" != "")  then
foreach i ( $v )
tar -xvf $i
end
else
echo "No tar files found."
endif

1 Answers1

0

You can do the same with just find; you don't really need a loop:

find /Documents/*.gz -exec gunzip {} \;
find /Documents/*.tar -exec tar xvf {} \;

-exec will run a command on every file it found, the {} is replaced by the filename, and \; terminates the command.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146