我怎么用echo来做呢?

perl -E 'say "=" x 100'

当前回答

如果你想在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 3.0或更高版本中

for i in {1..100};do echo -n =;done
#!/usr/bin/awk -f
BEGIN {
  OFS = "="
  NF = 100
  print
}

Or

#!/usr/bin/awk -f
BEGIN {
  while (z++ < 100) printf "="
}

例子

我的建议(接受n的变量值):

n=100
seq 1 $n | xargs -I {} printf =
n=5; chr='x'; chr_string='';
for (( i=0; $i<$n; i++ ))
do
    chr_string=$chr_string$chr
done
echo -n "$chr_string"

适用于…… N =整数(包括0和负数)。 Chr =可打印和空白(空格和制表符)。

我怎么用echo来做呢?

如果echo后面跟着sed,你可以用echo来实现:

echo | sed -r ':a s/^(.*)$/=\1/; /^={100}$/q; ba'

实际上,这个回声在这里是不必要的。