Please consider the following org-mode snippet containing code to call "show tables" on a particular database via a sql code block and to dump out the database via mysqldump using an sh code block

*** Database
:header-args: :engine "mysql" :dbuser "user" :dbpassword "password" :dbhost "" :database "mydb" :var dbuser="user" :var dbpassword="password" :var dbhost="" :var database="mydb"

**** Test connectivity
#+begin_src sql
show tables;


**** Dump schema
#+begin_src sh 
echo mysqldump -u $dbuser -p $dbpassword -h $dbhost $database

: mysqldump -u user^M^M -p password^M^M -h^M^M mydb

You will note that the line that is echoed contains spurious whitespace (line ends by the look of it).

Why is this and how can I make it go away?

If I remove the echo from the sh code block then I get the following error:

mysqldump: Got error: 2005: "Unknown MySQL server host '^M^M' (8)" when trying to connect

So the whitespace is really there. I am running GNU Emacs (x86_64-w64-mingw32) of 2016-05-26 on Windows 10. So it might be a Windows problem - haven't tried it on Linux yet, will do that when I get home from work.

For bonus marks, can someone tell me how to refactor the header_args so that I don't have to declare everything twice (once for SQL language specific headers and once for code block variables)?

Let me know what additional information I should provide as this is my first post.

  • The problem isn't there on emacs 24.5.1 on linux. – JeanPierre Aug 25 '16 at 12:25
  • Thanks for checking. This is happening for me on every header-arg referenced from an sh code block - it's making it difficult to use code blocks effectively. – Matt Innes Aug 26 '16 at 8:21

Ok, after much banging my head on this, I think I've worked it out. The spurious ^M characters are not as such caused by Emacs specifically but by any Windows program interacting with the Cygwin bash shell (which I am using).

Putting the following into ~/.emacs will tell bash to ignore spurious carriage returns and all my problems go away:

(setenv "SHELLOPTS" "igncr")
| improve this answer | |

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.