我在Linux中编写了一个脚本,直到用户按下零按钮,脚本将从dialog --input中获取文件名和路径(例如,采用以下格式:/etc/bob),然后它将列出可供用户使用dialog --menu选择的位置。然后,用户在菜单中选择一项,脚本将搜索该文件,如果该文件存在,则脚本将所选文件复制到用户的主目录。
到目前为止,它抛出了Error: Expected 2 arguments, found only 1。
首先,用户输入他想要搜索的文件的数量,因此这个数量将在for循环步骤中设置,并在dialog --menu中设置为项数($nu)。然后,dialog --inputbox获取用户位置并将其放入loc,然后放入asd;然后放入db。最后,dialog --menu从db文件中获取带有head和tail的行条目。
它适用于一项,有时是2项,甚至4项;但随后它就停止了
即使我将dialog --menu放在for循环之外的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发布于 2019-02-05 04:49:28
到目前为止,我想出了这个,所有的东西都是搜索的,问题是我不知道如何计算用户输入的内容,以及我应该搜索哪个文件,或者fine.but命令。
我可以用4或5if检查用户输入,但如果脚本开头的用户输入6、7或8路径怎么办?
请帮帮忙-提前谢谢

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 elochttps://stackoverflow.com/questions/54389449
复制相似问题