【发布时间】:2021-08-03 01:27:40
【问题描述】:
在 bash GNU bash,版本 4.2.46(2)-release (x86_64-redhat-linux-gnu) 或任何稳定版本中,
您可以使用# 或: 发表评论
这2个和用处有什么区别?
我注意到# 注释使整行成为注释,而: 范围/效果仅在到达第一个\n 或; 字符(在给定行中)之前。
[gigauser@someserver ~]$ # this is a # comment; echo this will not print
[gigauser@someserver ~]$ : this is a : comment; echo this will print
this will print
在以下代码中,为什么最后 2 个 cmets 没有按预期工作以将它们视为注释(尽管 :: 在 : 之后有效?
[gigauser@someserver ~]$ #
[gigauser@someserver ~]$ ##
[gigauser@someserver ~]$ ####
[gigauser@someserver ~]$ ####
[gigauser@someserver ~]$ : : : : : : : : : :
[gigauser@someserver ~]$ #
[gigauser@someserver ~]$ # # #
[gigauser@someserver ~]$ ####
[gigauser@someserver ~]$
[gigauser@someserver ~]$ :
[gigauser@someserver ~]$ : :
[gigauser@someserver ~]$ : : : : : : : : : : : : ::::::::
[gigauser@someserver ~]$ : : :::::
[gigauser@someserver ~]$
[gigauser@someserver ~]$
[gigauser@someserver ~]$ ::
-bash: ::: command not found
[gigauser@someserver ~]$ :::::
-bash: :::::: command not found
[gigauser@someserver ~]$
【问题讨论】:
-
您可以使用
:,但它不适用于cmets。#就是为此而设计的 stackoverflow.com/questions/3224878/… -
@micke 那篇文章非常好,但只关注
:(bash null command) 不确定它是否提供了比较。我还发现了这个帖子:shell-tips.com/bash/null-commandBASHNULL COMMAND -
是的,我的意思是强调这一点,当然可以使用
:发表评论。这不是它的目的,一个坏主意,反对所有和任何风格指南。见:shell-tips.com/bash/comments/…
标签: linux bash unix command comments