summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorSuleyman Farajli <suleyman@farajli.net>2024-07-27 19:26:32 +0400
committerSuleyman Farajli <suleyman@farajli.net>2024-07-27 19:26:32 +0400
commiteee4d4f29ce0a4256f88c8b65d4ff233b635a26d (patch)
tree098319d46bf394fe2b3c0b9ae1087fc5d91b6909 /scripts
parent69539985bbde98fa8b3a1fb8efbfa53e8b63a604 (diff)
nospac: small script added
Diffstat (limited to 'scripts')
-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