I am failing to add comments for multi-line statements in bash script. Seems that bash is not interpreting.Since comments can really be useful because there are potential 4-5 lines, can anyone advice me how to achieve this?This is just basic example, which is - not working.#!/bin/bashiptables -A INPUT \#Comment for rule bellow-p tcp --dport 21 \# Comment for rule bellow no2-s 10.0.0.1 \-j ACCEPTI just give a plain example. Allowing comments can be more easier for complex examples (this is not complicated example, but you got a point) like this:grep some_file \#awk does that...awk '{print $1}' \#sed does that...sed 's/match1/match2/g' Of course there are no whitechars behind \.
How to add comments on multiline statements on Bash script?
bash;shell script;shell
A line broken into several lines by escaping the newline is still only one line.A comment stretches from the # to the end of the line, no matter if that line is broken into many lines or not.What the shell parses when you writeecho hello \# worldisecho hello # worldThis is different though (and works):grep hello |# now sed:sed 1pSince each part of the pipeline is complete on its own line, it's possible to intermingle the lines with comments, as long as the newlines are not escaped.