两个提示 - bash

时间:2013-08-22 17:54:27

标签: bash loops for-loop

我正在尝试提示如下:

script:输入文件名

用户: data.pdf

脚本:输入您想要的 data.pdf 金额

用户: 2

然后它在我的输出文件中输出2 data.pdf的,这是我目前正在尝试的但是它不起作用:

 PROMPT_TEXT='Enter the filename:'
 PROMPT_TEXT='Enter the Number of that files you want outputted'
 read -p "$PROMPT_TEXT" filename
 read -p "$PROMPT_TEXT" amount
 grep -m "$amount" "$filename" input.txt > output.csv
 echo "**Stored Successfully in output.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

谢谢

2 个答案:

答案 0 :(得分:2)

等到你读完文件名后再创建第二个提示:

PROMPT_TEXT='Enter the filename:'
read -p "$PROMPT_TEXT" filename
PROMPT_TEXT="Enter the amount of $filename you want outputted"
read -p "$PROMPT_TEXT" amount
grep -m "$amount" "$filename" input.txt > output.csv
echo "**Stored Successfully in output.txt**"

答案 1 :(得分:2)

你没有说出问题所在。我假设您两次获得相同的提示。您需要将两个提示定义为单独的变量:

PROMPT_TEXT1='Enter the filename:'
PROMPT_TEXT2='Enter the Number of that files you want outputted'
read -p "$PROMPT_TEXT1" filename
read -p "$PROMPT_TEXT2" amount
grep -m "$amount" "$filename" input.txt > output.csv
echo "**Stored Successfully in output.txt**";;

或者,完全取消它们:

read -p "Enter the filename:" filename
read -p "Enter the Number of that files you want outputted:" amount
grep -m "$amount" "$filename" input.txt > output.csv
echo "**Stored Successfully in output.txt**";;