matryer / xbar

Put the output from any script or program into your macOS Menu Bar (the BitBar reboot)
https://xbarapp.com
MIT License
17.5k stars 642 forks source link

jq: command not found, even though installed on system? #415

Closed reteps closed 7 years ago

reteps commented 7 years ago

my code:

echo -n "E:"; curl -s "https://api.gdax.com/products/ETH-USD/ticker" | jq -r '.bid'
which jq
/usr/local/bin/jq
reteps commented 7 years ago

When I run it from the terminal, it works fine! whats up?

oleander commented 7 years ago

Your environment isn't loaded. You need to run your script using /bin/bash -c ... or /usr/bin/sudo -u you -i a-script.sh.

oleander commented 7 years ago

More info can be found here https://github.com/oleander/bitbar/commit/9792c95805d1abc97d4afc2cdbbc460fc7a66539#commitcomment-22144737

reteps commented 7 years ago

what is the ...? the script?

oleander commented 7 years ago

Yes.

reteps commented 7 years ago

hmm. still isn't working.

/bin/bash -c echo -n "E:"; curl -s "https://api.gdax.com/products/ETH-USD/ticker" | jq -r '.bid'

same "jq" not found error"

oleander commented 7 years ago

Bash requires a couple of extra params to work, sudo with the -i flag as shown above would be easier.

reteps commented 7 years ago

but then would I need a seperate file to run myscript.sh?

reteps commented 7 years ago

Thanks for helping!!!

oleander commented 7 years ago

Aha, I missed your |. Try this /usr/bin/sudo -u you -i bash -c 'echo -n "E:"; curl -s "https://api.gdax.com/products/ETH-USD/ticker" | jq -r ".bid"'

reteps commented 7 years ago

perfect, thanks!

YDundie commented 4 years ago

Aha, I missed your |. Try this /usr/bin/sudo -u you -i bash -c 'echo -n "E:"; curl -s "https://api.gdax.com/products/ETH-USD/ticker" | jq -r ".bid"'

Bruv you a lifesaver

glowinthedark commented 4 years ago

Provide the absolute path to jq:

which -a jq will show something like e.g.:

>>> /usr/local/bin/jq

Now instead of jq -r ".bid"' use /usr/local/bin/jq -r ".bid"

Why should I use an absolute path?

Because xbar/bitbar does not use your user's $PATH environment, and instead uses a restricted env that does not include /usr/local/bin in the $PATH (similar to the env crontab uses). If you do want to use your user's environment then do it explicitly at the top of the script with source ~/.bashrc (if using bash) or source ~/.zshrc (if using zsh) — but be aware that this might slow down your scripts depending on what you have in your shell config files. A better, safer and faster alternative would be to put at the top of your script

export PATH=/usr/local/bin:$PATH
Dizlen commented 3 years ago

/usr/local/bin/jq...

Thank you! Pointing directly to the location of it fixed my issue.

TOPWN commented 2 years ago

Provide the absolute path to jq:

which -a jq will show something like e.g.:

>>> /usr/local/bin/jq

Now instead of jq -r ".bid"' use /usr/local/bin/jq -r ".bid"

Why should I use an absolute path?

Because xbar/bitbar does not use your user's $PATH environment, and instead uses a restricted env that does not include /usr/local/bin in the $PATH (similar to the env crontab uses). If you do want to use your user's environment then do it explicitly at the top of the script with source ~/.bashrc (if using bash) or source ~/.zshrc (if using zsh) — but be aware that this might slow down your scripts depending on what you have in your shell config files. A better, safer and faster alternative would be to put at the top of your script

export PATH=/usr/local/bin:$PATH

you are a lifesaver!

AshokkumarMuthukrishnan commented 1 year ago
Screenshot 2023-01-16 at 8 19 15 PM

Folks, Can anyone help how to fix this one? In the GitLab pipeline, I'm getting this issue. However, in terminal jq working perfectly.