2
0
I have a string in my shell script which is in a fixed format : '[STATUS REPORT] PROJECT'
.
When user executes my shell script he will be asked to provide a value for 'PROJECT'
.
I would like to replace the word 'PROJECT'
with the user provide value. For Eg if 'ABCD'
was user input:
'[STATUS REPORT] ABCD'
I have two issues: 1: How to tackle special characters like '&' in a project name? For eg:
echo "[STATUS REPORT] PROJECT" | awk '{ gsub(/PROJECT/, "A&A"); print }'
and I get the following output:
[STATUS REPORT] APROJECTA
2: My actual shell statement looks like this:
echo "[STATUS REPORT] PROJECT" | awk '{ gsub(/PROJECT/, $ProjectName); print }'
where $ProjectName stores the project name provided by user. But this doesn't seem to work
How can I get this working properly?
1To be pedantic, this is not true: "
&
is a special char in regular expressions" --&
is special in the replacement string of thesub
andgsub
commands. – glenn jackman – 2011-08-10T10:24:10.947@glenn: true, I updated the answer. – jfg956 – 2011-08-10T10:59:00.513