help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] FUNCNAME[0]: unbound variable


From: Paolo Supino
Subject: [Help-bash] FUNCNAME[0]: unbound variable
Date: Sun, 8 Mar 2015 17:03:55 +0100

Hi

While write scripts I usually set my PS4 to: '+(${BASH_SOURCE##*/}:${LINENO}):
${FUNCNAME[0]}($?):' to have nice printout of what my script does when it
executes. I've read in a blog post that it's good habit to: "set -o
nounset" and "set -o errexit" , so I started adding them to my scripts, but
the combination of my PS4 + 'set -o nounset' aborts the script immediately
with the error: "FUNCNAME[0]: unbound variable".

The BASH manual page explains it pretty clearly:
*FUNCNAME*
An array variable containing the names of all shell functions currently in
the execution call stack. The element with index 0 is the name of any
currently-executing shell function. The bottom-most element is "main".
This variable exists only when a shell function is executing. Assignments
to FUNCNAME have no effect and return an error status. If FUNCNAME is
unset, it loses its special properties, even if it is subsequently reset.

My question is there a way to combine the use of FUNCNAME and 'set -o
nounset'?




TIA
Paolo


reply via email to

[Prev in Thread] Current Thread [Next in Thread]