开发者

Linux variable expansion problem ?

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜