[plug] bash script program help

Mr E_T troll at arach.net.au
Wed Jan 11 09:10:09 WST 2006


On Wednesday 11 January 2006 08:29, 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.
> What I need to do is to compare the file size of "A" against file "B", not sure if this possible in bash scripting.
> Also in the script cat A >> B doesn't seem to work.
> 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.
> 
> 
> Thanks
> 

make sure the files are readable - try
chmod +w B

#!/bin/sh

declare -a FILES
FILES_CNT=0

for x in `ls *`
  do
    FILES[$FILES_CNY]="$x"
    let FILES_CNT+=1
  done

function file_size ()
{
  F1=`ls -s --block-size=1 $1`
  echo "${F1%%' '*}"
}

for (( x=0 ; x<${FILES_CNT} ; x++ ))
  do
    for (( y=${x}+1 ; y<${FILES_CNT} ; y++ ))
      do
        if test `file_size ${FILES[$x]}` -eq `file_size ${FILES[$y]}`
          then
            echo ${FILES[$x]} same size as ${FILES[$y]}
            if diff-q ${FILES[$x]} ${FILES[$y]}
              then
                echo ${FILES[$x]} same as ${FILES[$y]}
              fi
          fi
      done
  done
do help test for more details

-- 
regs MR E_T
_______________________
\                      \
  \   OOHH I hate TYPOS  \
    \                      \
      ~~~~~~~~~~~~~~~~~~~~~~~
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plug.org.au/pipermail/plug/attachments/20060111/7dcd7643/attachment.html>


More information about the plug mailing list