Shell script output/logging question

I have a shell script that does a lot of work and pretty close to the top I have this:

if [[ -r "${SCRIPT_BASE_DIR}/etc/" ]] && 
        [[ -s "${SCRIPT_BASE_DIR}/etc/" ]]; then
    source "${SCRIPT_BASE_DIR}/etc/"
if [[ -r "/usr/local/lib/" ]] && 
        [[ -s "/usr/local/lib/" ]] && 
        [[ -n "${LOGGING_LOADED}" ]] && 
        [[ "${LOGGING_LOADED}" == "${_TRUE}" ]]; then
    source "/usr/local/lib/"
if [[ -z "$(command -v "writeLogEntry")" ]]; then
    printf "e[00;31m%se[00;32mn" "Failed to load logging configuration. No logging available!" >&2

Here ${_TRUE} is true and ${_FALSE} is false.

Also note that in the logging script, I have the ability to independently enable tracing/verbosity just for the log function:

if [[ -n "${ENABLE_LOGGER_VERBOSE}" ]] && 
    [[ "${ENABLE_LOGGER_VERBOSE}" == "${_TRUE}" ]]; then 
     set -x; 
if [[ -n "${ENABLE_LOGGER_TRACE}" ]] && 
    [[ "${ENABLE_LOGGER_TRACE}" == "${_TRUE}" ]]; then 
     set -v; 

And an example of how it’s being called/utilized:

Debug/trace output expected:

if [[ -n "${ENABLE_VERBOSE}" ]] && 
    [[ "${ENABLE_VERBOSE}" == "${_TRUE}" ]]; then 
      set -x;
if [[ -n "${ENABLE_TRACE}" ]] && 
    [[ "${ENABLE_TRACE}" == "${_TRUE}" ]]; then 
     set -v;

Normal log entry:

writeLogEntry "STDERR" "${CNAME}" "${METHOD_NAME}" "${LINENO}" 
   "Unable to read configuration file ${CONFIG_FILE_LOCATION}. Please ensure the file exists and is readable." 2>/dev/null;

Note that the 2>/dev/null is there in case the function isn’t loaded for whatever reason.

The goal here is that we source in a logging script (source ->, related configuration file -> and then do some stuff based on that logging. The problem I’m having is that when $ENABLE_VERBOSE and $ENABLE_TRACE are set to true, ONLY the output from the sourced function is printed. None of the output from the actual shell script I want it from.

I’m not sure if I’ve got enough here to render an opinion, if not please let me know and I will add as much as necessary.

Asked By: Kevin Huntly


So, not sure what I did (or didn’t do?) but this has resolved itself.

Thanks everyone!

Answered By: Kevin Huntly
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.