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

help() {
cat << EOF
${0}: Replace all the spaces in file and directory
names with "_" in in the current directory.
options:
 -h              Print this message and exit
EOF
}

if [ ${#} -gt 0 ]; then
	[ ${#} = 1 ] && [ "${1}" = "-h" ] && help && exit 0
	printf "%s: Invalid usage\nTry '%s -h' for help.\n" "${0}" "${0}"
	exit 1
fi

for file in ./*; do
	newfile=$(echo "${file}" | tr ' ' '_')
	[ "${newfile}" != "${file}" ] && mv -v "${file}" "${newfile}"
done

exit 0