我正在撰寫一個極小的腳本,我需要檢查值。
size 將是一個浮點數,或帶小數點的數字,例如 28.0。
出于某種原因,每當我運行時,我都會收到此錯誤:
1 while read -r line;
2 do
3 sample=$(echo $line | awk 'BEGIN{FS="/"}; {print $5}')
4 size=$(aws s3 ls --summarize --human-readable $line | grep "Total Size:" | awk 'BEGIN{FS=" "}; {print $3}')
5 # aws s3 cp $line ./crams/
6 if [[ $( echo "${size} < 20" | bc ) -eq 1 ]]; then
7 echo "${sample}\t${size}"
8 fi
9 done < $1
download-aws.sh: 6: download-aws.sh: [[: not found
有什么想法嗎???
另外,如果您知道將浮點數與整數進行比較的更好方法……那就太好了!
謝謝
編輯:
所以我找到了一個解決方案,我將 if 陳述句更改為:
if [ $( echo "${size} < 20" | bc ) -eq 1 ]; then
如果有人能指出我對括號等背后邏輯的一些很棒的解釋的方向……那就太棒了!
uj5u.com熱心網友回復:
來自“Bourne Shell built-ins”檔案:
https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html
test [ test expr Evaluate a conditional expression expr and return a status of 0 (true) or 1 (false). Each operator and operand must be a separate爭論。運算式由以下 Bash 條件運算式中描述的基元組成。test 不接受任何選項,也不接受和忽略 -- 作為表示選項結束的引數。
When the [ form is used, the last argument to the command must be a ].
換句話說,
[是“測驗”的別名
問:你有沒有機會為“size”分配一個整數?因此,也許您的測驗條件可以簡化為:
if [ $size -lt 20 ]; then
...
fi
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/421747.html
標籤:
上一篇:嵌套ifelse()或case_when()用于R中未知數量的查詢
下一篇:文本輸入過濾器未初始化?
