Your script will fail if mysql
is not in the script PATH.
Try using find
.
Note: This is only one way to do this. There are other examples that may be more efficient or more to your liking. One of the strengths of this site is the differing opinions and approaches to achieve the same result.
for file in $(find / -executable -type f -name mysql -print 2>/dev/null)
do
echo "Found $file"
"$file" -V
done
This will return
Found /usr/bin/mysql
/usr/bin/mysql Ver 14.14 Distrib 5.5.23, for Linux (x86_64) using readline 5.1
Note that if you have a large filesystem and a lot of files, this may take a long time.
Realize that as per your request, this will see if the mysql
client is installed, not the mysqld
server. It's possible to install the client without the server. If you want to see if mysqld
is installed, modify the find
and remove the version test.
which
only returns regular files anyway. This test will always be false. – Chris Down May 26 '12 at 20:16which mysql
to give back the path to mysql that then is checked if it's a file or not. But it seems to just not work. – Kit Sunde May 26 '12 at 20:19[
is an external command, as ifwhich
does not return anything,-f
will be missing an argument. – Chris Down May 26 '12 at 20:24