Created
September 28, 2023 08:22
-
-
Save opplatek/c77daef31b0bfec33aa9254c89559e24 to your computer and use it in GitHub Desktop.
Fill (prefix zeros) number of digits to predefined number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DIGIT=52 | |
TARGET_DIGITS=4 | |
# Easier | |
echo $(printf "%0${TARGET_DIGITS}d" ${DIGIT}) | |
#0052 | |
# More complicated | |
FILL=$(echo $TARGET_DIGITS - ${#DIGIT} | bc) | |
echo $(printf '0%.0s' $(seq 1 "$FILL"))${DIGIT} | |
#0052 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment