【问题标题】:Using cut or sed in Android busybox在 Android busybox 中使用 cut 或 sed
【发布时间】:2013-11-20 14:45:04
【问题描述】:

我想在 adb 中修剪一个字符串。 如果我写busybox --help 它会将cut 和sed 列为可用命令。

mount |grep -e /system

有效,但是

 mount |grep -e /system| cut -f 1 -d ' '

不起作用。 android的busybox中有特殊的语法吗? 我也试过了

 echo "Hello World"|cut -f 1 -d ' '

从手册页,它不起作用..

root@android:/ # busybox cut --help
busybox cut --help
BusyBox v1.21.1-Stericson (2013-07-08 15:58:11 BST) multi-call binary.

Usage: cut [OPTIONS] [FILE]...

Print selected fields from each input FILE to stdout

    -b LIST Output only bytes from LIST
    -c LIST Output only characters from LIST
    -d CHAR Use CHAR instead of tab as the field delimiter
    -s      Output only the lines containing delimiter
    -f N    Print only these fields
    -n      Ignored

【问题讨论】:

  • 第一次检查可用选项cut --help
  • 为问题添加了可用选项。
  • 刚刚将busybox添加到线路中并且它可以工作。就像cut --help 不起作用,但busybox cut --help 起作用。 mount |grep -e /system|busybox cut -f 1 -d ' '
  • 可能没有从cut 到busybox 的符号链接,或者您的搜索路径中首先出现了一些更原始的版本。

标签: android adb cut busybox


【解决方案1】:

为了让busybox 小程序以您期望的方式工作,您需要首先创建适当的符号链接:

$ adb shell whence sed
$ adb shell sed
/system/bin/sh: sed: not found
$ adb root
$ adb remount
remount succeeded
$ adb shell whence busybox
/system/bin/busybox
$ adb shell ln -s /system/bin/busybox /system/bin/sed
$ adb shell whence sed
/system/bin/sed
$ adb shell sed
Usage: sed [-efinr] SED_CMD [FILE]...

或者只是做mount | grep -e /system | busybox cut -f 1 -d ' '

【讨论】:

  • 是的,正如我在评论中所说的那样,它确实有效,错误确实是缺少符号链接。我没有意识到当我输入“sed”或“cut”时没有错误,它找到了命令并给了我参数列表。我仍然必须使用busybox 命令而不是别名。感谢您的帮助!
猜你喜欢
  • 2014-12-10
  • 2020-06-19
  • 2021-12-07
  • 2020-05-15
  • 1970-01-01
  • 2021-11-03
  • 2013-02-05
  • 2021-03-14
  • 2019-10-20
相关资源
最近更新 更多