here is the script that I am trying to run
#!/bin/bash
charlist=$1 #possible input:cat
wordlength=$2 #possible input: 3
cat ./nounlist | egrep \\b[${charlist}]
You need to wrap the argument in double-quotes so that Bash doesn't try to handle the backslashes, and move the second \b
to after the {${wordlength}}
:
cat ./nounlist | egrep "\b[${charlist}]{${wordlength}}\b"
(If you run echo \b
, you'll see that it just prints b
. This is because Bash assumes that the \
is there to prevent b
from having any special meaning; so it removes it.)