문제

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