Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Tuesday, December 11, 2012

Check if a program exists from a bash script

$ command -v foo >/dev/null 2>&1 || { 
  echo >&2 "I require foo but it's not installed.  Aborting."; exit 1;  
}
OR 
$ type foo >/dev/null 2>&1 || { 
  echo >&2 "I require foo but it's not installed.  Aborting."; exit 1;  
}
OR 
$ hash foo 2>/dev/null || { 
  echo >&2 "I require foo but it's not installed.  Aborting."; exit 1;  
}