Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading