How to resolve this "ambiguous redirect"

48,953

Put quotes around INSTALL_LOG_OUTPUT in your function, like this:

function install_log() {
    echo "$1" >> "$INSTALL_LOG_OUTPUT" 2>&1
}

After running your script again, you will probably get an error message indicating that INSTALL_LOG_OUTPUT is empty, with a message of this sort: bash: : No such file or directory.

Share:
48,953

Related videos on Youtube

devopsfun
Author by

devopsfun

Updated on September 18, 2022

Comments

  • devopsfun
    devopsfun over 1 year

    I have a script with a function in it:

    function install_log() {
        echo "$1" >> $INSTALL_LOG_OUTPUT 2>&1
    }
    

    This function is working as it should. It is a function to write something into a log file.

    I added some other commands to the script, for reading the given parameters of the script:

    AUTOMATIC_INSTALL=
    
    for argument in "$@"
    do
        install_log "-> parameter $argument"
        if [ "$argument" == "--automatic" ] || ["$argument" == "-automatic" ]; then
            AUTOMATIC_INSTALL=True
        fi
    done
    install_log "# AUTOMATIC_INSTALL: $AUTOMATIC_INSTALL"
    

    But with the new lines, I get some non needed messages:

    $INSTALL_LOG_OUTPUT: ambiguous redirect
    

    I found out, that this comes from the two lines

    install_log "-> parameter $argument"
    # ...
    install_log "# AUTOMATIC_INSTALL: $AUTOMATIC_INSTALL"
    

    Does anyone know, why the messages are occurring.