For the purpose you describe is correct. You can, however, make a small change by removing the use of echo
, if you are using a sufficiently current version of the bash shell that supports " here strings "
row=$(mysql $dbName -u $dbUser --password=$dbPass <<< "select file_id, file from catalogue__pdf_file WHERE is_converted='no' ORDER BY file_id DESC LIMIT 0,1")
I leave only one suggestion regarding the data dbName, dbUser, dbPass . Usually what I do is save this information in a configuration file, instead of including this information in the script where you execute the command. This can be useful if in the future you have multiple scripts that use the same credentials and need to make a change. This way you only change your configuration file and not a set of scripts individually.
I store the data in the file ~/.my.cnf
with the structure.
[client]
user = 'utilizador'
password = 'password'
database= 'basedados'
In this way your command would be:
row=$(mysql <<< "select file_id, file from catalogue__pdf_file WHERE is_converted='no' ORDER BY file_id DESC LIMIT 0,1")
If the script is used by more than one user, you can centralize this information in a common directory and have multiple users access and use flag --defaults-file=/path1/path2/ficheiro_configuracao
in your script to indicate your location.
Your command would be:
row=$(mysql --defaults-file=/path1/path2/ficheiro_configuracao <<< "select file_id, file from catalogue__pdf_file WHERE is_converted='no' ORDER BY file_id DESC LIMIT 0,1")