Skip to content
Browse files

Fix command_exists to work with builtin commands.

Was mistakenly using -P option to type, which requires that the 
command be in the path. Using -t will also check aliases, functions,
and builtins. However, due to the script starting a new shell, it 
will not find aliases and functions defined by the caller.
  • Loading branch information...
1 parent e967ee6 commit b7c9172294d924c53647cf52ba2547454852c727 @booch booch committed Mar 7, 2013
Showing with 3 additions and 3 deletions.
  1. +3 −3 sbin/command_exists
View
6 sbin/command_exists
@@ -1,8 +1,8 @@
#!/bin/bash
-# Determine whether a command exists on the system and in the $PATH (or an alias, function, or builtin).
+# Determine whether a command exists on the system and in the $PATH (or a builtin).
# Returns 0 (true) if the command exists, otherwise 1 (false).
+# NOTE: Because this script starts a new shell, it will not find aliases and functions defined by the caller.
-type -P "$1" > /dev/null 2>&1;
-exit $?
+type -t "$1" > /dev/null 2>&1

0 comments on commit b7c9172

Please sign in to comment.
Something went wrong with that request. Please try again.