我怎么用echo来做呢?

perl -E 'say "=" x 100'

当前回答

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

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

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

其他回答

有不止一种方法。

使用循环:

大括号展开可用于整型字面值: 对于I在{1..100};执行echo -n =;完成 类c循环允许使用变量: 开始= 1 结束= 100 ((我= $开始;我< = $结束;我+ +));执行echo -n =;完成

使用内置的printf:

printf '=%.0s' {1..100}

在这里指定精度将截断字符串以适应指定的宽度(0)。当printf重用格式字符串以使用所有参数时,这将简单地打印"=" 100次。

使用head (printf, etc)和tr:

head -c 100 < /dev/zero | tr '\0' '='
printf %100s | tr " " "="

大多数现有的解决方案都依赖于{1..shell的10}语法支持,这是bash和zsh特定的,并且不能在tcsh或OpenBSD的ksh和大多数非bash sh中工作。

以下代码适用于OS X和所有*BSD系统;实际上,它可以用来生成各种类型装饰空间的整体矩阵:

$ printf '=%.0s' `jot 64` | fold -16
================
================
================
================$ 

遗憾的是,我们没有得到一个尾随换行符;这可以通过在折叠后额外的printf '\n'来修复:

$ printf "=%.0s" `jot 64` | fold -16 ; printf "\n"
================
================
================
================
$ 

引用:

http://mdoc.su/-/printf.1 http://mdoc.su/-/jot.1 http://mdoc.su/-/fold.1

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

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

我的答案有点复杂,可能并不完美,但对于那些希望输出大数字的人来说,我能够在3秒内完成大约1000万。

repeatString(){
    # argument 1: The string to print
    # argument 2: The number of times to print
    stringToPrint=$1
    length=$2

    # Find the largest integer value of x in 2^x=(number of times to repeat) using logarithms
    power=`echo "l(${length})/l(2)" | bc -l`
    power=`echo "scale=0; ${power}/1" | bc`

    # Get the difference between the length and 2^x
    diff=`echo "${length} - 2^${power}" | bc`

    # Double the string length to the power of x
    for i in `seq "${power}"`; do 
        stringToPrint="${stringToPrint}${stringToPrint}"
    done

    #Since we know that the string is now at least bigger than half the total, grab however many more we need and add it to the string.
    stringToPrint="${stringToPrint}${stringToPrint:0:${diff}}"
    echo ${stringToPrint}
}
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 =可打印和空白(空格和制表符)。