我需要编写一个小的bash脚本来确定一个字符串是否符合bash变量命名规则。我的脚本接受变量名作为参数。我试图将该参数与我的正则表达式一起传递给grep命令,但是无论我尝试了什么,grep都会尝试打开传递的值作为文件。
I tried placing it after the command as such
grep "$regex" "$1"
and also tried passing it as redirected input, both with and without quotes
grep "$regex" <"$1"
每次grep都会尝试将其作为文件打开,有没有办法将变量传递给grep命令?