5 ms·
In 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
by reacweb 7y ago
In 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
- imihai1988 7y agoi do think 'man command' should bring up the specific man page for this, so there is no need to search into the bash man. this works with most builtin shell commands. e.g. 'man ls' is a thing
- stragies 7y agoOn (at least) Debian systems (, and probably many more) `ls` is not a built-in, but an external binary (`/usr/bin/ls`) is used. `which ls` and `help ls` will show you, if it is similar on your system.
- imihai1988 7y agoIt does't need to be a built-in to have a man page (many first party and third party libraries come with their own man pages).
- m463 7y ago"man command" on linux says "no manual entry for command" "man echo" on linux describes /usr/bin/echo "help echo" describes the builtin. on the othe hand, "man command" on mac os x gives a huge manpage of builtins (still hard to search for the common word "command")
- deleted 7y ago[deleted]
- dTal 7y agoHow little we expect from our computers. "help <command>" should be the first thing you expect to work.
- gravitas 7y ago`command` is a bash builtin, not an external program. The information is in the bash man page (which is hard to find in there because the word "command" is in the man page 7 bajillion times. Look in the major section "SHELL BUILTIN COMMANDS" where you find `cd` and others like it).
- jplayer01 7y agoYou can determine if something is a bash built-in by using 'which command'. If it's built-in, man won't work.
- Fnoord 7y agoIn config.fish I use type for this purpose, together with the exit code test (type brew 2>/dev/null); and brew # blahblah