summaryrefslogtreecommitdiff
path: root/rm_whitespaces
blob: 758c1c367280c4f72cb19d203b14d914414af179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh

if [ "$#" -gt 1 ]; then
	echo "Usage: rm_whitespaces <dir>" >&2
	exit 1
fi

if [ "$#" -eq 0 ]; then
	dir="$(pwd)"
else
	dir="$1"
fi

cd "$dir" || {
	echo "Couldn't cd to directory. Exiting..." >&2
	exit 1
}

for file in "$dir"/*; do
	newname="$(echo "$file" | sed -e 's/[ \t]/\_/g' -e 's/["`”“]*//g')"
	mv "$file" "$newname"
done

exit 0