將字串的欄位讀入陣列
我們假設欄位分隔符是:
var='1:2:3:4:
newline'
arr=()
while IFS= read -d : -r field || [ -n "$field" ]; do
arr+=("$field")
done <<< "$var"
echo "${arr[4]}"
輸出:
newline
我們假設欄位分隔符是:
var='1:2:3:4:
newline'
arr=()
while IFS= read -d : -r field || [ -n "$field" ]; do
arr+=("$field")
done <<< "$var"
echo "${arr[4]}"
輸出:
newline