linux-tutorial/codes/shell/示例脚本/查找替换文本/sed/重定向sed输出.sh

22 lines
319 B
Bash
Raw Normal View History

2019-05-10 11:17:57 +08:00
#!/bin/bash
# add commas to numbers in factorial answer
factorial=1
counter=1
number=$1
while [ $counter -le $number ]
do
2019-10-10 08:56:31 +08:00
factorial=$[ $factorial * $counter ]
counter=$[ $counter + 1 ]
2019-05-10 11:17:57 +08:00
done
result=`echo $factorial | sed '{
:start
s/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/
t start
}'`
echo "The result is $result"