我最近开始研究shell脚本,我希望能够在shell脚本中注释出一组行。我的意思是,就像在C/Java的情况下:
/* comment1
comment2
comment3
*/`
我怎么能那样做呢?
我最近开始研究shell脚本,我希望能够在shell脚本中注释出一组行。我的意思是,就像在C/Java的情况下:
/* comment1
comment2
comment3
*/`
我怎么能那样做呢?
当前回答
在阅读了其他答案后,我想出了以下答案,恕我直言,这是一个评论。特别适合脚本内使用信息:
<< ////
Usage:
This script launches a spaceship to the moon. It's doing so by
leveraging the power of the Fifth Element, AKA Leeloo.
Will only work if you're Bruce Willis or a relative of Milla Jovovich.
////
作为一名程序员,斜杠的序列会立即在我的大脑中注册为注释(尽管斜杠通常用于行注释)。
当然,“////”只是一个字符串;前缀和后缀中的斜杠个数必须相等。
其他回答
使用:'打开'和'关闭。
例如:
: '
This is a
very neat comment
in bash
'
直白地说 注释掉 一段代码 我做
: | | { 块 的代码 }
bash中的多行注释
: <<'END_COMMENT'
This is a heredoc (<<) redirected to a NOP command (:).
The single quotes around END_COMMENT are important,
because it disables variable resolving and command resolving
within these lines. Without the single-quotes around END_COMMENT,
the following two $() `` commands would get executed:
$(gibberish command)
`rm -fr mydir`
comment1
comment2
comment3
END_COMMENT
你对此有什么看法?
function giveitauniquename()
{
so this is a comment
echo "there's no need to further escape apostrophes/etc if you are commenting your code this way"
the drawback is it will be stored in memory as a function as long as your script runs unless you explicitly unset it
only valid-ish bash allowed inside for instance these would not work without the "pound" signs:
1, for #((
2, this #wouldn't work either
function giveitadifferentuniquename()
{
echo nestable
}
}
我尝试了选择的答案,但发现当我运行一个shell脚本时,整个事情都打印到屏幕上(类似于jupyter笔记本如何打印出“xx”引号中的所有内容),并在结束时出现错误消息。它什么都没做,但是很吓人。后来我在编辑的时候意识到单引号可以跨越多行。所以. .让我们把这个块赋值给一个变量。
x='
echo "these lines will all become comments."
echo "just make sure you don_t use single-quotes!"
ls -l
date
'