我怎么用echo来做呢?
perl -E 'say "=" x 100'
我怎么用echo来做呢?
perl -E 'say "=" x 100'
当前回答
#!/usr/bin/awk -f
BEGIN {
OFS = "="
NF = 100
print
}
Or
#!/usr/bin/awk -f
BEGIN {
while (z++ < 100) printf "="
}
例子
其他回答
Python无处不在,在任何地方都能正常工作。
import sys;Print ('*' * int(sys.argv[1]))"" = " 100
Character和count作为单独的参数传递。
我刚刚发现了一个非常简单的方法来做到这一点使用seq:
更新:此功能适用于OS x附带的BSD序列。YMMV与其他版本
seq -f "#" -s '' 10
将打印'#' 10次,如下所示:
##########
-f "#"设置格式字符串忽略数字,只输出#。 -s "将分隔符设置为空字符串,以删除seq在每个数字之间插入的换行符 -f和-s后面的空格似乎很重要。
编辑:这里是一个方便的功能…
repeat () {
seq -f $1 -s '' $2; echo
}
你可以这样叫它…
repeat "#" 10
注意:如果你重复使用#,那么引号就很重要!
我的答案有点复杂,可能并不完美,但对于那些希望输出大数字的人来说,我能够在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}
}
我怎么用echo来做呢?
如果echo后面跟着sed,你可以用echo来实现:
echo | sed -r ':a s/^(.*)$/=\1/; /^={100}$/q; ba'
实际上,这个回声在这里是不必要的。
最简单的方法是在bash中使用这一行代码:
seq 10 | xargs -n 1 | xargs -I {} echo -n ===\>;echo