我需要制作一个脚本,在Android设备上执行很多东西,我的设备是root的,当我进入shell时,我可以给命令su,它可以工作,但我需要传递这个命令,如: / p>
adb shell "
su;
mv /sdcard/Download/app_test /data/local;
cd /data/local;
./app_test;
exit;
exit;
"
当我在su之前输入一些命令时,根据我读的su创建了一个立即返回的新shell,但是我需要在su shell上发出命令,我该怎么做?
答案 0 :(得分:27)
如果您的手机已植根,您可以使用" su -c"命令。
以下是build.prop文件中cat命令的示例,用于获取电话产品信息。
adb shell" su -c' cat /system/build.prop | grep" product"'"
这会调用root权限并在'中运行命令。 ' 强>
请注意5个结束引号,要求您关闭所有结束引号,否则您将收到错误。
为了澄清,格式是这样的。
adb shell" su -c' [你的命令在这里]'"
确保以在shell中运行它的方式完全按照通常的方式输入命令。
尝试一下,希望这有帮助。
答案 1 :(得分:4)
su
命令不会执行任何操作,只会提高您的权限。
尝试adb shell su -c YOUR_COMMAND
。
答案 2 :(得分:2)
默认情况下,CM10仅允许从Apps而非ADB进行root访问。转到设置 - >开发者选项 - > Root访问权限,并将选项更改为“Apps and ADB”。
答案 3 :(得分:2)
在我的Linux上,我看到一个错误
adb shell "su -c '[your command goes here]'"
su:无效的uid / gid'-c'
解决方案在Linux上
adb shell su 0 '[your command goes here]'
答案 4 :(得分:0)
对于我的用例,我想从magisk配置文件中获取SHA1哈希。下面对我有用。
adb shell "su -c "cat /sbin/.magisk/config | grep SHA | awk -F= '{ print $2 }'""
答案 5 :(得分:0)
win cmd
C:\>adb shell id
uid=2000(shell) gid=2000(shell)
C:\>adb shell 'su -c id'
/system/bin/sh: su -c id: inaccessible or not found
C:\>adb shell "su -c id"
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
C:\>adb shell su -c id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
win msys bash
msys2@bash:~$ adb shell 'su -c id'
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
msys2@bash:~$ adb shell "su -c id"
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
msys2@bash:~$ adb shell su -c id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
如果要运行am
cmd,则可能需要-t
选项:
C:\>adb shell su -c am stack list
cmd: Failure calling service activity: Failed transaction (2147483646)
C:\>adb shell -t su -c am stack list
Stack id=0 bounds=[0,0][1200,1920] displayId=0 userId=0
...
外壳选项:
shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...]
run remote shell command (interactive shell if no command given)
-e: choose escape character, or "none"; default '~'
-n: don't read from stdin
-T: disable pty allocation
-t: allocate a pty if on a tty (-tt: force pty allocation)
-x: disable remote exit codes and stdout/stderr separation
Android Debug Bridge版本1.0.41
版本30.0.5-6877874