# Description: # -Example below shows how to pad zeroes to a number using PRINTF command. # -It will pad zeroes to the number until the total length is 5. SHORT_NUBMER=13 PADDING_RESULT=$(printf %05d ${SHORT_NUBMER}) echo ${PADDING_RESULT} LONG_NUBMER=343 PADDING_RESULT=$(printf %05d ${LONG_NUBMER}) echo ${PADDING_RESULT} # OUTPUT: # 00013 # 00343
Reference
- http://wiki.bash-hackers.org/commands/builtin/printf