bash中for循環的一個特別寫法

#!/bin/bash
# program:      lists big planets

for planet in "Mercury 36" "Venus 67" "Earth 93" "Mars 142" "jupiter 483"
do
        set -- $planet
        echo "$1        $2,000,000 miles from the sun."
done

這裏“set -- $planet”重新指定了命令行參數。將planet的內容作爲命令行參數。

而且這裏planet是每個雙引號括起來的字符串而不是像

for planet in "Mercury Venus Earth Mars Jupiter"

時,$planet代表每個詞。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章