我不能替换“?”用两位数表示; 当我尝试替换字符“?”时带有两位数的数字,仅打印第一个数字
我需要打印一个具有不同连续数字的字符串,这是我能够用这一行代码完成的;
echo 'my-page-number-?' | tr '?' ${i}
但是当数字是两位数时,它将被切断;
#!/bin/bash
numbers=13
for (( i=1; i <= ${numbers}; ++i ))
do
echo 'my-page-number-?' | tr '?' ${i}
done
my-page-number-1
my-page-number-2
my-page-number-3
my-page-number-4
my-page-number-5
my-page-number-6
my-page-number-7
my-page-number-8
my-page-number-9
my-page-number-10
my-page-number-11
my-page-number-12
my-page-number-13
答案 0 :(得分:1)
像这样使用printf:
for (( i=1; i <= ${numbers}; ++i ))
do
printf "my-page-number-%02d" $i
done