Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Shell EOF

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.

like image 414
Daniel B Avatar asked Mar 07 '13 22:03

Daniel B


2 Answers

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.

like image 50
mirabilos Avatar answered Oct 13 '22 00:10

mirabilos


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.

like image 21
Julian Fondren Avatar answered Oct 13 '22 00:10

Julian Fondren