Bartosz Kaczyński <bkaczyn...@posteo.net> writes: > Hello TRAMP users,
Hi Bartosz, > I am using TRAMP to connect to a remote system over SSH and execute > shell commands with sudo. However, the shell environment on the remote > system does not load certain environment variables (specifically those > defined in ~/.bashrc), which causes commands like systemctl --user > daemon-reload to fail. > > My ~/.bashrc file in the serviceuser homedir: > > export XDG_RUNTIME_DIR=/run/user/$(id -u) > > Here is the Org-mode block I am trying to execute: > > #+begin_src shell :dir /ssh:user@remotesrv|sudo:serviceuser@remotesrv: > systemctl --user daemon-reload > #+end_src > > To work around this, I have tried forcing the remote shell to be > interactive by modifying the TRAMP settings: > > (custom-set-variables > '(tramp-encoding-shell "/bin/bash") > > (add-to-list 'tramp-connection-properties > (list ".*" > "remote-shell" "/bin/bash" > "remote-shell-args" '("-i" "-c"))) "remote-shell-args" is not used in shell-command, if I read the code correctly. You might try to modify tramp-sh-extra-args. > I also tried sourcing ~/.bashrc explicitly in the Org-mode shell block, > which works, but I'd prefer to have the environment variables set > automatically without this extra step. Yes, that's working just now. > I’m wondering if this issue is related to the way TRAMP handles shell > sessions or if it might be specific to how Org-mode executes code > blocks. Do you have any advice on how I might ensure that environment > variables like XDG_RUNTIME_DIR are automatically loaded when executing > commands in Org-mode shell blocks via TRAMP? Hmm, I don't know org-mode good enough. If you find a way to modify tramp-remote-process-environment in time, it might help. > Any guidance or suggestions would be greatly appreciated. > > Thank you for your time! > > bartk Best regards, Michael.