1

I have this line in my script:

mysqlinsert=$(/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot --password=notmyrealpassword << EOF
$mysqlrun)

Despite what it returns, the variable $mysqlinsert is always empty. I tried using -n (disables output buffering) for mysql and putting EOF after $mysqlrun but neither worked.

  • the usual suspects would be: (1) there was no output, and/or (2) the output went to stderr instead of stdout. During the script's execution, did any mysql output accumulate to your screen? – Jeff Schaller Mar 29 at 18:45
  • Another option would be that the current user could not execute /Applications/MAMP/Library/bin/mysql, resulting in yet more stderr and an empty variable. – Jeff Schaller Mar 29 at 18:46
  • @JeffSchaller, yes I see the output on my screen. It's likely that the output went to stderr, which I tried to change with 2>&1, it didn't work (but I may have placed this redirect in the wrong place? I put it after $mysqlrun) – DisplayName Mar 29 at 18:49
2

If the command is sending the output you want to stderr, then redirect the command's stderr inside the command substitution:

mysqlinsert=$(/Applications/MAMP/Library/bin/mysql ... 2>&1 << EOF ...)
#
#                                                     /\______addition____

... where I've elided some parameters to focus on the change I'm suggesting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.