views:

34

answers:

2

I'm trying to loop round a load of tar files and then move the extracted files into a new folder, inspect them and delete them before moving onto the next tar.

Code is below:

for i in *
do
  tar -zxvf $i 
  mv *TTF* encoded
  cd encoded
  for j in *
  do
    echo $j
  done

  rm -f *TTF*
  cd ..
done

When it gets to the nested loop, it asks if I want to display all x possibilities. Clearly something is going wrong. Any ideas?

+2  A: 

Did you write this in a text editor, then try to paste it into a terminal, by any chance? Did you use tabs to indent the lines? If so, try changing tabs to spaces, or just save the file as a shell script and then run it.

(The tab key invokes completion, which displays the "display all x possibilities" message if there are lots of completions that match.)

Doug
A: 

Run the 'cd' command and its following actions in a sub-shell, which means you don't have to do 'cd ..'. Also, it would probably be better to extract each tar file directly in the sub-directory.

for i in *.tar.gz
do
  mkdir encoded
  (
  cd encoded
  tar -zxvf ../$i 
  for j in *
  do
    echo $j
  done
  )
  rm -fr encoded
done

This assumes only that the tar file doesn't contain any names with '..' in the paths of the files, which is very uncommon.

Jonathan Leffler
Thanks this works great.
Sea Em