开发者

ask about the meaning of a bash script

开发者 https://www.devze.com 2023-04-13 05:17 出处:网络
I have a shell script application.sh, as follows. 开发者_高级运维#! /bin/busybox sh set -o nounset -o errexit

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 cats 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号