Save the Output in a Shell Script Variable

I was counting how many times a file was referenced by other files. I then wanted to do some processing based on this number.

To do this I saved the output of this count in a variable which I was then able to reference later in the shell script.

num_files=`find . -type f -name '*.html' | xargs grep $img_file | wc -l`

# delete this file if it is not referenced
if [ "0" = $num_files ]
then
  rm $IMAGE_DIR/$img_file
fi

Leave a Reply

Your email address will not be published. Required fields are marked *