Sed error "command a expects \ followed by text"

user3032743 picture user3032743 · May 20, 2016 · Viewed 9.6k times · Source

Here is my script:

openscad $1 -D generate=1 -o $1.csg 2>&1 >/dev/null |
sed 's/ECHO: \"\[LC\] //' |
sed 's/"$//' |
sed '$a;' >./2d_$1

That output:

sed: 1: "$a;": command a expects \ followed by text

Answer

Jonathan Leffler picture Jonathan Leffler · May 21, 2016

Your version of sed is not GNU sed which allows what you use. You need to write:

openscad $1 -D generate=1 -o $1.csg 2>&1 >/dev/null |
sed 's/ECHO: \"\[LC\] //' |
sed 's/"$//' |
sed '$a\
;' >./2d_$1

Also, three copies of sed is a little excessive (to be polite); one suffices:

openscad $1 -D generate=1 -o $1.csg 2>&1 >/dev/null |
sed -e 's/ECHO: \"\[LC\] //' \
    -e 's/"$//' \
    -e '$a\' \
    -e ';' >./2d_$1

or:

openscad $1 -D generate=1 -o $1.csg 2>&1 >/dev/null |
sed -e 's/ECHO: \"\[LC\] //' -e 's/"$//' -e '$a\' -e ';' >./2d_$1