0

I tried using this code to delete all files containing specific expressions.

  # ! /bin/ bash 
for i in `ls `;   do 
if  [ ! -d  $i  ] && ([$i = violence] || [$i = hatred] || [$i = war]);  then 
 rm $i 
 fi 
done

I am getting the following error (There are two files in this directory, "war" and "hatred"):

    [hatred: command not found
[hatred: command not found
[hatred: command not found
[war: command not found
[war: command not found
[war: command not found

Could you point me to the problem ?

Ben J
  • 147
  • 2
  • 14
  • See http://shellcheck.net for some other problems with your code. – chepner Dec 08 '18 at 18:17
  • Syntax errors aside, you're only going to delete the three files whose names are *exactly* `violence`, `hatred`, or `war`, which you could do with `rm -f violence hatred war`. – chepner Dec 08 '18 at 18:19
  • This shellcheck tool is great, thank you – Ben J Dec 08 '18 at 19:46

0 Answers0