Replies: 3 comments
-
You can't have script lines without a $, at best they won't do anything.
So if you want to run a sequence of commands, either create a shell
script with a hashbang and call it like:
$ myscript.sh
Or use a [heredoc
format](https://bunchapp.co/docs/bunch-files/scripts/shell-scripts/#heredoc):
$```
#!/bin/sh
...
```
However, it seems to me that all your problems could be solved by just
providing a full path the the pm2 binary. Do you actually need to load
an environment for the command to work?
…-Brett
On 17 Feb 2024, at 17:24, Laurence Cope wrote:
Please can somoene share a working bunch example of how to get shell
scripts to work? I just cant get it to work!!
I have a Macbook 2020 13". Its zsh shell, althoughthen I have tried
sh and bash.
I would like to run a Node server, which I call using NPM which I also
run in PM2 so its in the background. So for example, this script works
fine in my own terminal as my user:
`pm2 start 'npm run dev --prefix /path/to/my/app'`
But in Bunch I get a "/bin/sh: pm2: command not found"
So I followed the instructions to load the paths to node. npm and pm2
but I still get the same message. In my Bunch files I have tried
these:
```
---
title: My Title
---
#!/bin/sh
source "$HOME/.profile"
$ pm2 start 'npm run dev --prefix /path/to/my/app'
```
```
---
title: My Title
---
#!/bin/zsh
source "$HOME/.zshenv"
$ pm2 start 'npm run dev --prefix /path/to/my/app'
```
```
---
title: My Title
---
#!/bin/bash
source "$HOME/.profile"
$ pm2 start 'npm run dev --prefix /path/to/my/app'
```
I also tried adding the dollar in front of the first two:
```
---
title: My Title
---
$ #!/bin/bash
$ source "$HOME/.profile"
$ pm2 start 'npm run dev --prefix /path/to/my/app'
```
or just all but not the first:
```
---
title: My Title
---
#!/bin/bash
$ source "$HOME/.profile"
$ pm2 start 'npm run dev --prefix /path/to/my/app'
```
My .profile and .zshenv files have this:
```
export PATH=~/.nvm/versions/node/v18.16.1/bin/npm:$PATH
export PATH=~/.nvm/versions/node/v18.16.1/bin/node:$PATH
export PATH=~/.nvm/versions/node/v18.16.1/bin/pm2:$PATH
```
if I run $ echo $PATH in a Bunch file it does echo the above as the
path, but I get the same error, PM2 command not found, every time.
Its the right path to the scripts, they all work when called., e.g.
this works fine:
`~/.nvm/versions/node/v18.16.1/bin/pm2`
Thanks!!!!
But I just can't
#!/bin/zsh
source "$HOME/.zshenv"
--
Reply to this email directly or view it on GitHub:
#324
You are receiving this because you are subscribed to this thread.
Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply. If I put the full pm2 path it says it can't find node then. I was hoping to not have to put full paths in the scripts. If I can get it working I'll probably have a lot more scripts for my workflows. I was also hoping to keep just one file for it all and not have multiple files for one workflow. But it's a last resort I guess. I'll try the heredoc approach. Thanks |
Beta Was this translation helpful? Give feedback.
-
Ahhh I got it working! Does not look like I can add paths to pm2, node, npm direct, just could not get it to work. But calling this line loads NVM:
This is actually in the .zshrc file and looks like I was calling the wrong zsh file above. I was sourcing .zshenv. So now I source .zshrc and it loads the above NVM line its working OK! Thanks |
Beta Was this translation helpful? Give feedback.
-
Please can somoene share a working bunch example of how to get shell scripts to work? I just cant get it to work!!
I have a Macbook 2020 13". Its zsh shell, although then I have tried sh and bash.
I would like to run a Node server, which I call using NPM which I also run in PM2 so its in the background. So for example, this script works fine in my own terminal as my user:
pm2 start 'npm run dev --prefix /path/to/my/app'
But in Bunch I get a "/bin/sh: pm2: command not found"
So I followed the instructions to load the paths to node, npm and pm2 but I still get the same message. In my Bunch files I have tried these:
I also tried adding the dollar in front of the first two:
or just all but not the first:
I also added #!/bin/bash to the very top above title (the instructions said add it to the top) but I get an error because it looks like it tries to open ----- and the title as an app, so i guess that's wrong.
My .profile and .zshenv files have this:
if I run $ echo $PATH in a Bunch file it does echo the above as the path, but I get the same error, PM2 command not found, every time.
Its the right path to the scripts, they all work when called., e.g. this works fine:
~/.nvm/versions/node/v18.16.1/bin/pm2
Thanks!!!!
Beta Was this translation helpful? Give feedback.
All reactions