Вопрос

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