我怎么用echo来做呢?

perl -E 'say "=" x 100'

当前回答

问题是关于如何使用echo:

echo -e ''$_{1..100}'\b='

这将与perl -E 'say "=" x 100'完全相同,但只使用echo。

其他回答

建议的Python解决方案的更优雅的替代方案可能是:

python -c 'print "="*(1000)'

如果你想在echo和printf的不同实现之间遵循posix并保持一致性,和/或shell而不仅仅是bash:

seq(){ n=$1; while [ $n -le $2 ]; do echo $n; n=$((n+1)); done ;} # If you don't have it.

echo $(for each in $(seq 1 100); do printf "="; done)

...将在所有地方产生与perl -E 'say "=" x 100'相同的输出。

最简单的方法是在bash中使用这一行代码:

seq 10 | xargs -n 1 | xargs -I {} echo -n  ===\>;echo

for i in {1..100}
do
  echo -n '='
done
echo

没有简单的方法。但是举个例子:

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),它们似乎不支持它:)