我的要求是根据显示的内容删除文件。以下是我列出文件的代码片段,但是当我选择选项时它会显示文件,当我捕获文件名时,它不会发生,只有获取键不是VALUE($ REPLY只显示键但不显示值)。有人可以帮助我。
#!/bin/bash
select list in $(ls *.tmp)
do
echo $list
echo Do you want to delete files ?
read userInput
echo "UserInput is :: " $userInput
echo "Reply is :: " $REPLY
if [ $userInput == $REPLY ] ; then
# rm $REPLY
echo 'Yes'
break
done
---- ----- OUTPUT
1) +~JF1905393034413613060.tmp
2) +~JF2032005334435574091.tmp
3) +~JF3116454937363220082.tmp
4) +~JF3334986634800781310.tmp
5) +~JF3651229840772890748.tmp
6) +~JF3882306323060007639.tmp
7) +~JF573641658479505435.tmp
8) +~JF6137053351660236007.tmp
9) +~JF6277682393160684532.tmp
10) +~JF6385610668752278364.tmp
11) +~JF6824954027739238354.tmp
12) +~JF7876557427734797684.tmp
#? 4
+~JF3334986634800781310.tmp
Do you want to delete files ?
y
UserInput is :: y
Reply is :: 4
No
答案 0 :(得分:0)
试试这个:
PS3="Pick a file number to delete (or Ctrl-C to quit): "
select f in *.tmp ; do echo rm "$f" ; done
然后删除echo
以使其实际删除文件。