Linux variable extension problems? … here is a solution to the problem.
Linux variable extension problems?
I want to get a sequence of numbers like 01,02,..,30
However, if I use {01..30}, I get 1,2,.. 30, missing zeros before single digits.
How can I get a format like 01,02..30? Thanks in advance
Solution
In Bash4, your {01..30}
curly brace extension actually works as you wish. If you’re using Bash3 or earlier, you can use the built-in printf
and curly brace extensions to get what you want without resorting to external commands.
$ printf "%02d " {1..20}
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20