我寫了一個樣本KornShell函數來分割一個String,將它放入一個數組中,然後打印出這些值。 的代碼如下KSH中的變量範圍
#!/usr/bin/ksh
splitString() {
string="[email protected];[email protected];[email protected]"
oIFS="$IFS";
IFS=';'
set -A str $string
IFS="$oIFS"
}
splitString
echo "strings count = ${#str[@]}"
echo "first : ${str[0]}";
echo "second: ${str[1]}";
echo "third : ${str[2]}";
現在echo
沒有打印出數組的值,所以我認爲它是與定義的數組的範圍。
我是新來的殼牌腳本,任何人可以幫助我瞭解變量的作用域在上面的例子嗎?
疑難雜症!!!! 該腳本正在工作,沒有問題。做了一個以錯誤的方式調用函數的小錯誤。 但是仍然想了解KSH的變量範圍 – Vivek 2012-08-17 06:47:32