0

Hi i need to delete all the log4j jars which is under webapps folder inside .war files recursively. Say webapps/ has 10 .war files and it has .jar files i need to delete .jar from .war with a single command. I know how to delete jar inside war but I don't want to run 10 times to delete jar file.

> zip -d <SOME_FILE>.war <log4j>.jar

this deletes 1 log4j jar from .war need to perform on 10 war files.

1 Answers1

0

Use a for loop. e.g. something like this:

for f in webapps/*.war; do
  zip -d "$f" log4j.jar
done
cas
  • 1
  • 7
  • 119
  • 185
  • ok thanks, so I used $f without quotes does it matter? – user2835563 Dec 29 '21 at 03:17
  • yes, it does. if \*.war matches a filename with spaces, tabs, newlines, etc in it then it will break. You may think "that's unlikely to happen because I know exactly what files are in that directory". And that may even be true. However, you are developing a bad habit that **will** inevitably cause you serious problems one day. Just get into the **good** habit of quoting your variables whenever you use them and avoid developing the bad habit. – cas Dec 29 '21 at 04:40
  • See [Why does my shell script choke on whitespace or other special characters?](https://unix.stackexchange.com/questions/131766/why-does-my-shell-script-choke-on-whitespace-or-other-special-characters) and [$VAR vs ${VAR} and to quote or not to quote](https://unix.stackexchange.com/questions/4899/var-vs-var-and-to-quote-or-not-to-quote) for some of the reasons why you should be careful about quoting and whitespace in shell scripts. – cas Dec 29 '21 at 04:41