I’m trying to read shell script which I haven’t worked with before… What does this code do?
# Setup some command defaults (can be overriden by the config)
MYSQL=${MYSQL:-`which mysql`}
MYSQLDUMP=${MYSQLDUMP:-`which mysqldump`}
PHP=${PHP:-`which php`}
I have a feeling it determines the location of php, mysql and mysqldump if the variable is not already defined. Is that correct?
If variable is undefined or is the empty string, it replaces it with the result of the
whichcommand so that it serves as a default value.Side note, you could make it more robust by using
type -P mysqlorhash mysqlinstead ofwhich mysqlsince implementations ofwhichmay differ.see http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html and Check if a program exists from a Bash script