
我在簡單閱讀時遇到問題。我讀取了 xml 專案的列表,然後使用它們。在某些時候,我需要詢問我是否確定並接受變數中的此回應。我的問題是,如果我問“while read linea”,“read -p ...”將被忽略,我無法回答這個問題。
xml2 < list | egrep "item" | egrep "url|pubDate|title" | while read linea;
do
case 1 in
$(($x<= 1)))
...
;;
$(($x<= 2)))
...
;;
$(($x<= 3)))
....
if [ $DIFERENCIA -lt $num_dias ];
then
...
read -p “Are you sure: ” sure
...
fi
...
;;
*)
let x=1
;;
esac
done
謝謝
答案1
使用這個代替:
read -p "Are you sure: " sure </dev/tty
引號應該是 ascii 0x22,而不是 UNICODE U-201c“
和 U-201d ”
。
答案2
(對於 bash)提供整個命令列作為其他檔案描述符的輸入3
:
while read -ru 3 linea; do
read -p "Are you sure: " sure
echo "sure=$sure linea=$linea"
done 3< <(xml2 < list | egrep "item" | egrep "url|pubDate|title" )
並且請使用正確的 ascii 雙引號:"
,而不是 U-201c“
和 U-201d ”
。