0

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?

5
  • Where are the multiple commands? There's just one bash command, sqlite3. It has multiple lines of input in the where-doc, but that doesn't create multiple commands. Commented May 6, 2022 at 8:37
  • What data are you getting? This just inserts and deletes, there's no SELECT. Commented May 6, 2022 at 8:37
  • #!/bin/bash variable=$(sqlite3 pdu.db <<'END_SQL' .timeout 2000 SELECT Variable_Value FROM Data Where Sr_No'7'; END_SQL ) Commented May 6, 2022 at 8:46
  • Edit the question. Commented May 6, 2022 at 8:47
  • 1
    You can stuff into a variable as much information as you like (since you can append to a variable). I would rather think of how the end effect should be represented: Just all the output pieces strung together, or with a separator? Or may be an array where each element contains the output of one command execution? Commented May 6, 2022 at 9:53

1 Answer 1

1

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
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.