ask about the meaning of a bash script
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.
The <<
is the heredoc construct and cat
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:
application.sh [-d]
-d :debug
You are missing the trailing }
by the way.
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.
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.
精彩评论