Jabeen
Jabeen

Reputation: 367

how to write shell script to run update query and what does "<<" means?

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

Answers (1)

Jonathan Leffler
Jonathan Leffler

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

Related Questions