hashname (363B)
1 #!/usr/bin/env bash 2 3 usage() { 4 echo "hashname <filename>" 5 exit 1 6 } 7 8 [[ -z "$1" ]] && usage 9 10 hash=$(sha1sum "$1" | awk '{ print $1 }') 11 hashlen=${2:-16} 12 shorthash=${hash:0:$hashlen} 13 filename=$(basename "$1") 14 15 case $filename in 16 *.*) 17 ext="${filename##*.}"; 18 sfilename="${shorthash}.${ext}" 19 ;; 20 *) 21 sfilename="${shorthash}" 22 esac 23 24 echo $sfilename 25