sql select statement over adb - sqlite

I would like to have a batch file that runs a select statement over adb and returns the found rows.
This is the command that I use in my batch file:
adb shell "su -c sqlite3 /data/user_de/0/com.android.providers.telephony/databases/mmssms.db 'select * from sms;'"
The problem I have is, that my command produces an error:
Error: incomplete input
What I don’t understand is that the fallowing command works just fine:
adb shell "su -c sqlite3 /data/user_de/0/com.android.providers.telephony/databases/mmssms.db '.tables'"
This returns the tables from the database, as expected.
My guess is, that I need to escape some characters, the “;” maybe, but escaping it with \ or with ^ both did not work.
Any help would be greatly appreciated.

I guess you are using powershell, then escape the ;:
adb shell "su -c sqlite3 /data/user_de/0/com.android.providers.telephony/databases/mmssms.db 'select * from sms`;'"

Related

Why am I getting a syntax error when trying to use -v flag for variables in psql command?

I'm trying to use the following psql command in a zsh shell to send a query to a database:
psql -Atx $mydburl -v myvar=1 -c "SELECT :myvar"
And I'm getting the following error:
ERROR: syntax error at or near ":"
LINE 1: SELECT :myvar
^
However, when I use a pipe, this works just fine:
echo "SELECT :myvar" | psql -Atx $mydburl -v myvar=1
And it produces the expected result of:
?column?|1
What is going on here?
That's as documented:
-c command
[...]
command must be either a command string that is completely parsable by the server (i.e., it contains no psql-specific features), or a single backslash command.

what is the first step of ssh copy execute in terminal?

I am using this command to copy file from remote server to local machine:
scp -r app:/home/dolphin/model* .
In bash it works fine.In zsh it throw this error:zsh: no matches found: app:/home/dolphin/model*.I am searching from Google and understand the bash and zsh have different rule of glob.Here is my question:
what is the execute step detail of this command?
anyone could tell me the shell how to execute the command,the first step is echo the path of this command?
I could use -v(verbose) to see the scp execute process.
I am unfamiliar with Zsh, but as far as I can say, Bash will pass the original string to the program as an argument if nothing is globbed, while it appears that Zsh complains in this case.
To ensure the "unglobbed" string is passed as an argument to scp(1), you can escape the asterisk:
scp -r app:/home/dolphin/model\* .
^^

UNIX commands from R via shell function

I need to issue unix commands from an R session. I'm on Windows R2 2012 server using RStudio 1.1.383 and R 3.4.3.
The shell() function looks to be the right one for me but when I specify the path to my bash shell (from Git for Windows install) the command fails with error code 127.
shell_path <- "C:\\Program Files\\Git\\git-bash.exe"
shell("ls -a", shell = shell_path)
## running command 'C:\Program Files\Git\git-bash.exe /c ls -a' had status 127'ls -a' execution failed with error code 127
Pretty sure my shell path is correct:
What am I doing wrong?
EDIT: for clarity I would like to pass any number of UNIX commands, I am just using ls -a for an example.
EDIT:
After some playing about 2018-03-09:
shell(cmd = "ls -a", shell = '"C:/Program Files/Git/bin/bash.exe"', intern = TRUE, flag = "-c")
The correct location of my bash.exe was at .../bin/bash.exe. This uses shell with intern = TRUE to return the output as an R object. Note the use of single quote marks around the shell path.
EDIT: 2018-03-09 21:40:46 UT
In RStudio we can also call bash using knitr and setting chunk options:
library(knitr)
```{bash my_bash_chunk, engine.path="C:\\Program Files\\Git\\bin\\bash.exe"}
# Using a call to unix shell
ls -a
```
Two things stand out here. Bash will return exit code 127 if a command is not found; you should try running the fully qualified command name.
I also see that your shell is being run with a /c flag. According to the documentation, the flag argument specifies "the switch to run a command under the shell" and it defaults to /c, but "if the shell is bash or tcsh or sh the default is changed to '-c'." Obviously this isn't happening for git-bash.exe.
Try these changes out:
shell_path <- "C:\\Program Files\\Git\\git-bash.exe"
shell("/bin/ls -a", shell = shell_path, flag = "-c")
Not on Windows, so can't be sure this will work.
Perhaps you need to use shQuote?
shell( paste("ls -a ", shQuote( shell_path) ) )
(Untested. I'm not on Windows. But do read ?shQuote))
If you just want to do ls -a, you can use the below commands:
shell("'ls -a'", shell="C:\\Git\\bin\\sh.exe")
#or
shell('C:\\Git\\bin\\sh.exe -c "ls -a"')
Let us know if the space in "Program Files" is causing problems.
And if you require login before you can call your command,
shell('C:\\Git\\bin\\sh.exe --login -c "ls -a"')
But if you are looking at performing git commands from R, the git2r by ropensci might suit your needs.

Execute multiple unix commands from SAS

I am trying to delete a file from a SAS program. The Unix commands I want to run are:
unalias rm;
rm -f &file..txt;
How do I do this? I tried using the 'x' statement, but can't get it to work. I need the commands to run in the same shell for unalias to work AND I need the macro variable to resolve.
You can use semi-colon (;) to separate multiple commands in one command string.
x "unalias rm; rm -f &file..txt";
In general I just use a leading backslash to force Unix to NOT use the alias for command.
x "\rm -f &file..txt";

What does set -e command does in Unix?

What does the set -e command do in SHELL scripting?
Like the following command:
set -e
Can we do any other things with set -e operation?
The 'set' command is used set and examine shell options, as well as set positional parameters.
The -e flag does the following:
-e Exit immediately if a command exits with a non-zero status.
Hope this helps :)
Using the flag -e you ensure stops the execution if a command during the execution has an error.
The default behaviour is to ignore the errors in script executions.
If you want to manage this errors, you can use the command "trap".

Resources