I'm told to run this command on terminal:

sudo env PATH=$PATH:/usr/local/bin /usr/local/lib/node_modules/pm2/bin/pm2 unstartup launchd -u dora --hp /Users/dora

It seems like it's multiple commands in one line:

sudo env PATH=$PATH:/usr/local/bin

/usr/local/lib/node_modules/pm2/bin/pm2 unstartup launchd -u dora --hp /Users/dora

But, how does that work? I know A;B, A&&B, A||B, but this looks like A B.

1 Answer 1


It indeed are multiple commands which get run here. If you look up man env you'll find

    env [-iv] [-P altpath] [-S string] [-u name] [name=value ...] [utility [argument ...]]

which explains that env does, among other things,

  • assign values to variables (the [name=value ...] bit which in your case is PATH=$PATH:/usr/local/bin /usr/local/lib/node_modules/pm2/bin/pm2)
  • and then runs another program passed as an argument (the [utility [argument ...]] bit, in your case the call to npm).

The intention here is to extend the search PATH of the command run through sudo in order to have npm find all the executables it needs.

This is purely a feature of env, other commands like sudo or xargs have similar capabilities. OTOH A;B, A && B or A || B are shell features.

  • That makes sense! I was using sudo all along and didn't notice that it was actually taking an extra command. Thanks @nohillside
    – Vincent
    Nov 27, 2019 at 14:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .