BASH:如何禁止用户input“*”,还有什么样的正则expression式应该检查用户input?

如何禁止用户input“*”

read -p "inputData : " inputData #user input * echo $inputData #here it outputs the current files in the directory... how do we prevent this? 

我应该检查什么样的正则expression式用户input?

这是我到目前为止…

 count=`echo "$1" | grep -q "[\*\.\+\?]" ` 

引用你的变量来防止路径名扩展

 echo "$inputData" 

 $ read -r -p "Gimme input: " ans; echo "You entered >$ans<" Gimme input: * You entered >*< 

或者,您可以通过首先在脚本中运行set -f来关闭通配符

如果你执行其中任何一个,只要你没有通过eval运行它 ,你不需要检查输入中的任何错误