我编写了一个简单的脚本,并编写了一个函数来检查返回值并相应地退出。
#!/bin/bash
function error_exit {
echo "$1" 1>&2
exit 1
}
function check_return_exit () {
$OUT=$1
if [[ $OUT != 1 ]]; then
error_exit $2
fi
}
function install_dependencies {
apt-get install -y lxc expect
EXIT_VAL=$?
EXIT_MSG="Failed to install dependencies (lxc, expect)!!"
check_return_exit $EXIT_VAL $EXIT_MSG
}
install_dependencies
启动脚本时出现此错误。有人可以帮我解决这个错误吗?
Reading package lists... Done
Building dependency tree
Reading state information... Done
expect is already the newest version.
lxc is already the newest version.
The following package was automatically installed and is no longer required:
python-urllib3
Use 'apt-get autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 90 not upgraded.
./launch_lxc.sh: line 9: =0: command not found
Failed
答案 0 :(得分:7)
$OUT=$1 ^
您可能想放弃$
。