简体   繁体   English

Android Shell,默认使用busybox命令

[英]Android shell using busybox commands as default

I'm running a script on android and in effort to make it as portable as possible, all commands use busybox. 我正在android上运行脚本,并努力使其尽可能可移植,所有命令均使用busybox。 How I've got it set up currently, is every command has a function named the same, so it converts those commands to use busybox, like so: 我目前如何设置它,每个命令都有一个相同的函数,因此它将这些命令转换为使用busybox,如下所示:

echo () {
busybox echo $1 $2 $3 $4 $5
}
echo "hai"

As this has to be done for every command, it takes a lot of space inside the script. 由于必须对每个命令执行此操作,因此在脚本内部会占用大量空间。 That's why I'm trying to figure out a way to force the shell to default to using busybox rather than /system/bin or /system/xbin. 这就是为什么我试图找出一种方法来强制Shell默认使用busybox而不是/ system / bin或/ system / xbin。 Could this be achieved by modifying the PATH variable? 可以通过修改PATH变量来实现吗? Or is there an environment variable build into shell I could use? 还是在我可以使用的shell中内置环境变量?

Or should I do something like this?: 还是我应该做这样的事情?:

bs () {
busybox $@
}

bs echo "Some text"

(I'd like to avoid this if possible as it decreases readability) (我想避免这种情况,因为它会降低可读性)

EDIT 编辑

Could I start a background process that loops and when it detects a command being passed for the shell to processes, it stops this and passes it to busybox? 我是否可以启动一个循环的后台进程,并且当它检测到将Shell传递给进程的命令时,它将停止并将其传递给busybox? Somehow read from stdin before shell processes it? 在外壳处理之前以某种方式从stdin读取?

EDIT 2 编辑2

So I thought about redirecting commands into busybox like this: 因此,我考虑过将命令重定向到busybox中,如下所示:

busybox <<EOF
echo "hai";
EOF

Could this be used somehow? 可以以某种方式使用它吗?

UPDATE UPDATE

I've moved to using busyboxes ash shell and it does everything I want it to do. 我已经开始使用busyboxes ash shell,它可以完成我想做的所有事情。 Appareantly there's no way of intercepting commands before they're passed to the shell. 显然,在将命令传递到外壳之前,无法拦截它们。

Use the shell's built-in 'alias' (Alias Substitution, Shell Command Language, IEEE Standard 1003.1 (2013) ) method. 使用外壳程序的内置“别名” (别名,外壳程序命令语言,IEEE Standard 1003.1(2013)) For example: 例如:

alias vi="busybox vi"
vi readme.txt

will substitute the word 'vi' with 'busybox vi' and the shell will then process 将用“ busybox vi”替换“ vi”一词,然后外壳程序将进行处理

busybox vi readme.txt busybox vi readme.txt

Because it is a simple substitution, all parameters are preserved and passed on to the substituted command. 因为这是简单的替换,所以所有参数都将保留并传递给替换的命令。

You can also add default parameters to the substitution like so: 您还可以将默认参数添加到替换中,如下所示:

alias fbset="busybox fbset -fb /dev/graphics/fb0"

after which one no longer needs to specify the frame buffer - it is added for you. 之后,您不再需要指定帧缓冲区-它会为您添加。 And typically programs will take the last specified parameter as the active one, so if you do need to specify another frame buffer (in the above example) it will ignore the one provided in the alias. 通常,程序会将最后指定的参数作为活动参数,因此,如果您确实需要指定另一个帧缓冲区(在上面的示例中),它将忽略别名中提供的那个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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