I don't understand how the source code blocks work exactly.

There are some variables, definitions and aliases in my .bashrc that I think I should be able to use in the source code blocks. However, when I run something like the following, the output suggests that my .bashrc is not being run.

#+BEGIN_SRC bash :results output
echo $0

: bash

Is this expected behaviour? How do I use the things in my bashrc file in source code blocks?

  • from what I understand Emacs will not read your aliases – manandearth Nov 24 '18 at 20:45

You can find out how your code is executed by checking ob-shell.el. As for your particular example, your code is passed to bash as stdin, something like the following

$ echo 'echo $VAR_DEFINED_IN_BASHRC' | bash

It will not work, you need the following instead

$ echo 'echo $VAR_DEFINED_IN_BASHRC' | bash -i

So you need to run bash interactively (-i) to source your .bashrc, your can use :shebang argument, then org will create a script (i.e., executable file) and execute it directly via operation system.

#+BEGIN_SRC sh :shebang #!/bin/bash -i :results output

: 42

In my .bashrc, VAR_DEFINED_IN_BASHRC is set to 42.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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