Skip to content

Instantly share code, notes, and snippets.

@gMan1990
Last active October 28, 2018 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gMan1990/1ef4dda4f0490bc3bea4ef3d14399e32 to your computer and use it in GitHub Desktop.
Save gMan1990/1ef4dda4f0490bc3bea4ef3d14399e32 to your computer and use it in GitHub Desktop.
递归列出jar文件内容便于查找Class
#!/bin/bash
# usage: bash this.sh path
# $1: path, parsed
jarList() {
path=$1
if [ -d "$path" ]; then
cd "$path" || exit #https://github.com/koalaman/shellcheck/wiki/SC2045
for sub in *; do
if [ "/" = "$1" ]; then
jarList "/$sub"
else
jarList "$1/$sub"
fi
done
elif [ -f "$path" ]; then
if [ "." != "${path%%_*}" ] && [ "jar" = "${path##*.}" ]; then
echo -e "\nJAR: $path"
jar -tf "$path"
fi
else
echo "type unimplement, file: [$path]"
return 1
fi
}
path=$1
if [ -d "$path" ]; then
path=$(cd "$path" && pwd)
dirname=$(dirname "$path")
basename=$(basename "$path")
if [ "/" = "$basename" ]; then
basename=""
fi
elif [ -f "$path" ]; then
dirname=$(cd "$(dirname "$path")" && pwd)
basename=$(basename "$path")
else
echo "type unimplement, file: [$path]"
exit 1
fi
if [ "/" = "$dirname" ]; then
dirname=""
fi
jarList "$dirname/$basename"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment