Shell编程之函数调用

Shell中的函数调用的使用方法见我下面的代码示例:

#!/bin/bash

# value init

ExP="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 target
function 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 targetMd5
function 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 here
function Main()
{
    echo "Imagation GPU Version test run ...";
    LoopEx "$ExP" $loop_count $targetMd5
}

Main;

后面写其他的简单脚本可以套用这个模板来做

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值