如何从文件添加对话框菜单项?

问题描述 投票:0回答:1

我正在Linux中编写脚本,直到用户按下零按钮,脚本将从dialog --input中获取文件名和路径(例如,以下格式:/etc/bob),然后它将列出用于用户用dialog --menu选择。然后,用户在菜单中选择一个项目,脚本搜索文件,如果文件存在,脚本将选择的文件复制到用户的主目录。

到目前为止,它抛出Error: Expected 2 arguments, found only 1

首先,用户输入要搜索的文件数量,因此该数量将在for循环步骤中以及在dialog --menu中设置为项目数($nu)。然后,dialog --inputbox获取用户位置并将其放置在loc中,然后放置在asd中;之后,在db中。最后,dialog --menuhead文件中获取带有taildb的行条目。

它适用于一件,有时是2件,甚至4件;但随后停止

即使将dialog --menufor循环中移出,在while循环中-也不起作用。

如何解决该问题?

wh=1
while [ $wh -ne 0 ]
do
dialog --inputbox "Please enter numbers of FILE you want to search" 8 60         2>/tmp/num
nu=`cat /tmp/num`

for i in `seq -w 1 $nu` #((i=1;i<=nu;i++));do

dialog --title "Search File" --inputbox "Please enter File name and Location in following Format to search .. [EX. /etc/passwd" 8 60 2> loc    #lo-$i
asd=`cat loc`
echo $asd >> db

dialog --menu "test" 15 50 $nu "1" `cat db | head -n 1`i "2" `cat db | head -n 2 | tail -n 1` "3" `cat db | head -n 3 | tail -n 2` 2>p 1>secl

done

done
linux shell dialog
1个回答
0
投票

到目前为止,我提出来了,一切都很好。但是问题是我无法弄清楚如何确定用户键入了什么,应该搜索哪个文件或查找命令搜索。

我可以用4或5检查用户输入,但是如果用户在脚本开始时输入6 7或8路径怎么办?

请帮助-预先感谢

output so far

clear

wh=1
while [ $wh -ne 0 ];do

    echo "Please enter FileName and Location to search for."
    read loc
    if [ $loc = 0 ];then
    wh=0
    fi
    echo "$loc" >> loc
done
clear
let lc=`wc -l < loc`-1
wz=`cat loc | head -n $lc`
echo "$wz" > eloc

while true;do
clear
echo "$(tput setaf 2)=====================================================================$(tput sgr 0)"
echo "$(tput setaf 2)========================== list of files ============================$(tput sgr 0)"
echo "$(tput setaf 2)=====================================================================$(tput sgr 0)"


for ((i=1;i<=$lc;i++));do
    echo -e " $i : "`cat eloc | head -n $i | tail -n 1` #print each line
    eval d$i=`cat eloc | head -n $i | tail -n 1` #put each line in a variable
done

echo "$(tput setaf 2)============================ q to exit ==============================$(tput sgr 0)"
echo "$(tput setaf 2)== if file is existed, will be copy to current user Home directory ==$(tput sgr 0)"

echo -e "\n"
echo -e "Enter your selection :\c"
read selec


#--------------------------------------------
if [[ "$selec" == q ]];then break; fi
#--------------------------------------------
if [[ "$selec" == "" ]];then
echo "$selec: not a valid selection."
continue
fi
#--------------------------------------------

echo -e "Press enter to continue \c"
read input
done

rm -Rf loc eloc
© www.soinside.com 2019 - 2024. All rights reserved.