0

I am querying a database from a bash script using following query:-

Output = echo "$QUERY_STR" | mysql -h $DB_HOST -u $DB_USER -p$DB_PASS $DB_NAME   

it gives me the required output which I save in a Variable

However when I echo $output I do not get proper formatted output like in command line of mysql query.

Read one of the post to use -t in the query however for large data set it does not give proper output.

To work around it, I am saving the output in a .csv file.

1 Answer 1

3

To maintain all the whitespace that is indeed kept in the variable's value, it is crucial to double-quote the variable:

echo "$output"

Also, you cannot have whitespace around the equal sign in a variable assignment:

output=$(mysql ... <<< "$QUERY_STR")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.