我怎么用echo来做呢?
perl -E 'say "=" x 100'
我怎么用echo来做呢?
perl -E 'say "=" x 100'
当前回答
在bash 3.0或更高版本中
for i in {1..100};do echo -n =;done
其他回答
我的建议(接受n的变量值):
n=100
seq 1 $n | xargs -I {} printf =
在bash 3.0或更高版本中
for i in {1..100};do echo -n =;done
没有简单的方法。但是举个例子:
seq -s= 100|tr -d '[:digit:]'
# Editor's note: This requires BSD seq, and breaks with GNU seq (see comments)
或者是一种符合标准的方式:
printf %100s |tr " " "="
还有一个tput代表,但对于我手头的终端(xterm和linux),它们似乎不支持它:)
最简单的方法是在csh/tcsh中使用这一行代码:
printf "%50s\n" '' | tr '[:blank:]' '[=]'
这是以利亚·卡根所支持的观点的长版本:
while [ $(( i-- )) -gt 0 ]; do echo -n " "; done
当然,你也可以使用printf,但不是我喜欢的:
printf "%$(( i*2 ))s"
这个版本与Dash兼容:
until [ $(( i=i-1 )) -lt 0 ]; do echo -n " "; done
I是初始数。