开发者

Rewriting script so it works without using a temp file

开发者 https://www.devze.com 2023-02-10 08:53 出处:网络
I have written a small script to pull of all shared object files from an android device for dynamically linked native code development. The script works fine and I could probably stop there, but I don

I have written a small script to pull of all shared object files from an android device for dynamically linked native code development. The script works fine and I could probably stop there, but I don't like the use of the temporary file. I spent some time trying to re-write this so I don't need it but failed with all sorts of attempts. Here is the script:

declare -rx OUT_FILE=tmp.sh
adb shell 'cd /system/lib && for f in *.so; do echo -e "adb pull /system/lib/$f ./lib"; done' > $OUT_FILE
dos2unix $OUT_F开发者_StackOverflow社区ILE
chmod +x $OUT_FILE
./$OUT_FILE
rm $OUT_FILE

I tried using a subshell for the adb command and assigning the result to a variable that could then be fed into sed to strip the carriage returns. I couln't get that to work. Here is an example how I tried using command substitution:

res=$(adb shell 'cd /system/lib && for f in *.so; do echo -e "adb pull /system/lib/$f ./lib"; done')
echo $res > tmp.txt

Now from my limited knowledge I would suspect that the tmp.txt file from the second solution would contain the same conent as the tmp file in my working solution. This is not the case.

Best Regards,

Andre


Assuming that pipes are supported, then this should work - no intermediate files. I'm making the wild assumption that 'dos2unix' will work as a pure filter, too.

adb shell 'cd /system/lib &&
           for f in *.so; do echo -e "adb pull /system/lib/$f ./lib"; done' |
dos2unix |
bash


from all the hints above I managed to distill this:

lib_list=$(adb shell 'for f in /system/lib/*.so; do echo $f; done')
for f2 in $lib_list
do
    path=$(echo $f2 | tr -d '\r');
    adb pull $path ./lib
done

This works, the main problem was the carriage return. This could nicely by seen by running the script with the -x debugging switch.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号