Android Enthusiasts
Q&A for enthusiasts and power users of the Android operating system
Latest Questions
7
votes
4
answers
3118
views
How to write Android shell history to file?
Using [Terminal Emulator for Android][1], is there a way to enable a persistent command history? So far, I've tried the following: * Initial command of `export HISTFILE=$HOME/.mksh_history` * User mksh profile */data/data/jackpal.androidterm/app_HOME/.mkshrc* containing `export HISTFILE=$HOME/.mksh_...
Using Terminal Emulator for Android , is there a way to enable a persistent command history?
So far, I've tried the following:
* Initial command of
export HISTFILE=$HOME/.mksh_history
* User mksh profile */data/data/jackpal.androidterm/app_HOME/.mkshrc* containing export HISTFILE=$HOME/.mksh_history
* System mksh profile */system/etc/mkshrc* containing export HISTFILE=/data/data/jackpal.androidterm/app_HOME/.mksh_history
(though preferably the solution does not involve writing to */system*)
I'm able to get other Android shells (ash and bash) to write histories into *app_HOME* without issue. I'm also able to get mksh to write *HISTFILE* on Linux without issue.
Six
(360 rep)
Jul 26, 2016, 02:16 AM
• Last activity: Apr 15, 2024, 04:22 PM
1
votes
1
answers
687
views
Difference between adb shell [command] and interactive adb shell
I am wondering if the interactive shell `adb shell` runs in a different context then when invoking a command via `adb shell [command]`? The background to this question is, that I am running `dinit` on an Android powered board. `dinit` is started in user mode just for service management. When I run `...
I am wondering if the interactive shell
adb shell
runs in a different context then when invoking a command via adb shell [command]
?
The background to this question is, that I am running dinit
on an Android powered board. dinit
is started in user mode just for service management. When I run dinitctl -u list
from the interactive shell I get the expected output (enabled services and their current state), but when I run it via adb shell dinitctl -u list
I just get an error about the socket not being found (as if dinit
itself was not running).
stylesuxx
(131 rep)
Apr 29, 2022, 10:56 PM
• Last activity: Apr 30, 2022, 10:57 AM
2
votes
1
answers
420
views
How to use multibyte file names in adb shell?
I have a Galaxy S6 running Android 7.0: zeroflte:/ $ getprop ro.build.version.release 7.0 There exists a file which uses the Unicode codepoint `U+1F308` (`RAINBOW`) in its name: zeroflte:/ $ ls -al /sdcard/tmp total 1024 drwxrwx--x 5 root sdcard_rw 4096 2020-07-09 05:44 . drwxrwx--x 49 root sdcard_r...
I have a Galaxy S6 running Android 7.0:
zeroflte:/ $ getprop ro.build.version.release
7.0
There exists a file which uses the Unicode codepoint
U+1F308
(RAINBOW
) in its name:
zeroflte:/ $ ls -al /sdcard/tmp
total 1024
drwxrwx--x 5 root sdcard_rw 4096 2020-07-09 05:44 .
drwxrwx--x 49 root sdcard_rw 4096 2020-06-25 07:27 ..
-rw-rw---- 1 root sdcard_rw 17 2018-04-25 20:47 123.org
drwxrwx--x 2 root sdcard_rw 4096 2020-07-09 05:54 crypt
-rw-rw---- 1 root sdcard_rw 9 2020-07-08 13:26 🌈.gpx
zeroflte:/ $
However, I have no idea how to use this file name in an adb shell command. I would like to apply ls -1 -d -l /sdcard/tmp/\🌈.gpx
or similar, but I cannot enter the RAINBOW
char. Any idea how to do this?
Michael Albinus
(121 rep)
Jul 9, 2020, 10:59 AM
• Last activity: Dec 28, 2020, 02:38 PM
1
votes
3
answers
2387
views
Lengthy sleep command not working in script
I've written a `su.d` script to periodically (every 4 hours) back up data from an app using a looped `sleep` command: #!/system/bin/sh ( # Wait for boot to complete until [ "$(getprop sys.boot_completed)" ] do sleep 300 done while true do ( new_dir="/storage/emulated/0/temp/AppData/$(date '+%Y%m%d-%...
I've written a
su.d
script to periodically (every 4 hours) back up data from an app using a looped sleep
command:
#!/system/bin/sh
(
# Wait for boot to complete
until [ "$(getprop sys.boot_completed)" ]
do
sleep 300
done
while true
do
(
new_dir="/storage/emulated/0/temp/AppData/$(date '+%Y%m%d-%H%M')"
mkdir -p $new_dir
cp /data/data/com.example.app/files/*.json $new_dir
echo "$(date '+%F %T') | app data backup OK!" >> /storage/emulated/0/su.d.log
) &
sleep 14400 # 4 hours
done
) &
In practice, the script backs up the data only after boot—not every 4 hours.
However, if I enter a remote shell via adb
and leave it alone, then the data does get backed up every 4 hours.
How can I force the periodic backup without being permanently connected to a PC? (And why isn't it working as expected?)
---
### EDITS ###
1. @Irfan Latif's comment gave me the idea of trying a different interpreter (busybox ash - #!/system/xbin/sh
), but the result was the same. I'll try @mirabilos's daemonise suggestion (sh -T- -c '...'
) next.
2. Tried @mirabilos's daemonise suggestion with the same result: backs up data only after boot.
3. Tried nohup
:
nohup /system/bin/sh -T- -c '...' >/dev/null 2>&1 &
Same result.
andronoid
(41 rep)
Feb 17, 2019, 03:01 PM
• Last activity: May 5, 2020, 11:33 AM
4
votes
1
answers
819
views
Update mksh to latest version
Android ships with `mksh` as shell, how can I upgrade to latest version (now R57, mine still on R43)? Official site https://www.mirbsd.org/mksh.htm offers to compile from source, anyone building ready to run binaries?
Android ships with
mksh
as shell, how can I upgrade to latest version (now R57, mine still on R43)?
Official site https://www.mirbsd.org/mksh.htm offers to compile from source, anyone building ready to run binaries?
Ju Tutt
(524 rep)
Oct 15, 2019, 02:34 PM
• Last activity: Oct 15, 2019, 04:01 PM
1
votes
1
answers
937
views
How to Check if Script is run once device is booted?
I have a script I need to run once, and only once the phone is booted. I have attempted init.qcom.post_boot.sh, init.sec.boot.sh, debuggerd, and finally mkshrc While my script ran with debuggerd, I found that it ran every time debuggerd ran, which is not something I need to happen... thus when I stu...
I have a script I need to run once, and only once the phone is booted.
I have attempted init.qcom.post_boot.sh, init.sec.boot.sh, debuggerd, and finally mkshrc
While my script ran with debuggerd, I found that it ran every time debuggerd ran, which is not something I need to happen... thus when I stumbled upon
/system/etc/mkshrc
(the other 2 simply did not work)
What I found was, the script runs that one time, on boot... however, it also seems to run every time adb shell
runs, along with (I assume) everytime shell is fired up... which is also undersireable.
So, what can I do in /system/etc/mkshrc
to ensure my call to my script runs only the one time... at boot?
I thought about running a while
loop to check for the getprop sys.boot_completed
if it ==
1 then dump a file somewhere, and through an if
statement inside the looop to check for that file, if exists then exit, if not then run the next command... however, everywhere I am allowed to dump that file, it persists between boots, so that next command
never runs again.
**NOTE**
Does not need root to do this, nor does my script need root to run (yes, I have confirmed)
**CODE**
BB=/system/xbin/busybox
MYPID=/mnt/sdcard/.kev-run
while [ getprop init.svc.bootanim
== "stopped" ] ; do
# if the run file does not exist, and we are stopped
if [ ! -e $MYPID ]; then
# run the scripts, then create the run file
LOG=/mnt/sdcard/Download/kevs-scripts.log
$BB rm -f $LOG;
$BB echo "Launching Kevs Scripts" >> $LOG;
MY_SCRIPT
# write the run file so we aren't running this everytime this file runs
touch $MYPID;
sleep 1;
fi
done
# if we are still booting, delete the run file
while [ getprop init.svc.bootanim
!= "stopped" ] ; do
# we're not done booting, remove our makeshift pid file and sleep a second
$BB rm -f $MYPID;
sleep 1;
done
Seems to be off to me
Kevin
(209 rep)
Feb 28, 2018, 08:39 PM
• Last activity: Mar 1, 2018, 03:14 PM
3
votes
3
answers
1416
views
Work-around for process substitution in mksh
An extremely useful feature of Bash, known as [process substitution](http://tldp.org/LDP/abs/html/process-sub.html), is missing in the Android shell, [mksh](https://www.mirbsd.org/htman/i386/man1/mksh.htm). This is highly unfortunate as it prevent you from doing things like: diff <(sort list1) <(sor...
An extremely useful feature of Bash, known as [process substitution](http://tldp.org/LDP/abs/html/process-sub.html) , is missing in the Android shell, [mksh](https://www.mirbsd.org/htman/i386/man1/mksh.htm) . This is highly unfortunate as it prevent you from doing things like:
diff <(sort list1) <(sort list2)
The mksh site has marked this as a "future plan" [here](https://www.mirbsd.org/mksh.htm#plans) . So my questions is:
**Are there any work-arounds for this?** (And what are they?)
not2qubit
(859 rep)
Mar 7, 2015, 10:52 PM
• Last activity: Apr 3, 2016, 04:28 AM
3
votes
1
answers
1371
views
Shell .profile or /etc/profile for old android 2.3.3
Just rooted my old phone with Android 2.3.3 and I would like to define some aliases for each shell I start (with adb or terminal app). I found [this question][1] where one answer says that `/etc/profile` (=`/system/etc/profile` due to soft link `/etc`->`/system/etc`) is one of the files the shell so...
Just rooted my old phone with Android 2.3.3 and I would like to define some aliases for each shell I start (with adb or terminal app). I found this question where one answer says that
/etc/profile
(=/system/etc/profile
due to soft link /etc
->/system/etc
) is one of the files the shell sources on startup. But this post talks about /system/bin/sh
being a link to /system/bin/mksh
, which is not the case on my 2.3.3 system.
Despite the fact that strings sh
produces /etc/profile
as one output, the file is not sourced.
Does anyone happen to know the old Android version and whether I have a chance to get /etc/profile or some other file sourced on shell startup? I thought it might be a permission problem but even rwxrwxr-x does not help.
Harald
(277 rep)
Sep 5, 2015, 12:58 PM
• Last activity: Apr 2, 2016, 09:08 PM
0
votes
1
answers
1104
views
unexpected root request for mksh when turning wifi on or off
Since today, I see the following root warning when turning wifi on or off: ![enter image description here][1] * Superuser Anfrage / Superuser request: **mksh (1000)** * Angeforderter Benutzer / Requested User: **ROOT (0)** * Befehl / Command: **ip route add 224.0.0.0/4 dev wlan0** My phone is a HTC...
Since today, I see the following root warning when turning wifi on or off:
* Superuser Anfrage / Superuser request: **mksh (1000)**
* Angeforderter Benutzer / Requested User: **ROOT (0)**
* Befehl / Command: **ip route add 224.0.0.0/4 dev wlan0**
My phone is a HTC One V with Android 4.0.3 and SuperSU installed as root app. It was running 8 months without this prompt. My last install was Power Toggles 1 week ago. Does anyone know about this? I'm afraid it's something dangerous...

Daniel Alder
(407 rep)
Feb 25, 2013, 07:42 PM
• Last activity: Apr 2, 2016, 08:51 PM
7
votes
3
answers
13893
views
Can I update the adb shell's environment variables?
I wanted to update the `PATH` environment variable permanently in the **adb shell**. I guessed the shell was `mksh` for I've found `/system/bin/sh` pointing to `/system/bin/mksh`. Then I tried - Making a new file `/data/.mkshrc` and adding the `PATH` definition into it. - Copy the above file into `/...
I wanted to update the
PATH
environment variable permanently in the **adb shell**. I guessed the shell was mksh
for I've found /system/bin/sh
pointing to /system/bin/mksh
. Then I tried
- Making a new file /data/.mkshrc
and adding the PATH
definition into it.
- Copy the above file into /
.
- Copy to /root
.
But all attempts failed.
Shawn Xie
(171 rep)
Sep 17, 2013, 10:02 AM
• Last activity: Apr 2, 2016, 08:50 PM
Showing page 1 of 10 total questions