When editing a remote file with tramp, I want org-babel source blocks to source the remote machine's .bashrc.

I found this workaround that does what I want:

#+BEGIN_SRC bash :preamble ". ~/.bashrc"
echo $PATH

I can save a bit of typing by adding this to the top of the file, so it applies to all bash blocks in the file:

:HEADER-ARGS:bash: :prologue ". ~/.bashrc"

However, what I really want is for the combination of tramp + org-babel to treat a shell source block as if I've started bash interactively on the remote machine.

Is there a way to configure this as the default, or is my hacky solution the best/only way to achieve my goal?

I tried the following suggestions, with no noticeable effect:


Based on one of the comments, I also tried adding this to my init file:

(add-to-list 'tramp-connection-properties
             (list (regexp-quote "/sshx:ibp2-admin:")
                   "remote-shell" "/bin/bash"
                   "sh-extra-args" "-l -i"))

This makes the remote shell /bin/bash instead of /bin/sh, but did not source the ~/.bashrc file.

  • The first two links are identical.
    – NickD
    Sep 4 at 21:12
  • Do C-h i g(tramp)Remote shell setup hints. It mentions that tramp-shell-extra-args are applied, so you might want to try adding -i to that.
    – NickD
    Sep 4 at 21:13
  • @NickD thanks, I gave it a try and was able to change the remote shell, but adding -i or -l seems to have no effect. Sep 5 at 15:35
  • D'oh - the variable is called tramp-sh-extra-args. Still untested, so I don't know if it'll work or not (you may have tried it already if you read the doc, rather than going by my erroneous comment), but a variable that is used by somebody has a better chance of working !-)
    – NickD
    Sep 6 at 1:44
  • You're right, the variable is tramp-sh-extra-args. According to the Tramp manual 4.14, setting a property using tramp-connection-properties prepends "tramp-" to the property name. To be thorough, I also tried using tramp-sh-extra-args instead, with no noticeable effect. Sep 6 at 14:41

Your Answer

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

Browse other questions tagged or ask your own question.