In the following script
#!/bin/bash
shopt -s globstar
set -e
fwd_slsh='/'
space=' '
ampersands='&&'
bang='!'
opnbrc='['
clsbrc=']'
caret='^'
prefix=${bang}${fwd_slsh}${opnbrc}${caret}
suffix=${clsbrc}${fwd_slsh}
echo $prefix
echo $suffix
the resultant output is as shown below:
!/^
/
The resulting echo output omits the '[' and the ']'.
What is the change required to the above script so that both '[' and ']' are included in the echo outputs? Just wanted to reiterate that I would want to retain the above convention if possible, that is, include both the '[' and ']' as part of the variables as shown above.
My intention is to use the variables prefix
and suffix
in awk commands, along with other variables input by the user during runtime.
Appreciate your thoughts.
TIA
Vinod
prefix="${bang}${fwd_slsh}${opnbrc}${caret}"
- i.e. add quotes? – Jaromanda X May 17 '23 at 04:36opnbrc='\['
– jsotola May 17 '23 at 04:49bash -x ./that-script
which might give you a clue. In any case you forgot the quotes around the expansions inecho $prefix
andecho $suffix
and rememberecho
can't be used to output arbitrary data. More on that at When is double-quoting necessary? and Why is printf better than echo? – Stéphane Chazelas May 17 '23 at 04:59