Reputation: 367
mysql $DB_NAME <<EOFMYSQL
UPDATE environment SET is_default = CASE WHEN environment='$ENV' THEN 1 ELSE 0 END;
EOFMYSQL
i want to update run my update query is it correct code to run? and what does << means in shell script why do we write EOFMYSQL after first line?
Upvotes: 1
Views: 2392
Reputation: 754800
The <<
notation is a 'here document' and supplies standard input from the text in the script from the line after the line containing <<
to the line consisting solely of the word specified after the <<
(in your example, EOFMYSQL
). So, the one-line UPDATE statement is the standard input to the mysql
command.
When you don't quote EOFMYSQL (as in your example, then shell variables are expanded in the here document. If you quote it, then variables etc are left unexpanded.
If $ENV
contains the value you're after, it should work.
Upvotes: 3