Shell編程之函數調用

來源:互聯網
上載者:User

標籤:style   blog   color   使用   io   for   ar   cti   

Shell中的函數調用的使用方法見我下面的程式碼範例:

#!/bin/bash# value initExP="adb shell /data/local/tmp/vpxdec  --yv12 --flipuv  -t 2 --md5   data/local/tmp/vp9Input/subset_function_test/Boating_1920x1080_t4_yv12_400frames_skip200.webm";TT="adb shell ls -l /data/local/tmp/";loop_count=2;targetMd5="2e8698fe47dd40bf6260206416530985";# Compare two value and output result,$1 is src,$2 is targetfunction Compare(){    #echo "Source value:$1, Target value:$2";    if [ "$1" = "$2" ]; then            echo "The same!";        return 0;    else            echo "Different!"        return 1;    fi    }# LoopEx: excute a programm in a loop, $1 is program,$2 is loop count, $3 is targetMd5function LoopEx(){    local Ex=$1;    local loop_count=$2;    local target=$3;    echo -e "Programm is $Ex \nloop_count ==$loop_count, TargetMd5==$target"    for i in $(seq $loop_count); do        local output=$($Ex);        local outputMd5=${output:0:32}        Compare $outputMd5 $target;        if [ "$?" != "0" ]; then            echo "Loop Break index is [$i],result MD5:$outputMd5"            break        fi    done;}# function main, shell excute from herefunction Main(){    echo "Imagation GPU Version test run ...";    LoopEx "$ExP" $loop_count $targetMd5}Main;

後面寫其他的簡單指令碼可以套用這個模板來做

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.