5 ms·
> Don’t try to install things with brew if brew is not installed: if which brew 2>&1 /dev/null ; then brew install jq fi This just hides a usefu
by asaph 7y ago
> Don’t try to install things with brew if brew is not installed:
if which brew 2>&1 /dev/null ; then
brew install jq
fi
This just hides a useful error message (brew not installed). I would rather just see that error message (either interactively or in a log) and have the script fail. Hiding the error message just leads to an eventual failure down the road when jq is invoked.
- deleted 7y ago[deleted]
- majewsky 7y agoI think this snippet needs some context. In all contexts that I can imagine, the first line should actually be if which jq &>/dev/null; then brew install jq fi
- playpause 7y agoThat seems more reasonable, but it's not what the author wrote. He precedes the snippet with "Don’t try to install things with brew if brew is not installed", so his intention does seem to be to swallow errors silently, which is definitely weird.
- deleted 7y ago[deleted]
- pletnes 7y agoHe might want his .bashrc to work on both macos and linux.
- deleted 7y ago[deleted]
- reacweb 7y agoIn bash, there is the build-in command named "command". I have used it for the same purpose, like in: command -v brew >/dev/null && brew install jq
- temo4ka 7y agoIf you don't care for maximum POSIX compatibility, i.e. your script is bash-specific, it's better to use "hash", which is going to ignore aliases (but not functions) and also has the benefit of caching the command for further use. hash foo &>/dev/null || { echo "foo command not found blabla..." >&2; exit 1; } more info: https://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script https://stackoverflow.com/questions/592620/how-to-check-if-a...
- raldi 7y agoWow. It's impossible to google, and on MacOS, `man command` is useless.
- s_gourichon 7y ago$ help command command: command [-pVv] command [arg ...] Execute a simple command or display information about commands. Runs COMMAND with ARGS suppressing shell function lookup, or display information about the specified COMMANDs. Can be used to invoke commands on disk when a function with the same name exists. Options: -p use a default value for PATH that is guaranteed to find all of the standard utilities -v print a description of COMMAND similar to the `type' builtin -V print a more verbose description of each COMMAND Exit Status: Returns exit status of COMMAND, or failure if COMMAND is not found.
- m463 7y agoThank you. I never knew about help to describe a builtin shell command. normally searching for something like "command" in the bash man page would be very tedious. also: help echo
- deleted 7y ago[deleted]
- jolmg 7y agoIt seems you miswrote, or the author corrected himself. Right now it's: if which brew >/dev/null 2>&1 ; then brew install jq fi Which would hide the error message. The code you posted outputs: brew not found /dev/null not found
- lmm 7y agoIt's impractical to determine whether Hacker New's undocumented formatting language is going to eat any given angle bracket ahead of time. I suspect OP wrote something correct and the site has mangled it.
- deleted 7y ago[deleted]
- asaph 7y agoIt got messed up when I was trying to format it, unfortunately. But my point still stands.
- aasasd 7y agoYou don't need to check for `brew` in each task if they're run automatically. Just have one task that checks for `brew`. With a proper dependency graph, the tasks installing things would depend on the task `brew-installed`. This, of course, is leaving alone the point that installing stuff on startup is weird, doubly so with brew which is pretty slow.
- aasasd 7y agoCorrection, to clarify: you need to check for `brew` in each task but not warn. One master warning is enough.