7

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.

3
  • 5
    INSTALL_LOG_OUTPUT being empty is one reason.
    – muru
    Commented Nov 12, 2015 at 12:30
  • There is a syntax error in the second test of the if statement. It should be [ "$argument" == "-automatic" ]; then. It may or may not be related to the reported error. Commented Nov 12, 2015 at 19:38
  • 1
    @muru: You were right. The assignment of the filename for $INSTALL_LOG_OUTPUT was three lines later -.-
    – devopsfun
    Commented Nov 13, 2015 at 7:58

1 Answer 1

11

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .