我想知道我是否可以在 POSIX shell 脚本的函数名和其主体之间使用注释?这似乎在 shellcheck 中不会引发任何问题,并且在 Dash/Bash 中运行,但是搜索这些信息却没有任何用处。
shell 函数示例:
is_int()
# POSIX [bool] function to test one variable for an integer.
{
case "${1#[+-]}" in
(*[!0123456789]*) return 1 ;;
('') return 1 ;;
(*) return 0 ;;
esac
}
is_uint()
# POSIX [bool] function to test one variable for an unsigned integer.
{
case "$1" in
([+-]*) return 1 ;;
esac
is_int "$1"
}
有哪个shell知道这个问题吗?我不希望它损害我的某些脚本的可移植性。
注意,我最近才使用它,因为我开始使用的 VS Codium 支持像这样折叠的功能块:
谢谢。
附言:我更喜欢在我的 Shell 脚本中这样使用注释来描述函数,而不是在f()
函数名上方添加注释。这只是一个外观问题,因此请不要讨论函数名上方的“为什么不”。谢谢!