變數中有變數作判斷該如何作? (eval) - Linux

By Lily
at 2017-08-25T18:38
at 2017-08-25T18:38
Table of Contents
小弟在寫測試script時, 在使用eval上遇到了一些問題, 想請教:
因為Cmp${Num}_F代入的數值是小數, 所以又增加了bc來輔助, Code如下:
需求是判斷Cmp${Num}_F是否介於LOWER與UPPER之間,
但是在變數$Cmp${Num}_F放到if裡面的時候出了錯誤, 請問我該怎麼在if裡面使用這類型的變數?
##COMPARISON
Amount=5
UPPER=1234.567
LOWER=12.3456
for ((Num=1 ; Num<Amount; Num++))
do
eval Cmp${Num}_F=$(cat xxx.log |grep Cmp${Num}_F |awk 'print $2')
done
for (( Num=1 ; Num<$Amount ; Num++ ))
do
if [ `echo "`$Cmp${Num}_F` > $UPPER"|bc` -eq 1 ] || [ `echo "`$Cmp${Num}_F` < $LOWER"|bc` -eq 1 ]; then
echo " Data in Range `eval echo '$'Cmp${Num}_F` Front: ($LOWER ~ $UPPER) "
else
echo " Data Not in Range"
fi
done
--
Tags:
Linux
All Comments

By Iris
at 2017-08-30T06:35
at 2017-08-30T06:35

By Carolina Franco
at 2017-09-03T13:07
at 2017-09-03T13:07

By Sierra Rose
at 2017-09-04T19:21
at 2017-09-04T19:21
``時,一律用$()取代

By Hamiltion
at 2017-09-06T23:51
at 2017-09-06T23:51

By Margaret
at 2017-09-07T08:02
at 2017-09-07T08:02

By Victoria
at 2017-09-08T02:06
at 2017-09-08T02:06
(standard_in) 1: syntax_error

By Zora
at 2017-09-08T14:56
at 2017-09-08T14:56

By Linda
at 2017-09-09T10:19
at 2017-09-09T10:19

By Eartha
at 2017-09-10T23:20
at 2017-09-10T23:20

By Joseph
at 2017-09-14T20:10
at 2017-09-14T20:10

By Olga
at 2017-09-16T01:53
at 2017-09-16T01:53

By Ina
at 2017-09-19T17:21
at 2017-09-19T17:21

By Dorothy
at 2017-09-20T16:20
at 2017-09-20T16:20

By Kelly
at 2017-09-24T11:04
at 2017-09-24T11:04

By Oscar
at 2017-09-25T06:18
at 2017-09-25T06:18

By Ida
at 2017-09-29T11:46
at 2017-09-29T11:46

By Mason
at 2017-10-02T13:06
at 2017-10-02T13:06

By Eartha
at 2017-10-05T20:58
at 2017-10-05T20:58

By Sierra Rose
at 2017-10-07T21:52
at 2017-10-07T21:52

By Damian
at 2017-10-10T03:16
at 2017-10-10T03:16

By Isla
at 2017-10-12T15:54
at 2017-10-12T15:54

By Isabella
at 2017-10-14T00:58
at 2017-10-14T00:58
型的疊加變數了 ~"~a 是嗎?

By Mia
at 2017-10-16T04:01
at 2017-10-16T04:01
參考看看 https://pastebin.com/pJDgjfG4

By George
at 2017-10-16T09:55
at 2017-10-16T09:55

By Caroline
at 2017-10-16T20:34
at 2017-10-16T20:34

By Hazel
at 2017-10-21T08:21
at 2017-10-21T08:21

By Jacob
at 2017-10-21T14:00
at 2017-10-21T14:00
Related Posts
請教export用法

By Bennie
at 2017-08-24T02:19
at 2017-08-24T02:19
關於筆電的fn鍵

By Mason
at 2017-08-22T14:56
at 2017-08-22T14:56
請問一個sed處理文字檔的的寫法

By Mia
at 2017-08-21T17:02
at 2017-08-21T17:02
網頁開不起來

By Margaret
at 2017-08-21T16:33
at 2017-08-21T16:33
motion跟sh跟py還有telegram bot的問題

By Zora
at 2017-08-21T12:58
at 2017-08-21T12:58