projects
/
BK-2020-03.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
chore(user/zeropad.sh):Add license
[BK-2020-03.git]
/
user
/
zeropad.sh
diff --git
a/user/zeropad.sh
b/user/zeropad.sh
index 903960266b88c66b148bdedf8f1e51e09ab8dba1..e8b2a88715d6b52ebe0ad0fe0b360a273c7a01c0 100755
(executable)
--- a/
user/zeropad.sh
+++ b/
user/zeropad.sh
@@
-1,18
+1,18
@@
#!/bin/bash
# Desc: Zero-pad working dir files with initial digits for sorting
# Usage: zeropad.sh
#!/bin/bash
# Desc: Zero-pad working dir files with initial digits for sorting
# Usage: zeropad.sh
-# Version: 0.0.
1
+# Version: 0.0.
2
# Find the maximum number of leading digits in the filenames of working dir
# Find the maximum number of leading digits in the filenames of working dir
-max_digits=
$(ls -1 * | sed 's/[^0-9].*//' | awk '{ if(length > L) L=length } END { print L }')
;
+max_digits=
"$(ls -1 * | sed 's/[^0-9].*//' | awk '{ if(length > L) L=length } END { print L }')"
;
declare -p max_digits;
# Loop over the files and rename them
for file in *; do
# Extract the leading digits
declare -p max_digits;
# Loop over the files and rename them
for file in *; do
# Extract the leading digits
- digits=
$(echo "$file" | sed 's/\([0-9]*\).*/\1/')
;
+ digits=
"$(echo "$file" | sed 's/\([0-9]*\).*/\1/')"
;
# Zero-pad the digits
# Zero-pad the digits
- padded_digits=
$(printf "%0${max_digits}d" "$digits")
;
+ padded_digits=
"$(printf "%0${max_digits}d" "$digits")"
;
# Construct the new filename
new_file="${padded_digits}${file#${digits}}";
# Rename the file
# Construct the new filename
new_file="${padded_digits}${file#${digits}}";
# Rename the file
@@
-20,4
+20,5
@@
for file in *; do
# declare -p file new_file; # debug
done;
# declare -p file new_file; # debug
done;
-
+# Author: Steven Baltakatei Sandoval
+# License: GPLv3+