我有一个用于测试软件的功能。我必须调用此函数,其中函数有2个参数,即currentSetName和failureDetected。这是代码:
#!/bin/bash
failureDetected=0
nbOfAllTests=0
nbOfDetectedFailures=0`
currentSetName="fair"
count_input=1
removeFromCurrentSet(){
if [[("$1" == "good")]]
then
#mv Partition/currentSet/* Partition/good_used
echo "Hai good"
elif [[("$1" == "fair")]]
then
if [[("$2" == "0")]]
then
#mv Partition/currentSet/* Partition/poor_used
echo "hai fair poor_used"
else
#mv Partition/currentSet/* Partition/good_used
echo "hai fair good"
fi
else
#mv Partition/currentSet/* Partition/poor_used
echo "jjj poor"
fi
}
removeFromCurrentSet currentSetName failureDetected
我使用上面的代码,但效果不佳。你能帮我解决这个问题吗?我怎样才能完全调用该函数?
答案 0 :(得分:3)
您错误地传递了参数。您的原始代码等同于
removeFromCurrentSet "currentSetName" "failureDetected"
只传递两个字符串,因为currentSetName
和failureDetected
未展开。您需要先使用$
扩展变量。
要传递给函数,变量的值会尝试这样:
removeFromCurrentSet "${currentSetName}" "${failureDetected}"