Bash scripting, call a function as a conditional test

Can someone please tell me why line 7 (the if statement) generates an error:

test.sh: line 7: [: command_exists: unary operator expected

thank!

#!/usr/bin/env bash

command_exists () {
  command -v "$1" &> /dev/null ;
}

if [ ! command_exists ruby ]; then  # test.sh: line 7: [: command_exists: unary operator expected
  echo 'found ruby'
else
  echo 'ruby not found'
fi
+3
source share
1 answer
if ! command_exists ruby; then

In Bash, ifa command is executed and acts on its return value. [- this is a team.

+5
source

All Articles