betweenGo

Save the Output in a Shell Script Variable

by Frank Kim on Dec.14, 2007, under Bash

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


  • Share/Bookmark

Related posts:

  1. Save the Output in a Shell Script Array
  2. Shell Tricks
  3. Maven Assembly Convert Shell Scripts to use UNIX LF’s
  4. Shell Scripts with Windows LF’s Fail in Latest Cygwin
  5. Unable to start Cygwin shell from Windows command prompt


Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!