2011-12-16 57 views
0

我需要bash腳本幫助 我在domain.com上有一個包含字符串「1234567」的lic.txt。 我想使用字符串「1234567」。在bash腳本 如果這個詞在http://domain.com/license.txt運行bash腳本功能發現,如果沒有找到輸出誤差許可證無效我怎樣才能在我的bash腳本添加此Bash腳本在txt中檢查單詞

我bash腳本代碼

if [ $1 ]; then 
    SIZE=$(($1 * 1024)) 
else 
    SIZE=$((100 * 1024)) 
fi 
Sname=`echo $0 | sed 's/.\///g'`; 

for x in $TXT_PATH/*_t.txt 
do 
if [ ! -e $LOCK_FILE ]; then 

    if [ "$x" == "$Sname" ]; then 
    echo -ne; 
    elif [ -d "$x" ] || [ -e "$x" ]; then 
     /bin/touch $LOCK_FILE 
     My command 1 
     My command 2 
     My command 3 
     My command 4 
     My command 5 
     My command 6 
     My command 7 
     rm -rf $LOCK_FILE 
    fi 
else 
    echo "Lock file remove for run" 
fi 
done 

回答

2

如果我的理解正確的問題,你需要類似的東西:

wget http://domain.com/license.txt 
code = $(grep 1234567 license.txt) 
if [ -z $code ]; then echo "Invalid license"; else function_call_here; fi 

感謝弗雷德裏克

+1

[UUoCA(http://partmaps.org/era/unix/award.html)一nd不要使用反引號,在編輯後使用`$(...)`代替 – 2011-12-16 13:33:44