5

I have a small problem with a script that I am making for Android. I can't seam to get 'EOF' to work in 'mksh'. It is working fine in 'sh' and 'bash', but since 'mksh' is becomming the most used in Android I really need for it to work in all.

cat <<EOF
  ... lines here ...
EOF

This example will cause the fallowing error

can't create temporary file /sqlite_stmt_journals/mksh.(random): No such file or directory

I have seen others with this issue, but no real solution.

mirabilos
  • 5,123
  • 2
  • 46
  • 72
Daniel B
  • 1,205
  • 14
  • 18
  • I can't see what this has to do with my issue? That is an app issue related to the Emulator whereas mine is a shell issue regarding mksh – Daniel B Mar 08 '13 at 07:56

4 Answers4

10

The problem comes from that /sqlite_stmt_journals used to exist and be a world-writable sticky directory, like /tmp is in normal Unix boxen, so I used it as standard TMPDIR when I added mksh to Android.

Recent Android security policy forbids world-writable directories, totally.

We (the Android team and I) are aware of the problem but have yet to come up with a good solution; “user” home directories would need to be created before they can be (automatically) used, but a Googler told me they have something in the queue.

Until then, set TMPDIR to something that is writable for your user.

This is a problem with the Android environment, not with mksh per se.

@Julian Fondren: your Android device is probably from when that directory still existed.

In AOSP git master, the default TMPDIR is /data/local which is writable at least for the root user… so, just set it to something writable for you (and export it if you’re running scripts) for now.

mirabilos
  • 5,123
  • 2
  • 46
  • 72
2

Well, there's this obvious if unpleasant solution: don't use HERE docs; just echo each line to a temporary file. So your example becomes:

echo ... first line ... > $tmpfile
echo ... subsequent lines ... >> $tmpfile
cat $tmpfile
rm $tmpfile

EDIT: wait, what? Sure looks like HERE docs work just fine on mksh to me. The following occurs with mksh R39 on a stock Kindle Fire HD (don't mind the perl):

$ perl <<FOO
print "hi\n"
FOO
hi
$ 

Your example also works as I'd expect.

Julian Fondren
  • 5,459
  • 17
  • 29
  • 1
    Thanks for the answer, but your example does not work on my device. It could be an issue with certain versions of mksh, but I will have to get it working on all versions as this is not something that should only be run on my own device, in which case I would just replace mksh with bash. It seams that the only working solution is to create the missing folder. I just can't see why this is only needed by mkfs and not sh and bash. – Daniel B Mar 08 '13 at 07:58
  • If you are in a position where you can “echo ... first line ... > $tmpfile” then you can also just set TMPDIR to whereever you created $tmpfile in and use here documents, as mksh will track and use $TMPDIR. The problem is that there is no sane default for $TMPDIR currently ☹ but that’s a problem of the platform. – mirabilos Nov 30 '13 at 18:02
1

1) If you have root privileges:

When you open android shell then if you have root privileges of that device then run adb as root user.

adb root

instead of just

adb shell

this will solve your problem.

2) if you can modify the sh binary in your android device then modify such that it will go to find path

/data/local/tmp/

or

/data/local/atvc/  // In Motorola’s android device.

above directory has read/write/execute permission for shell user.

3) Install Busybox and run as Busybox cat <<EOF

Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222
0

from this post:

package=com.tayek.tablet.gui.android.cb7
cat <<EOF | adb -s 0a9196e8 shell
run-as $package
ls -l /data/data/$package
exit
exit
EOF
Community
  • 1
  • 1
Ray Tayek
  • 9,841
  • 8
  • 50
  • 90
  • This code runs `HERE` docs on the host PC and then pipes the result to the `adb shell` which is irrelevant to the OP's problem – Alex P. Nov 19 '16 at 15:20