mis*_*ter 2 unix linux bash shell
如何禁止用户输入"*"
read -p "inputData : " inputData
#user input *
echo $inputData
#here it outputs the current files in the directory... how do we prevent this?
Run Code Online (Sandbox Code Playgroud)
我应该检查哪种正则表达式用户输入?
这是我到目前为止所得到的......
count=`echo "$1" | grep -q "[\*\.\+\?]" `
Run Code Online (Sandbox Code Playgroud)
引用您的变量以防止路径名扩展
echo "$inputData"
Run Code Online (Sandbox Code Playgroud)
$ read -r -p "Gimme input: " ans; echo "You entered >$ans<"
Gimme input: *
You entered >*<
Run Code Online (Sandbox Code Playgroud)
或者,您可以先set -f
在脚本中运行来关闭globbing
如果您执行其中任何一项,只要您没有运行它,就不需要检查输入中的任何恶意内容eval