All pastes #955251 Raw Edit

Anonymous

public text v1 · immutable
#955251 ·published 2008-03-24 14:12 UTC
rendered paste body
#!/bin/bash

index() {
		usedext=0
		for (( i=0; i < ${#exts[@]}; i++ ));  do
			if [ "${exts[i]}" = "$1" ]; then
				usedext=1
				(( counts[i]++ ))
				i=${#exts[@]}
			fi
		done
		if [ $usedext = "0" ]; then
			exts+=("$1")
			counts+=("1")
		fi
}

exts=()
counts=()

path=`pwd`
if [ ! $1 = "" ]; then
	path=$1
fi

IFS_=$IFS
IFS=$'\n'

for file in `dir "$path" -a1`; do
# there are multiple possibilities: does the filename contain a dot?
	if [ -d $file ]; then
		if [[ $file == .* ]]; then
			index ".dir"
		else
			index "dir"
		fi
	else
		if [[ $file =~ \. ]]; then
			if [[ $file == .* ]]; then
				index ".file"
			else
				index "${file##*.}"
			fi
		else
			index "file"
		fi
	fi
done

IFS=$IFS_

for (( i=0; i < ${#exts[@]}; i++ ));  do
	echo ${exts[i]}$'\t'${counts[i]}
done