我希望能够在一行命令中注释掉一个标志.Bash似乎只有from # till end-of-line
评论.我正在看这样的技巧:
ls -l $([ ] && -F is turned off) -a /etc
Run Code Online (Sandbox Code Playgroud)
它很难看,但总比没有好.有没有更好的办法?
以下似乎有效,但我不确定它是否可移植:
ls -l `# -F is turned off` -a /etc
Run Code Online (Sandbox Code Playgroud)
Raf*_*ino 100
我的首选是:
这将有一些开销,但从技术上讲它确实回答了你的问题
Run Code Online (Sandbox Code Playgroud)echo abc `#put your comment here` \ def `#another chance for a comment` \ xyz etc
特别是对于管道,有一个更清洁的解决方案,没有开销
Run Code Online (Sandbox Code Playgroud)echo abc | # normal comment OK here tr a-z A-Z | # another normal comment OK here sort | # the pipelines are automatically continued uniq # final comment
Dan*_*Dan 56
我发现只复制该行并注释掉原始版本是最简单的(也是最可读的):
#Old version of ls:
#ls -l $([ ] && -F is turned off) -a /etc
ls -l -a /etc
Run Code Online (Sandbox Code Playgroud)
Ign*_*ams 23
$(: ...)
有点不那么难看,但仍然不好.
这是我针对多个管道命令之间的内联注释的解决方案。
未注释代码示例:
#!/bin/sh
cat input.txt \
| grep something \
| sort -r
Run Code Online (Sandbox Code Playgroud)
管道注释的解决方案(使用辅助函数):
#!/bin/sh
pipe_comment() {
cat -
}
cat input.txt \
| pipe_comment "filter down to lines that contain the word: something" \
| grep something \
| pipe_comment "reverse sort what is left" \
| sort -r
Run Code Online (Sandbox Code Playgroud)
或者,如果您愿意,这里是没有帮助函数的相同解决方案,但它有点混乱:
#!/bin/sh
cat input.txt \
| cat - `: filter down to lines that contain the word: something` \
| grep something \
| cat - `: reverse sort what is left` \
| sort -r
Run Code Online (Sandbox Code Playgroud)