[英]Cannot pass third argument to bash script
I think the answer will be pretty simple for you, however I cannot handle it alone.我认为答案对你来说很简单,但我无法单独处理。 First of all function in the script looks like:首先脚本中的函数如下所示:
function assertEqual() {
local expected=$1
local actual=$2
local message=$3
echo $message
if [ "$actual" = "$expected" ]
then
echo "Test OK (actual value: $actual)"
return 0
else
echo "Test FAILED, EXPECTED VALUE: $expected, ACTUAL VALUE: $actual, WILL ABORT"
return 1
fi
}
The logic of the function do what it has to do, it is correct however I cannot find a way to print $message into console:该函数的逻辑做它必须做的事情,它是正确的,但是我找不到将 $message 打印到控制台的方法:
local message=$3
echo $message
I am invoking function like this:我正在调用这样的函数:
assertEqual "$MOV_ID_REVS_RECS" $(echo $RESPONSE | jq .movieId) "Comparing id's"
assertEqual 3 $(echo $RESPONSE | jq ".recommendations | length") "Comparing recommendations length"
assertEqual 3 $(echo $RESPONSE | jq ".reviews | length") "Comparing reviews length"
Output I get is like:我得到的输出是这样的:
Test OK (HTTP Code: 200)
Test OK (HTTP Code: 200)
Test OK (HTTP Code: 200)
Wait for messages to be processed...
Test OK (HTTP Code: 200)
Test OK (actual value: 2)
Test OK (actual value: 3)
Test FAILED, EXPECTED VALUE: 3, ACTUAL VALUE: 1, WILL ABORT
You can see that there are blank white rows which means that I am passing third argument wrongly right?您可以看到有空白行,这意味着我错误地传递了第三个参数,对吗?
The issue may be multiple words in the substitution while passing the argument.问题可能是传递参数时替换中的多个单词。
assertEqual "$MOV_ID_REVS_RECS" $(echo $RESPONSE | jq .movieId) "Comparing id's"
assertEqual 3 $(echo $RESPONSE | jq ".recommendations | length") "Comparing recommendations length"
assertEqual 3 $(echo $RESPONSE | jq ".reviews | length") "Comparing reviews length"
Please try to quote the $(echo $RE...)
> "$(echo $RE...)"
in the arguments and test the results.请尝试在参数中引用$(echo $RE...)
> "$(echo $RE...)"
并测试结果。 Alternatively, try passing just assertEqual 3 test "Comparing reviews length"
if all arguments work properly.或者,如果所有参数都正常工作,请尝试仅通过assertEqual 3 test "Comparing reviews length"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.