0

我正在尝试创建一个脚本,用户将在其中运行它选择一个选项,然后提示输入 a$FileName和 a$Number我将如何在 bash 中执行此操作?

这是我现在需要的选项 [1] 和 [3] 中的帮助:

Begin
echo "-----------------------------"
echo "   Data Processing Menu      "
echo "-----------------------------"
begin case structure
echo "What would you like to do"
echo "*[1]Enter Number $Number of Files $FileName to output.txt*"
echo "*[2]Show Classifiers only"
echo "*[3]Auto All $All of Files $AllFileName to output.txt*"
echo "*[4]Exit/Abort*"
echo "------------------------------------------------------"
echo -n "Enter your choice [1-4]:"
read Pmenu
case $Pmenu in
 1) "Building";;
 2) cut -f 4 input.txt;;
 3) "Building";;
 4) exit 0;;

 esac

以下是此脚本通过 ( input.txt) 处理的数据:

FilePath    Filename    Probability ClassifierID    HectorFileType  LibmagicFileType
/mnt/Hector/Data/benign/binary/benign-pete/ 01d0cd964020a1f498c601f9801742c1    19  S040PDFv02  data.pdf    PDF document
/mnt/Hector/Data/benign/binary/benign-pete/ 0299a1771587043b232f760cbedbb5b7    0   S040PDFv02  data.pdf    PDF document
/mnt/Hector/Data/benign/binary/benign-pete/ 02a3f29050abd76f8d5dbe5972dff932    0   S040PDFv02  data.pdf    PDF document
/mnt/Hector/Data/benign/binary/benign-pete/ 068e56e175dc41a91ab0a34b4729200d    0   S040PDFv02  data.pdf    PDF document
/mnt/Hector/Data/benign/binary/benign-pete/ 07812135184347a9a2c772665e14d5b2    10  S040PDFv02  data.pdf    PDF document

感谢您的帮助

4

1 回答 1

1

使用 bash 的select命令来简化菜单:

echo "-----------------------------"
echo "   Data Processing Menu      "
echo "-----------------------------"

choices=(
    "Enter Number $Number of Files $FileName to output.txt"
    "Show Classifiers only"
    "Auto All $All of Files $AllFileName to output.txt"
    "Exit/Abort"
)
PS3="Enter your choice: "

select Pmenu in "${choices[@]}"; do
    case $Pmenu in
        1) "Building"; break ;;
        2) cut -f 4 input.txt; break ;;
        3) "Building"; break ;;
        4) exit 0;;
    esac
done

我不清楚 1 和 3 需要什么帮助。

于 2013-08-21T15:08:07.813 回答