我想通过Linux中的管道在bash adb shell
循环中解析while
命令的输出,但是adb shell
总是输出DOS换行符而不是Unix / Linux换行符:
$ adb shell "echo Hello World" | file -b -
ASCII text,with CRLF line terminators
所以我总是需要音乐会,需要将DOS换行符转换为Unices',否则我将无法获得预期的结果:
$ adb shell pm list packages -3 | dos2unix | sort | cut -d: -f2 | \
while read appID; \
do \
echo "=> appID = $appID"; \
\curl -qs "https://play.google.com/store/apps/details?id=$appID"| pup --charset utf8 "title text{}" | awk -F' - ' '{print$1}'; \
done
我的问题如下:
如何设置adb shell
而不是LF
来输出CRLF
?
顺便说一句:dos2unix
是我perl -pe 's/\r//g'
的别名
EDIT0:命令adb exec-out
在adb
版本1.0.31中不可用:
$ adb exec-out echo 2>&1 | head
Android Debug Bridge version 1.0.31
-a - directs adb to listen on all interfaces for a connection
-d - directs command to the only connected USB device
returns an error if more than one USB device is present.
-e - directs command to the only running emulator.
returns an error if more than one emulator is running.
-s <specific device> - directs command to the device or emulator with the given
serial number or qualifier. Overrides ANDROID_SERIAL
environment variable.
....
编辑1:在此手机上找不到stty
>
$ adb shell "stty raw;echo Hello World"
/system/bin/sh: stty: not found
Hello World
$ adb shell "stty raw;echo Hello World" | file -b -
ASCII text,with CRLF line terminators
$