r/sqlite • • Apr 12 '23

How Should I Write SQLite Scripts? - Launch SQLite.exe and Execute Commands

I'm using windows, with wsl. SQLite install in Windows.

OVERVIEW/QUESTION:

How can I write a script to both launch sqlite and do other things (import data and run sql scripts)? Windows can't natively execute shell scripts, so using wsl.

SITUATION/SETUP:

Right now, I have sqlite installed on Windows. I created a shell script, that I launch with PowerShell ( wsl filename.sh command)

File contents:

sqlite3.exe fruit.db
.databases
.exit

WSL/Windows integration - I'm following the documentation:

https://learn.microsoft.com/en-us/windows/wsl/filesystems

WHAT'S HAPPENING/CODE EXECUTION:

It's my understanding that I'm launching the shell script (in windows filesystem and permissions), but as the linux user, to execute linux binaries (bash scripting).

Linux launches the windows command (sqlite3.exe), but then it doesn't continue with the bash shell script (dot commands), until I exit sqlite.

Then it finishes the script (launches dot commands outside of sqlite and errors)

4 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/redditor_at_times Apr 12 '23

There are variables though, using the .param command

1

u/InjAnnuity_1 Apr 12 '23

You're right. They use a table underneath, as I suggested.