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?

g-gundam
  • 1,096
  • 1
  • 3
  • 13
Evgeny Mikhaylov
  • 179
  • 1
  • 14

1 Answers1

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

g-gundam
  • 1,096
  • 1
  • 3
  • 13