列表文件,并显示在使用bash菜单 [英] List files and show them in a menu with bash
本文介绍了列表文件,并显示在使用bash菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用目录中的文件作为一个bash脚本选项。用户应该能够选择一个,然后通过所选择的文件的名称到一个变量。到目前为止,我能得到的文件列表,但几个小时后,尝试我无法弄清楚如何将它们显示为选项。
I am trying to use the files in a directory as options in a bash script. The user should be able to select one and then pass the name of the selected file into a variable. So far I can get the list of files, but after a few hours trying I can't figure out how to show them as options.
#!/bin/bash
prompt="Please select a file:"
options=( $(find -maxdepth 1 -print0 | xargs -0) )
PS3="$prompt "
select opt in "${options[@]}" "Quit"; do
case "$REPLY" in
for i in "${options[@]}"
do
$i' ) echo "You picked $opt which is file $REPLY";;'
done
$(( ${#options[@]}+1 )) ) echo "Goodbye!"; break;;
*) echo "Invalid option. Try another one.";continue;;
esac
done
任何帮助很多AP preciated。谢谢!
Any help is much appreciated. Thanks!
推荐答案
我不认为情况
是适合这里:
#!/bin/bash
prompt="Please select a file:"
options=( $(find -maxdepth 1 -print0 | xargs -0) )
PS3="$prompt "
select opt in "${options[@]}" "Quit" ; do
if (( REPLY == 1 + ${#options[@]} )) ; then
exit
elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
echo "You picked $opt which is file $REPLY"
break
else
echo "Invalid option. Try another one."
fi
done
ls -ld $opt
这篇关于列表文件,并显示在使用bash菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文