我怎么用echo来做呢?
perl -E 'say "=" x 100'
我怎么用echo来做呢?
perl -E 'say "=" x 100'
当前回答
我的建议(接受n的变量值):
n=100
seq 1 $n | xargs -I {} printf =
其他回答
最简单的方法是在bash中使用这一行代码:
seq 10 | xargs -n 1 | xargs -I {} echo -n ===\>;echo
在bash 3.0或更高版本中
for i in {1..100};do echo -n =;done
我猜这个问题的最初目的是仅用shell的内置命令来完成这个任务。因此,for循环和printfs是合法的,而下面的rep、perl和jot则不是。但是,下面的命令
$((COLUMNS/2))
例如,打印的窗户完全线 \/\/\/\/\/\/\/\/\/\/\/\/
repeat() {
# $1=number of patterns to repeat
# $2=pattern
printf -v "TEMP" '%*s' "$1"
echo ${TEMP// /$2}
}
没有简单的方法。但是举个例子:
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),它们似乎不支持它:)