按字段读取字符串字段
我们假设字段分隔符是:
var='line: 1
line: 2
line3'
while IFS= read -d : -r field || [ -n "$field" ]; do
echo "-$field-"
done <<< "$var"
输出:
-line-
- 1
line-
- 2
line3
-
我们假设字段分隔符是:
var='line: 1
line: 2
line3'
while IFS= read -d : -r field || [ -n "$field" ]; do
echo "-$field-"
done <<< "$var"
输出:
-line-
- 1
line-
- 2
line3
-