2017-11-14 14 views
0

파일에서 숫자를 읽는 스크립트를 원합니다.이 숫자가 일정 값 이상이면, 다른 명령을 실행합니다. 그렇지 않으면 스크립트가 죽을 것입니다. 다음과 같이됩니다.숫자가 같거나 X 값보다 크면 파일에서 숫자를 읽고 명령을 실행하는 Bash 스크립트

[[email protected] ~]# cat result.txt 
50 
[[email protected] ~]# 
[[email protected] ~]# ./run.sh 
result.txt is higher or equals 50. Running /sbin/reboot 
[[email protected] ~]# 

감사합니다.

+0

시도한 것을 보여줄 수 있습니까? – urban

답변

1
#!/bin/bash 

THRESHOLD=50 
VALUE=$(cat result.txt) 

# -eq -> equals 
# -gt -> greater than 
# -ge -> greater than or equal (you are looking for this one) 

if [ $VALUE -ge $THRESHOLD ] 
then 
    # Your action 
fi 
+0

고맙습니다. :) –

+0

니스! 이게 도움이된다면 대답을 받아 들여주세요. –