spread a one-line command over multiple lines
July 11th, 2007 by Lawrence David
to spread a one-line command over multiple lines in a shell script, end each line with a slash and indent the next line. for instance:
cat $1 | sed ‘s/>FALF/F_FAL/g’Â \
| sed ‘s/>FAL1/1_FAL/g’Â \
| sed ‘s/>FAL5/5_FAL/g’Â \
| sed ‘s/>FALZ/Z_FAL/g’Â \
| sed ‘s/>OUTGROUP/5_OUTGROUP/’ > $2
That’s a good tip, but the example you used (sed) can be better written as:
sed “s/>FALF/F_FAL/g
s/>FAL1/1_FAL/g
s/>FAL5/5_FAL/g
s/>FALZ/Z_FAL/g
s/>OUTGROUP/5_OUTGROUP/” $1 > $2
Saves five processes. This doesn’t change your original meaning that you can spread multiple commands over several lines, but sed can take multiple directives in a single program.