我对 zenity 列表有疑问。问题是如果我选择例如opt2返回我opt1和opt2作为结果。当我从终端运行命令时,结果是正确的。这是我的脚本
#!/bin/bash
opt1=$(cat ~/test.txt | head -n 1 | tail -n 1)
opt2=$(cat ~/test.txt | head -n 2 | tail -n 1)
opt3=$(cat ~/test.txt | head -n 3 | tail -n 1)
response=$(zenity --list --width="350" --height="350" --text "Text" --checklist --column "Text" --column "Text" FALSE "$opt1" FALSE "$opt2" FALSE "$opt3" --separator=":")
(
[[ $response = *$opt1* ]] && echo "$opt1" >> file.txt
[[ $response = *$opt2* ]] && echo "$opt2" >> file.txt
[[ $response = *$opt3* ]] && echo "$opt3" >> file.txt
[[ $response = *$opt4* ]] && echo "$opt4" >> file.txt
[[ $response = *$opt5* ]] && echo "$opt5" >> file.txt
)
我也尝试了[ $response = "$opt2" ] 但没有成功,并且[ $response = $opt2 ]仅在我从列表中选择一个选项时才有效,但如果我选择多个选项,则结果为空白。文件test.txt是这样的
name-1
name-1-new
name-1-0-new
name-2
name-2-new
name-2-0-new
name-3
name-3-new
name-3-0-new
有谁知道我如何解决这个问题?