i have some file in my directory like

  a.txt
  a.txt.md5
  b.txt
  b.txt.md5
  c.txt

and i am trying to write a shell script which will print the name of file of which Md5 is no present or Md5 is changed

like

 for filename in ".txt"
 do
   if($filename.md5 not present OR $filename.md5 is changed)
     echo $filename
   fi
 done

so how will this if condition be like?

  if($filename.md5 not present OR $filename.md5 is changed)
有帮助吗?

解决方案

Putting in a single if statement:

is_changed
if [ !-e $file -o $? == 0 ];then
   print $file
fi

It assumes that your function is_changed returns 0 if it's changed and something else otherwise.

其他提示

Test if the file exists is easy:

if [ -e $file ]; then
   #checksum again
   if [ $? == 0 ];then
       echo $file
   fi
else
    echo $file 
fi

I am just abstracting whatever you do to check checksum

perhaps I better add a pseudo code:

if file exists
   checksum
   if changed
      print filename
 else
      print filename
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top