pepero
pepero

Reputation: 7513

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.

Upvotes: 1

Views: 174

Answers (3)

Alexander Pogrebnyak
Alexander Pogrebnyak

Reputation: 45616

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.

Upvotes: 0

glglgl
glglgl

Reputation: 91159

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.

Upvotes: 1

trojanfoe
trojanfoe

Reputation: 122468

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.

Upvotes: 4

Related Questions