Shell scripting SQLite

后端 未结 2 607
滥情空心
滥情空心 2020-12-29 13:51

How do I write a shell script that displays SQLite results? I have written a script that adds an entry to the SQLite database. Now I want to display the results after adding

2条回答
  •  渐次进展
    2020-12-29 14:28

    If you need to assign sqlite SELECT result to a shell variable, you can do this.

    r=$(sqlite3 your_db_path.db "select something from some_table where condition")
    

    $r will be your variable.

    Single row also can be fetched. You can do some work to split it into an array, may be using IFS

    Additionally keep in mind to use #!/bin/bash convention on top of your every shell script. It'll solve many unwanted issues. Some times old #!/bin/sh convention gives troubles. :).

提交回复
热议问题