我有內容的文件:條件使用
$> cat file
1
2
4
現在,我想用/運行另一個腳本,如果數量(減法)之間的差異大於1時,從主否則退出腳本。
我試圖做到這一點通過以下方式,但不工作:
less file \
| awk '\
function abs(x){return (((x < 0.0) ? -x : x) + 0.0)}\
BEGIN{i=1;}\
{new=old;old=$1}\
{if(abs($1-new)>1)i++;}
END{if(i>1) print 1; else print 0;}' \
| while read i;do
if ((${i}));then
echo -n "Would you like to continue? [yes or no]: "
read yno
case ${yno} in
y)
echo Continuing...
;;
n)
echo Exiting...
;;
*)
echo "Invalid input"
;;
esac
else echo Cont...
fi
done
我所期望的,如果$ {I} == 1,那麼我就可以做出決定,我是否要繼續與否。
快樂幫您解決問題,如果這些解決方案都沒有幫助,如果你能澄清通過提示「你......」你的意圖。爲什麼你不能做減法並且允許退出代碼來確定在awk之外發生了什麼。你說'但不起作用:',請編輯你的問題以顯示你得到了什麼錯誤信息,或者說明你爲什麼說它不起作用。它看起來應該起作用。祝你好運。 – shellter 2012-01-06 04:02:58