1

The script

#!/system/bin/sh
/system/bin/busybox find . 
f=$(/system/bin/busybox find .)
echo $f
for f in $(/system/bin/busybox find .) 
do 
 echo $f
done

does not work as expected in my environment. I get:

.
./loop.sh

while

bash loop.sh 
.
./loop.sh
. ./loop.sh
.
./loop.sh

is the result for the equivalent on a linux box:

#!/bin/sh
find . 
f=$(find .)
echo $f
for f in $(find .) 
do 
 echo $f
done

What can I do about this?

The environment is:

getprop ro.build.version.sdk 
22
getprop ro.build.version.release 
5.1.1
busybox
BusyBox v1.22.1 (2014-09-16 09:27:06 CST) multi-call binary.
busybox uname -a
Linux localhost 3.14.0 #68 SMP PREEMPT Wed Jan 18 10:27:06 CST 2017 i686 GNU/Linux
Wolfgang Fahl
  • 111
  • 1
  • 5
  • Maybe you're comparing apples with peaches here, as /bin/sh is something else than /bin/bash (e.g. doesn't support as many things as Bash does). Have you tried how that script works on Linux when using #!/bin/sh instead of #!/bin/bash? Or on your Android device when using Bash (if you have it available there that is)? – Izzy May 12 '17 at 09:20
  • @lzzy - thank you for looking into this. On linux the /bin/sh doesn't make any difference. I would love to try out bash on my android device but i don't see how i could try it out without e.g. installing a full debian or a different busybox version. For the time being I'd love to understand what's going on that such a basic function like subshell doesn't work out of the box. – Wolfgang Fahl May 12 '17 at 09:32
  • Making no difference means it works the same as with Bash – or the same as with sh on the Android device? As for Bash on Android: my corresponding app list says there is e.g. Bash Shell X you could give a try (if you don't mind it coming with AdMob; otherwise Termius also includes a local Bash). – Izzy May 12 '17 at 09:39
  • 1
    I guess it's because BusyBox has a different version of find compared to your Linux Distro.. BTW, what is your script trying to achieve? If it's simply listing the contents of a directory, you could better use ls, and pipe it to grep for searching.. – Gokul NC May 12 '17 at 14:00
  • it doesn't make any difference what subshell command I call. the subshell $() doesn't work as expected .. – Wolfgang Fahl May 12 '17 at 14:37

0 Answers0