是否有一种简单的方法来注释掉shell脚本中的代码块?
当前回答
你可以使用:
if [ 1 -eq 0 ]; then
echo "The code that you want commented out goes here."
echo "This echo statement will not be called."
fi
其他回答
在一个:
去你想评论的第一行 shift-V(进入可视模式),向上向下突出块中的行 执行以下选择:s/^/#/ 命令如下所示: : <、>年代/ ^ / # 回车
e.g.
shift-V
jjj
:s/^/#
<enter>
你可以使用:
if [ 1 -eq 0 ]; then
echo "The code that you want commented out goes here."
echo "This echo statement will not be called."
fi
shell脚本上没有块注释。
使用vi(是的,vi),您可以轻松地从第n行注释到第m行
<ESC>
:10,100s/^/#/
(从第10行到第100行,用#符号代替第(^)行。)
联合国的评论是
<ESC>
:10,100s/^#//
(从第10行到第100行,替换行开始(^),后面跟着#,并注明//。)
Vi几乎在任何有/bin/sh的地方都是通用的。
我喜欢单线开闭:
if [ ]; then ##
...
...
fi; ##
“##”可以帮助我轻松地找到块注释的开始和结束。我可以在“##”后面加上一个数字,如果我有很多的话。要关闭注释,我只需在“[]”中插入一个“1”。我还避免了在注释块中使用单引号时遇到的一些问题。
在vscode中ctrl+K+C (ctrl+K+U取消注释)。