【发布时间】:2019-03-10 13:45:02
【问题描述】:
环境
系统:Linux Mint 19(基于 Ubuntu 18.04)。
编辑:我使用 Visual Studio Code (official website) 和 ShellCheck 插件来即时检查错误、警告和提示。
ShellCheck
是每个shell脚本编写者必备的工具。
尽管开发人员必须付出巨大的努力才能使其尽可能好,但有时会产生不相关的警告和/或信息。
示例代码,带有此类消息(警告SC2120 + 直接相邻信息SC2119):
示例 shell 脚本 sn-p
am_i_root ()
# expected arguments: none
{
# check if no argument has been passed
[ "$#" -eq 0 ] || print_error_and_exit "am_i_root" "Some arguments have been passed to the function! No arguments expected. Passed: $*"
# check if the user is root
# this will return an exit code of the command itself directly
[ "$(id -u)" -eq 0 ]
}
# check if the user had by any chance run the script with root privileges and if so, quit
am_i_root && print_error_and_exit "am_i_root" "This script should not be run as root! Quitting to shell."
地点:
-
am_i_root正在检查传递的不需要的参数。它的真正目的是不言自明的。 -
print_error_and_exit就像它的名字所说的那样,它或多或少是不言自明的。 -
如果传递了任何参数,我希望函数/脚本打印错误消息并退出。
问题
如何禁用这些消息(仅限本地)?
【问题讨论】:
标签: linux shell shellcheck