Search code examples
androidadbcutbusybox

Using cut or sed in Android busybox


I want to trim a string in adb. If I write busybox --help it lists cut and sed as available commands.

mount |grep -e /system

works, but

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

doesn't work. Is there a special Syntax in android's busybox? I also tried

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

from the manpage and it doesn't work..

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

Solution

  • In order for busybox applets to work the way you expect you need to create the appropriate symlinks first:

    $ 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]...
    

    Or just do mount | grep -e /system | busybox cut -f 1 -d ' '