【发布时间】:2015-07-02 23:06:25
【问题描述】:
我试图拼凑一个脚本来列出不同的 jws 目录,并允许用户在继续编辑目录中的 jnlp 文件之前选择不同的客户端目录。我的编辑部分正在工作,我的菜单大部分都在工作;做出选择后,我无法弄清楚如何退出循环。
我希望它在没有选择数字的情况下按 ENTER 键退出,然后继续执行脚本的下一部分。
function update_jnlp
{
while :
do
# JNLP update submenu
options=($(ls /tmp/test/ | grep "jws$"))
menu() {
clear
echo "Locally installed jnlps:"
for i in ${!options[@]}; do
printf "%3d%s) %s\n" $((i+1)) "${choices[i]:- }" "${options[i]}"
done
[[ "$msg" ]] && echo "$msg"; :
}
prompt="Check an option (again to uncheck, ENTER when done): "
while menu && read -rp "$prompt" num && [[ "$num" ]]; do
[[ "$num" != *[![:digit:]]* ]] &&
(( num > 0 && num <= ${#options[@]} )) ||
{ msg="Invalid option: $num"; continue; }
((num--)); msg="${options[num]} was ${choices[num]:+un}checked"
[[ "${choices[num]}" ]] && choices[num]="" || choices[num]="+"
done
printf "You selected"; msg=" nothing"
for i in ${!options[@]}; do
[[ "${choices[i]}" ]] && { printf " %s" "${options[i]}"; msg=""; }
done
done
for i in ${choices[@]}; do
printf "%s\n" ${choices[@]};
echo "fun"
done
echo "@msg"
# here is the script to edit the files now contained as ${choices[@]}
}
我意识到我在一个菜单循环中,并且我需要验证来自读取命令 = "" 的输入或 $prompt 输入是否为空,我假设我从那里中断
【问题讨论】:
-
"我意识到我在一个菜单循环中,并且我需要验证来自读取命令 = "" 的输入或 $prompt 输入是否为空,我假设我从那里“你试过吗?
-
我有,但我想我只是无法正确获取操作顺序或语法。
-
$prompt input is null
$prompt必须为“null”的值是多少?尝试打印它并查看它包含的内容,如果您的意思是未设置,请尝试[ "$prompt" ] || break。read存储在$num中。要查看它是否为空字符串,请使用完全相同的[ "$num" ] || break。