我有一个简单的 bash 脚本,可以在 Unbuntu 20 和 LMDE 4 上按预期工作。但是,当我在 Debian 11 上运行它时,它会退出并出现错误:
"choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)" command filed with exit code 127.
我以 root 身份运行它,但仍然收到错误。我还检查了以下代码:shellcheck.net它说一切都很好。这是 Debian 11 的全新安装。
有什么建议么?我很感激。
这是代码:
#!/bin/bash
# exit when any command fails
set -e
# keep track of the last executed command
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# echo an error message before exiting
trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT
cmd=(dialog --separate-output --checklist "Select options:" 22 76 16)
options=(1 "Option 1" off # any option can be set to default to "on"
2 "Option 2" off
3 "Option 3" off
4 "Option 4" off)
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
clear
for choice in $choices
do
case $choice in
1) ls
echo "First Option"
;;
2) pwd
echo "Second Option"
;;
3) pwd
echo "Third Option"
;;
4) ls -la
echo "Fourth Option"
;;
esac
done
答案1
它突然击中了我。缺少的是对话。我安装了它并且脚本按预期运行。