Home > Blockchain >  How to combine multiple commands output in the one varialble in shell script?
How to combine multiple commands output in the one varialble in shell script?

Time:05-07

I'm using the following script to get the data of one of the variables from the database file

#!/bin/bash

sqlite3 pdu.db <<'END_SQL'
.timeout 2000
SELECT Variable_Value FROM Data Where Sr_No'7';
END_SQL

Now I wanted to store the output of the above commands in one variable. How we can store multiple commands output in one variable in the shell script?

CodePudding user response:

There's no restriction against putting a multiline command inside a command substitution.

variable=$(sqlite3 /var/www/dbs/ha.db <<'END_SQL'
.timeout 2000
INSERT INTO table1 SELECT * FROM table2;
DELETE FROM table2;
END_SQL
)
  • Related