在多行命令中的Bash脚本中进行注释 [英] Commenting in a Bash script inside a multiline command
本文介绍了在多行命令中的Bash脚本中进行注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在脚本的以下各行中添加注释?
How can I comment on each line of the following lines from a script?
cat ${MYSQLDUMP} | \
sed '1d' | \
tr ",;" "\n" | \
sed -e 's/[asbi]:[0-9]*[:]*//g' -e '/^[{}]/d' -e 's/""//g' -e '/^"{/d' | \
sed -n -e '/^"/p' -e '/^print_value$/,/^option_id$/p' | \
sed -e '/^option_id/d' -e '/^print_value/d' -e 's/^"\(.*\)"$/\1/' | \
tr "\n" "," | \
sed -e 's/,\([0-9]*-[0-9]*-[0-9]*\)/\n\1/g' -e 's/,$//' | \
sed -e 's/^/"/g' -e 's/$/"/g' -e 's/,/","/g' >> ${CSV}
如果我尝试添加评论,例如:
If I try and add a comment like:
cat ${MYSQLDUMP} | \ # Output MYSQLDUMP File
我得到:
#: not found
可以在这里发表评论吗?
Is it possible to comment here?
推荐答案
这会有一些开销,但是从技术上讲,它确实回答了您的问题:
This will have some overhead, but technically it does answer your question:
echo abc `#Put your comment here` \
def `#Another chance for a comment` \
xyz, etc.
特别是对于管道,有一个干净的解决方案,没有任何开销:
And for pipelines specifically, there is a clean solution with no overhead:
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
请参阅堆栈溢出问题 如何为多行命令添加行注释
See Stack Overflow question How to Put Line Comment for a Multi-line Command.
这篇关于在多行命令中的Bash脚本中进行注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文