#!/bin/bash #=============================================================================== # check a java classpath for duplicate classes #=============================================================================== # possible usage exit [ $# -ne 1 ] && { echo >&2 "usage: $(basename "$0") classpath .." exit 1 } # main pipeline echo "$1" | tr ':;' '\n' | while IFS=$'\n' read -r part; do [ -n "$part" ] || continue; [ -e "$part" ] || { echo >&2 "cannot find $part"; continue; } [ -r "$part" ] || { echo >&2 "cannot read $part"; continue; } echo >&2 "checking $part" echo -en "#\t" echo "$part" if [ -f "$part" ]; then unzip -l "$part" | awk 'NR > 3 && $4 != "" && $4 !~ "/$" {print $4}' elif [ -d "$part" ]; then find "$part" -type f -printf "%P\n" fi done | awk ' BEGIN { FS = "\t" } $1 == "#" { part = $2 next } { found[$1] = found[$1] "\t" part count[$1]++ } END { for (file in found) { if (count[file] > 1) print file found[file] } } ' | sort -u #=============================================================================== #:mode=shellscript:noTabs=false:tabSize=4:indentSize=4:lineSeparator=\n: