我怎么用echo来做呢?

perl -E 'say "=" x 100'

当前回答

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

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

其他回答

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

python -c 'print "="*(1000)'
repeat() {
    # $1=number of patterns to repeat
    # $2=pattern
    printf -v "TEMP" '%*s' "$1"
    echo ${TEMP// /$2}
}

如果你想在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'相同的输出。

Python无处不在,在任何地方都能正常工作。

import sys;Print ('*' * int(sys.argv[1]))"" = " 100

Character和count作为单独的参数传递。

我猜这个问题的最初目的是仅用shell的内置命令来完成这个任务。因此,for循环和printfs是合法的,而下面的rep、perl和jot则不是。但是,下面的命令

$((COLUMNS/2))

例如,打印的窗户完全线 \/\/\/\/\/\/\/\/\/\/\/\/