赞
踩
直接在行最前端加上符号 #
即可。具体用法如下所示:
# this is comment test
echo "this is comment test"
:
和追加输入重定向 <<
:<<BLOCK
....注释内容
BLOCK
说明:
<<
)到前面的命令,但是 :
是空命令,所以就相当于注释了。var=`ls -l` # 这个就不会被注释掉,因为有反引号
WORD
和 _a_
也可以:例(1):
:<<WORD
....注释内容
WORD
例(2):
下面的 :<<_a_
和 _a_
代表段注释,可以把中间的代码注释掉,_a_
为 Here Documents 中的定义符号,名称任意,只要前后匹配就行。
for ((i=0; i<10; i++))
do
:<<_a_
if [ ]; then
...
fi
_a_
echo ""
done
常用来作为注释的成对字符有:
EOF
、_a_
、WORD
、BLOCK
、!
备注:
EOF
截止符用作后续输入命令
!
叹号一般作为嵌入内容部分
'
单引号一般用来区分内容
:<<BLOCK'
....注释内容
'BLOCK
:<<'BLOCK
....注释内容
BLOCK'
:<<'
....注释内容
'
:<<\EOF
注释的代码...
EOF
:<<'EOF'
注释的代码...
EOF
:
和 if…then…
语句:
就是什么也不做(do nothing)即空命令,一般用在 if…then… 条件中,用作什么也不做的命令,如下:
if [ -d $DIRECTORY ]; then
:
else
echo 'the directory do not exit !'
fi
扩展知识:
例(1):
cmd<<WORD
any input
file content
WORD
例(2):
cat <<Menu
1.List
2.Help
3.Exit
Menu
:
和单引号 ’
注意:单引号 '
和冒号 :
之间要加空格。
# echo is test
echo "test"
echo "test"
echo "test"
echo "test"
echo "test"
: '
echo "comment"
echo "comment"
echo "comment"
echo "comment"
echo "comment"
echo "comment"
'
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。