Linux variable extension problem?

I would like to get a sequence of numbers like this 01,02, .., 30 But if I use {01..30}, I will get 1,2, ... 30, zero before the single-digit number is missing. How can I get the format, for example, 01,02..30? thanks in advance

+3
source share
2 answers

In Bash4, your brace extension {01..30}actually works the way you want it. If you are on Bash3 or lower, you can use the built-in printfalong with the brace extension 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
+3
source

seq -w 1 30  # ought to work

how in:


for number in $(seq -w 1 30); do
 touch /tmp/bleah$number.dat
done
+1
source

Source: https://habr.com/ru/post/1776813/


All Articles