【发布时间】:2015-12-03 00:17:19
【问题描述】:
我需要编写一个具有以下行为的脚本:
$ echo $'one&some text\ntwo&other text' | ./my_script.sh --delimiter &
Line:
1st: one
2nd: some tex
Line:
1st: two
2nd: other text
也可以使用默认分隔符\t:
$ echo $'one\tsome text\nfive\tother text' | ./my_script.sh
输出应该和上面一样。
脚本应该通过标准输入接受输入。
最简单的方法是什么?可能在纯 bash 中。
我尝试过这种方法,但它不起作用,我不知道为什么:
while read -r line
do
echo "$line"
IFS=$DELIMITER
arr=(${line//$DELIMITER/ })
echo ${arr[0]}
echo ${arr[1]}
done
【问题讨论】:
标签: bash