1

I want to execute sudo command in org-babel like this:

#+begin_src shell :dir "/sudo::" :cache no
make
sudo make install
#+end_src

It works fine. It use TRAMP /sudo: method.

But I need to execute sudo command relative under current working directory. As following block shows:

#+begin_src shell :dir "/sudo::data/code/quirc" :cache no
make
sudo make install
#+end_src

But it does not work. It is under /root instead of current working directory. So how can I execute sudo command under a specific directory as in org-babel like upper?

EDIT: Might add an advice to change TRAMP sudo method default directory to babel src block's directory? Don't know how to change this in TRAMP code. Have not found any tramp-default-directory related variables.

  • Have you tried with a trailing slash at the end of a path? – DoMiNeLa10 Mar 1 '18 at 10:23
  • With a trailing slash like "/sudo::data/code/quirc/" does not work. – stardiviner Mar 2 '18 at 3:44
1

You must use an absolute local directory path. Like this:

#+begin_src shell :dir "/sudo::/data/code/quirc" :cache no
make
sudo make install
#+end_src

See the leading slash in /data/code/quirc.

Edit: You must recompute the directory for the root shell. Something like this:

#+begin_src shell :dir "/sudo::" :var dir=(expand-file-name "data/code/quirc") :cache no
cd $dir
make
make install
#+end_src
  • What I want to execute under a relative path not absolute path. As my question described. – stardiviner Mar 2 '18 at 3:43
  • /sudo::data/code/quirc means a relative directory under the home dir of user root. And this is /root. – Michael Albinus Mar 2 '18 at 7:43
  • Yeah, I know that. I need to relative directory under current working directory. – stardiviner Mar 2 '18 at 12:29
  • You mean the relative directory under current working directory, but with sudo? – Michael Albinus Mar 3 '18 at 14:39
  • yes. that what I need. – stardiviner Mar 6 '18 at 4:23

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.