shell命令单行和多行注释

单行注释

# echo "hello world"

多行注释

#!/bin/bash
# author: lne
# url: lne.cc

echo "hello world"

# v1
: '
echo "hello world"
echo 'hello world'
echo `ls -l; mkdir 1`
'
# v2
:<<"eof"
echo "hello world"
echo 'hello world'
echo `ls -l; mkdir 1`
eof

# v3
:<<'!'
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
!false
!

# v4
:<<\EOF
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
EOF

# v5 注释中不能有单独"}", 包含可导致语法错误
((0)) && {
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
}

# v5 注释中不能有单独"}", 包含可导致语法错误
false && {
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
}

# v6 注释中不能有单独"fi", 包含可导致语法错误
if false; then
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
fi

# v7 注释中不能有单独"done", 包含可意外结束循环
while false; do
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
done

# v8 注释中不能有单独"done", 包含可意外结束循环
while :; do
break
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
done

# v9 注释中不能有单独"done", 包含可意外结束循环
for false; do
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
done

# v10 注释中不能有单独"done", 包含可意外结束循环
for ((;;)); do
break
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
done

# v11 注释中不能有单独"done", 包含可意外结束循环
until true; do
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
done

# v12 注释中不能有单独"done", 包含可意外结束循环
until :; do
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
done

# v13 注释中不能有单独"EOF", 包含可意外结束循环
<<"EOF"
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
EOF

# v14 将注释放到函数中
function comment() {
echo "hello world!"
echo 'hello world'
echo `ls -l; mkdir 1`
}


发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据