如何在 adb shell 上使用 su 命令? [英] How to use su command over adb shell?

查看:77
本文介绍了如何在 adb shell 上使用 su 命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个在Android设备上执行很多东西的脚本,我的设备是root的,当我进入shell时,我可以给出命令su,它可以工作,但我需要传递这个命令:

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;
"

当我在 su 之前放置一些命令时,它会根据我阅读的内容创建一个新的 shell 立即返回,但我需要在 su shell 上给出命令,我该怎么做?

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?

推荐答案

好吧,如果您的手机已root,您可以使用 su -c 命令运行命令.

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

下面是 build.prop 文件中的 cat 命令示例,用于获取手机的产品信息.

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

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

这会调用 root 权限并在 ' ' 中运行命令.

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

请注意 5 个结束引号,这要求您关闭所有结束引号,否则您会收到错误消息.

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]'"

确保您输入命令的方式与在 shell 中运行时的正常方式完全相同.

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

这篇关于如何在 adb shell 上使用 su 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆