How to use su command over adb shell?

2020-02-09 00:41发布

I need to make a script that executes a lots of thing on Android device, my device is rooted, when I enter on the shell, I can give the command su, and it works but I need pass this command like:

adb shell "
su;
mv /sdcard/Download/app_test /data/local;
cd /data/local;
./app_test;
exit;
exit;
"

when I put some commands before the su it works, according what I read su creates a new shell that return immediately, but I need give commands on the su shell, how can I do that?

3条回答
闹够了就滚
2楼-- · 2020-02-09 01:18

The su command does not execute anything, it just raise your privileges.

Try adb shell su -c YOUR_COMMAND.

查看更多
Emotional °昔
3楼-- · 2020-02-09 01:30

Well if you phone is rooted you can run commands with the "su -c" command.

Here is an example of a cat command on the build.prop file to get a phones product information.

adb shell "su -c 'cat /system/build.prop |grep "product"'"

This invokes root permission and runs the command inside the ' '

Notice the 5 end quotes, that is required that you close ALL your end quotes or you will get an error.

For clarification the format is like this.

adb shell "su -c '[your command goes here]'"

Make sure you enter the command EXACTLY the way that you normally would when running it in shell.

Give it a try, hope this helps.

查看更多
Rolldiameter
4楼-- · 2020-02-09 01:34

By default CM10 only allows root access from Apps not ADB. Go to Settings -> Developer options -> Root access, and change option to "Apps and ADB".

查看更多
登录 后发表回答