gerg wrote:
> Hongyi Zhao <
hongy...@gmail.com> wrote:
>>
>>But there is still not a good solution for this issue.
>>
>>Does we may have a more flexible / graceful solution for this issue?
>>
>
> I don't think there is a graceful solution for this in the bash/ksh script
> language. All computer languages have compromises. In other words, each
> language will do many things well, and some things poorly.
>
> There are a number of things shell scripts do poorly, and multi-line
> comments mixed together with multi-line commands, are one of these things.
>
> I either add a line comment on each line (as your example)
OK, but how? the OP's question is exactly that.
Note that the OP's solution of placing a shell comment immediately after
each line cannot work. As presented, it
1) prevents the line continuation from working (a continuation is explicitly
a line that ends with a backslash followed by a newline), and
2) presents the invoked command with one (or more) additional arguments
(consisting of the octothorpe and the individual "words" that follow it).
For example:
18:22 $ cat comments.sh
# echo a single command line
# expected output: This is a single line
echo This is a single line
# echo a single command line split across two input lines
# expected output: This is a split line that should echo as a single line
echo This is a split line that should \
echo as a single line
# echo a single command line, with comments as per the OP
# expected output: This is a line that should echo on the next line
echo This is a line that should \ # NOT, with a comment
echo on the next line
18:22 $ sh comments.sh
This is a single line
This is a split line that should echo as a single line
This is a line that should # NOT, with a comment
on the next line
> or a multi-line comment just above the multi-line command it explains
> -Greg