回文章列表
作者fu0653.bbs@ptt.cc (fu0653) 看板: linux
標題Re: [問題] bash程式設計小問題!!
時間批踢踢實業 (2008/09/01 Mon 16:31:22)
想請問像下面簡單的1加到100

#!/bin/bash
s=0
for (( i=1; i<=100; i=i+1 ))
do
        s=$(($s+$i))
done
echo "The result of '1+2+3+...+100' is ==> $s"

原本只會run一次The result of '1+2+3+...+100' is ==> $s
那我在這行s=$(($s+$i))後面加上& 變成s=$(($s+$i))&
這樣子他就會run100次The result of '1+2+3+...+100' is ==> $s
是這樣子的意思嗎??

--
※ 發信站: 批踢踢實業坊(ptt.cc) 
◆ From: 61.231.160.28
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻