1

I have a bash script like this:

#!/bin/bash

cd ~/src/program && rm -rf node_modules && yarn

When I invoke this script by executing (shell-command "bash ~/src/helper/script.sh") it stumbles on yarn and returns exit code 127. Also, it successfully executes every command before yarn.

I also tried yarn install, bash -c "yarn install" with no avail.

When I run the script from emacs shell buffer or from an external bash, it executes successfully. I also made the script executable, but it didn't help.

How to easily run a bash script or an emacs function from an Org Mode file to remove a directory and invoke yarn install to populate that directory?

1 Answer 1

1

This sounds like a problem with environment variables where your interactive bash session has a different PATH than your emacs session. In your interactive bash session (where yarn is working), try the following:

which yarn
echo $PATH

Then, inside emacs, start an elisp repl via M-x ielm, and try this:

(getenv "PATH")

You may notice that the path for yarn is missing for emacs. There are a few ways to fix this, but the most direct way may be to use setenv to add the missing path to PATH.

(setenv "PATH" (concat (getenv "PATH") ":/path/for/yarn/bin"))

Of course, replace ":/path/for/yarn/bin" with a path that's appropriate for your own system.

If you need more environment variables, you might be interested in this answer to another environment-related question. https://emacs.stackexchange.com/a/73665/37580

2
  • 1
    It works, thank you! Also, thank you for introducing the Elisp REPL to me! Now I am confused how to exit it. :-) Oct 15, 2022 at 16:35
  • 1
    You can just kill the ielm buffer using C-x k.
    – g-gundam
    Oct 15, 2022 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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