I Z
I Z

Reputation: 5927

How to prevent bash script from putting all output into one line?

I have the following bash script top_script.sh

#!/bin/bash
# "Usage: $0 JOBNAME LOGFILE"
JOBNAME=$1
LOGFILE=$2
JOB_OUTPUT=$($1 2>&1)
echo ${JOB_OUTPUT} >> "${LOGFILE}"

that is supposed to be invoked like this

top_script.sh script_to_run.sh log.txt

If script_to_run.sh has multiple echo statements, e.g.

echo Line 1 from $0
echo Line 2 from $0

then what I get in log.txt is

Line 1 from script_to_run.sh Line 2 from script_to_run.sh

i.e. all this output gets concatenated into a single line. I suspect that the reason is line #5 in the first code block above. How can I modify it to ensure separate echos print into separate lines in log.txt?

Not that it really matters, but in case you are wondering, top_script.sh gets generated automatically form some a config file.

Upvotes: 1

Views: 64

Answers (1)

R Sahu
R Sahu

Reputation: 206667

echo "${JOB_OUTPUT}" >> "${LOGFILE}"

Upvotes: 2

Related Questions