[plug] bash script program help

Russell Steicke r.steicke at bom.gov.au
Wed Jan 11 08:56:08 WST 2006


On Wed, Jan 11, 2006 at 08:29:10AM +0800, Jon  Miller wrote:
> I could use some help in creating a program for a task that I need
> to do.  I would like to know if there is a function in bash
> scripting or that can be used in a bash script that can determine
> the size of a file.

I don't think this is built in to bash, but:

  function filesize() {
    echo $(ls -l $1 | awk '{print $5}')
  }



> What I need to do is to compare the file size
> of "A" against file "B", not sure if this possible in bash
> scripting.

  size_A=`filesize A`
  size_B=`filesize B`
  if [ $size_A -gt $size_B ] ; then
    echo A is bigger
  elif [ $size_B -gt $size_A ] ; then
    echo B is bigger
  else
    echo same
  fi


> Also in the script cat A >> B doesn't seem to work.

Why do you say that?  Are there any error messages?

> Need to read in the listing of a text file to get names from it,
> when finish with the various functions read the next name on the
> list and repeat the functions.

If the files are alone on lines by themselves:

  cat files | while read FILE ; do
    # do stuff with $FILE
  done

or
  while read FILE ; do
    stuff
  done < files


else:

  awk '{program to extract file names}' | while read FILE ; do
    stuff
  done


-- 
Russell Steicke

-- Fortune says:
Decaffeinated coffee?  Just Say No.



More information about the plug mailing list