我正在尝试在另一个 shell 脚本的函数中执行测试 bash 脚本。该函数接受一个参数,即测试 bash 脚本(echo
命令),然后检查退出状态。这里的问题是将退出状态作为测试脚本输出的第一行。
脚本 :single_run.sh
function sing_run() {
exec_script=$1
`$exec_script`
return_status=$?
if [[ `$return_status` = "0" ]]; then
echo "SUCCESS"
else
echo "FAILURE"
fi
}
sing_run "/bin/bash -x /home/mspprod/customers/adobe/prod/scripts/test_run.sh | tee -a /home/mspprod/customers/adobe/prod/logs/testing.log"
脚本 :test_run.sh
#!/bin/bash
echo "This is a test script"
错误信息:
bash -x single_run.sh
+ sing_run '/bin/bash -x /home/mspprod/customers/adobe/prod/scripts/test_run.sh | tee
-a /home/mspprod/customers/adobe/prod/logs/testing.log'
+ exec_script='/bin/bash -x /home/mspprod/customers/adobe/prod/scripts/test_run.sh |
tee -a /home/mspprod/customers/adobe/prod/logs/testing.log'
++ /bin/bash -x /home/mspprod/customers/adobe/prod/scripts/test_run.sh '|' tee -a
/home/mspprod/customers/adobe/prod/logs/testing.log
+ echo 'This is a Test Script'
+ This is a Test Script
single_run.sh: line 5: This: command not found
+ return_status='echo 127'
++ echo 127
+ [[ 127 = \0 ]]
+ echo FAILURE
FAILURE
我怎样才能获得正确的退出状态而不是This
退出状态?