询问bash脚本的含义
我有一个 shell 脚本 application.sh
,如下所示。
#! /bin/busybox sh
set -o nounset -o errexit
readonly emul_script="/usr/local/bin/emul.sh"
readonly profile="/etc/vendor/profile"
source "${profile}"
_usage() {
cat << EOF
${0} [-d]
-d :debug
EOF
上面的脚本启动一个特定的应用程序。我的问题与从_usage
开始的部分有关,我不太明白它的含义,也看不到它是如何使用的。
I have a shell script application.sh
, as follows.
#! /bin/busybox sh
set -o nounset -o errexit
readonly emul_script="/usr/local/bin/emul.sh"
readonly profile="/etc/vendor/profile"
source "${profile}"
_usage() {
cat << EOF
${0} [-d]
-d :debug
EOF
The above script starts a specific application. My question is related to the part starting from _usage
, I do not quite understand what it means and cannot see how it is used.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
<<
是 heredoc构造并cat
将结束标记(在本例中为EOF
)之前的所有内容发送到 stdout。${0}
是输入文件的名称,这将在标准输出中打印类似以下内容:顺便说一下,您缺少尾随的
}
。The
<<
is the heredoc construct andcat
s everything up to the end marker (EOF
in this case) to stdout.The
${0}
is the name of the input file and this will print something like the following to stdout:You are missing the trailing
}
by the way.添加到 trojanfoe 所说的内容中,
_usage()
是一个 shell 函数。但它永远不会被调用,应用程序本身也不会被调用,所以我认为这只是脚本的一部分。
Adding to what trojanfoe says,
_usage()
is a shell function.But it is never called, nor is the application itself called, so I suppse that is only part of a script.
_usage
函数可以从位于其上方的${profile}
脚本调用。请注意,您可能希望将其放在
source
行之前,因为严格来说,它必须在使用之前定义。The
_usage
function might be called from${profile}
script that is sourced just above it.Beware, that you may want to put it before the
source
line, because, strictly speaking, it has to be defined before it is used.