0

I want to check if the function mdfind returns true, and by that I mean if it finds what the user specified in a variable from a read call.

This is what I've got but it isn't working:

#!/bin/bash
clear
echo "Loading..."
sleep 2
clear
echo "Grand Theft Auto Launcher | v1.0"
echo -n "Grand Theft Auto Game Name: "
read game

if [ mdfind $game ]
then
clear
echo "$game found."
echo "Launching..."
fi
NanoCoder
  • 35
  • 1
  • 6
  • 1
    debug using `+x` at `#!/bin/bash +x` – rajuGT Nov 20 '15 at 14:57
  • `[` tests values using its predicates. It is a command (not syntax). It **returns** true or false as appropriate. If you want to test a command other then `[`/`test` just use that command directly instead of `[`. – Etan Reisner Nov 20 '15 at 14:58
  • I don't get it. Could you write an example? – NanoCoder Nov 20 '15 at 15:00
  • Just remove `[` and `]` from your example. `if` checks the return code of the command between `if` and `then`. That is very often the `[` command. In your case you want it to be the `mdfind` command. – Etan Reisner Nov 20 '15 at 15:01
  • See [When square brackets are required in bash if statement?](https://stackoverflow.com/questions/8934012/when-square-brackets-are-required-in-bash-if-statement) – Etan Reisner Nov 20 '15 at 15:02
  • Thanks, it worked! :) – NanoCoder Nov 20 '15 at 15:03

0 Answers0