#!/bin/bash # Author : Martti Kühne # Created On : Thu Apr 10 03:06:54 CEST 2008 # Created On Node : base (my laptop) # Last Modified By : Martti Kühne # Last Modified On : Thu Apr 10 03:06:54 CEST 2008 # Last Machine Used: base (my laptop) # Update Count : 1 # Status : Tested. A Backup of the target directory is recommended though. # HISTORY : # Description : $($progname -h) # make sure we exit on error set -e # we do use globbing in this script and don't want to be bothered with error messages shopt -s nullglob progname="`basename \"$0\"`" pversion='$Revision: 1.0 $' # echoes the ascii char of $1 chr() { # printf \\$(printf '%03o' $1) # doesn't work # eval "echo \$'\\x$(printf %x $1)'" printf '%b\n' "$(printf '\\0%o' "$1")" } # echoes 0 if the first character of $1 is a digit isnum() { echo ${1:0:1} | tr '[:digit:]' '0' } upper() { echo $@ | tr "[:lower:]" "[:upper:]" } # echoes the full path or returns 1 fullp() { [ -d $@ ] || return 1 [ ${@:0:1} = "/" ] || echo -n "$(pwd)/" echo $@ } usageversion() { cat >&2 <&2 "$progname: error: the directory specified does not exist."; exit 1 } ;; -unaz) unaz=1 ;; *) cat >&2 </dev/null set -e rm -r "$fullpath" } else # only create directories that don't exist if [ $char = $compchar ]; then files=("$targetdir"/$char* "$targetdir"/$(upper $char)*) else files=("$targetdir"/$char*) fi if [ ${#files[@]} != "0" ]; then [ ! -d "$fullpath" ] && mkdir "$fullpath" # here we go. for line in "${files[@]}"; do [ -f "$line" ] && mv "$line" "$fullpath" done fi fi done exit 0