0

I am using a shell script to find out files which contains a class file from a list of JAR files in UNIX using bash script:

find . -name "*.jar" -exec bash -c 'jar -tf {} |grep -H --label {} GenericClassLoader' \;

But I was getting error as :

java.util.zip.ZipException: error in opening zip file
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:131)
        at java.util.zip.ZipFile.<init>(ZipFile.java:92)
        at sun.tools.jar.Main.list(Main.java:997)
        at sun.tools.jar.Main.run(Main.java:242)
        at sun.tools.jar.Main.main(Main.java:1167)

I am taking help from this post : Find for a class file in Linux that is present in JAR

In order to avoid the error I have modified my query as:

find . -name "*.jar" -exec bash -c 'jar -tf {} 2>&/dev/null |grep -H --label {} GenericClassLoader' \;

But I started getting below errors:

bash: /dev/null: ambiguous redirect

Please help me in solving this issue, what is the issue with my command.

Community
  • 1
  • 1
chaitanya
  • 701
  • 4
  • 14
  • 26

1 Answers1

2

It is because of the redirection you wrote, you should redirect with 2> /dev/null to send stderr to /dev/null (provided this is what you want).

Also note that you are not fixing the error, you are just preventing it to be visible.

For more details look here: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html

Alberto Zaccagni
  • 30,779
  • 11
  • 72
  • 106