summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/nospac21
1 files changed, 19 insertions, 2 deletions
diff --git a/scripts/nospac b/scripts/nospac
index 3dee5de..07f53a7 100755
--- a/scripts/nospac
+++ b/scripts/nospac
@@ -1,5 +1,22 @@
#!/bin/sh
-# Replace all the spaces in file names with "_" in the current working directory
+help() {
+cat << EOF
+${0}: Replace all the spaces in file and directory
+names with "_" in in the current directory.
-for file in *; do mv "$file" `echo $file | tr ' ' '_'` ; done
+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