Unix - Nested Loop. One loop to untar then another to inspect each file in directory
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 *开发者_StackOverflow
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?
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.)
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.
echo "Enter no of terms" read count for i in $(seq 1 $count) do t=expr $i - 1
for j in $(seq $t -1 0) do echo -n " " done j=expr $count + 1
x=expr $j - $i
for k in $(seq 1 $x) do echo -n "* " done echo ""
精彩评论