简体   繁体   中英

Run adb shell commands from script without exiting shell

I'm trying to create a script to simplify data checking with sqlite. For me it's quite troublesome to write :

adb shell
sqlite /data/data/my.package.name/databases/mydatabse.db

every time I want to check something in the db (and in the beginning phases of db development this is quite often), especially because TAB completion doesn't seem to work (at least for me). So I tried to write a script to automatically open the database for me, but the android documentation clearly states that:

shell [<shellCommand>] - Issues a shell command in the target emulator/device 
                         instance and then exits the remote shell.

So I was wondering whether there would be some way around that, so that my shell would remain running and I could use the sqlite3 command-line program. With a bit of help from here I was able to create scripts that run specific database queries, like so (but I'd like to keep the sqlite command-line program running):

#!/bin/bash
adb shell sqlite3 /data/data/my.package.name/databases/mydatabse.db "select * from someTable"

Thanks in advance!

You could try adding quotes around your adb commands, like mentioned here .

adb shell "sqlite /data/data/my.package.name/databases/mydatabse.db"

Make sure you have permission to access your database (read/write).

There is a github code published for dumping dbs, from here . Direct link: https://github.com/Pixplicity/humpty-dumpty-android/blob/master/humpty.sh

How about just using the command adb shell

Then run: sqlite /data/data/my.package.name/databases/mydatabse.db

This will keep the window open and then you just need to push up to get the last command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM