I have SED patterns:
[^a-zA-Z0-9]
/b\./s/.*c\.. \([^ ]*\) .*/\1/p
and so on.
I need to pass these to an echo command as variables.
At the moment, I define the $pattern variable like so:
$pattern="[^a-zA-Z0-9]"
and then pipe it to echo, like so:
echo "$OUTPUT" | sed "s/$pattern/g"
But the code is not passing the pattern, but a command and returns the error
=[^a-zA-Z0-9]: command not found
What's going wrong?
pattern='[^a-zA-Z0-9]'
work better? You're not assigning a variable with$pattern=
. Take a look ateval
as an alternative too... I can make it into a proper answer if it works... – Zip Dec 07 '17 at 16:55[^a-zA-Z0-9]
is a pattern but/b./s/.c.. ([^ ]) .*/\1/p
is a fullsed
script. – Stéphane Chazelas Dec 07 '17 at 17:18bash
expands it as if it were a variable and because there was nothing in$pattern
at that point,bash
saw this:=[^a-zA-Z0-9]
. And what's the next step? Executing the command with that name, thus the error. – PesaThe Dec 07 '17 at 17:57