I need to write a small bash script that determines if a string is valid for bash variable naming rules. My script takes the variable name as an argument. I am trying to pass this argument to the grep command with my regular expression, but all I tried is grep trying to open the value passed as a file.
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"
and both times grep tries to open it as a file. Is there a way to pass a variable to grep?
source share