Issue
I would like to check whether a directory exists on the SD card of an Android device using Bash.
I am aware that a similar question was answered here: href="https://stackoverflow.com/questions/59838/how-to-check-if-a-directory-exists-in-a-bash-shell-script">How can I check if a directory exists in a Bash shell script?
The difference is that when I do
if [ -e /sdcard/myDir ]; then
# magic
fi
it is checked whether /sdcard/myDir exists on my computer and not on the phone. How can I check if the folder exists on the phone?
Solution
If I understood you correctly try:
adb shell
... and then type your shell commands on the device. I'm not really sure if bash is available on standard Android device. I'd bet that there are only simple busybox tools installed.
Also note, that there is very limited set of directories that you will be able to access this way on non-rooted device.
UPDATE:
More precisely, if you need to execute some kind of shell script on the remote device, first prepare the script, say foo.sh
and then execute:
adb push foo.sh /sdcard/
adb shell sh /sdcard/foo.sh
That should do the trick.
Answered By - pkk Answer Checked By - Dawn Plyler (WPSolving Volunteer)