将参数传递到脚本以及函数之间的问题

时间:2018-08-23 14:10:59

标签: bash

下午,请抱紧我,我仍在学习bash。

我有一个脚本,我想将两个参数传递给该脚本,并在该脚本中调用一个函数来处理该参数。

脚本:

function checksum_download()
{
        # Check if the supplied hash is the same as the hash of the stored file
        if [ "$(md5sum < $1)" = "$2  -" ]
        then
                echo "Match"
        else
                echo "Fail"
        fi
        exit 0
}

./processing.sh checksum_download "/user/scripts/file.txt" d41d8cd98f00b204e9800998ecf8427e

我知道我可以在脚本中通过添加checksum_download $1 $2来调用函数,但是如果执行此操作,则每次调用脚本时都会调用该函数,并且脚本中有多个函数。

传递要处理的函数名称和参数的最简单方法是什么?

0 个答案:

没有答案
相关问题