I'd like to get a sequence of number like this 01,02,..,30 But if I use {01..30}, I will get 1,2,..30, the zero before single-digit number is missing. How can I get the format like 01,02..30 ? Thanks in advance
In Bash4, your {01..30} brace expansion actually works as you want it to. If you are on Bash3 or lower you can use the printf builtin along with the brace expansion 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
seq -w 1 30 # ought to work
as in:
for number in $(seq -w 1 30); do
touch /tmp/bleah$number.dat
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With