1

I came across the below sed statement in our shell script.

sed -n "/set -A $REC/,/#${REC}_END/p"

I know that -n option suppresses the automatic printing and p is to display.

Are the contents inside /../ a plain string or another command is being used in the above statement? (set -A)

  • it is just string.. however, the double quotes allow variable substitution (shell functionality, nothing to do with sed).. see https://stackoverflow.com/questions/7680504/sed-substitution-with-bash-variables (one of the links from https://stackoverflow.com/tags/sed/info) – Sundeep Mar 21 '18 at 07:36
  • @Sundeep So the meaning of the above statement is making a string which starts with `set -A $REC` and ends with `#${REC}_END` ? – Sindhu Choudary Mar 21 '18 at 07:41
  • no, it is address range.. see https://www.gnu.org/software/sed/manual/sed.html#Range-Addresses – Sundeep Mar 21 '18 at 07:43

1 Answers1

0

This is an "address range", it tells sed to only print lines between /set -A $REC/ and /#${REC}_END/. Double quotes around the expression expand variables, so $REC will be replaced by the variable value (hopefully, it doesn' t contain a slash) in the first address, and similarly ${REC} in the second one. The curly brackets are needed there, as an underscore is a valid part of a variable name, so $REC_END looks like a variable name, not a variable name followed by a string _END.

choroba
  • 200,498
  • 20
  • 180
  • 248