How to execute Shell script in android

1,880 views
Skip to first unread message

Vikas KM

unread,
Apr 9, 2012, 8:20:40 AM4/9/12
to android-porting, andro...@googlegroups.com, andro...@googlegroups.com
Hi All,

I want to execute a shell script in android

*************** SHELL SCRIPT ********************

 if [ ! -d "/sys/devices/platform/ehci-omap.0/usb1/1-2/1-2.4" ]; then
    if [ -d "/sys/devices/platform/ehci-omap.0/usb1/1-2" ]; then
        NUMINTERFACE=`cat /sys/devices/platform/ehci-omap.0/usb1/1-2/bNumInterfaces`
    fi
 fi

********************************************************

That is based on the path if it exists, I want to run another script...

But i m unable to run the below script any idea what might be wrong?

I have root shell...


# sh ($PATH)/script_name.sh   Command i m using.


--------------
Regards

Vikas KM

Cheryala Venu Madhav

unread,
Apr 9, 2012, 4:15:37 PM4/9/12
to vikk...@gmail.com, android-porting, andro...@googlegroups.com, andro...@googlegroups.com
You can add this as part of your init scripts

ex: add it in init.rc or some other init scripts. it should work.

thanks
Venu




--
Thanks
Venumadhav

Chris Stratton

unread,
Apr 19, 2012, 3:57:04 PM4/19/12
to andro...@googlegroups.com, android-porting, andro...@googlegroups.com
On Monday, April 9, 2012 8:20:40 AM UTC-4, Vikas KM wrote:
I want to execute a shell script in android

*************** SHELL SCRIPT ********************

 if [ ! -d "/sys/devices/platform/ehci-omap.0/usb1/1-2/1-2.4" ]; then
    if [ -d "/sys/devices/platform/ehci-omap.0/usb1/1-2" ]; then
        NUMINTERFACE=`cat /sys/devices/platform/ehci-omap.0/usb1/1-2/bNumInterfaces`
    fi
 fi

********************************************************

That is based on the path if it exists, I want to run another script...

But i m unable to run the below script any idea what might be wrong?

Various things... but it's likely not relevant.

Take a step back and tell us what you are trying to accomplish.  It appears you are trying to create a shell variable or modify an environment variable based on the existence of a file.  Unless you are doing system programming (in which case you should be asking on android-porting) that's note really an android way of doing things and would be pointless anyway as the variable would not propagate anywhere.  On android, whatever app needs to know this information should be finding it out via an android-style ipc or property mechanism, or simply doing the checking itself.

Vikas KM

unread,
Apr 20, 2012, 3:57:16 AM4/20/12
to android-porting
Hi,

Works with busybox..

Any other way of doing this without buybox..


--------------
Regards

Vikas KM


On Fri, Apr 20, 2012 at 1:59 AM, Ivo Topchev <ivo.t...@gmail.com> wrote:
Install busybox and it does most of the scripts, Google it and you will see what are the steps. 
Ivo


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/UZF3Z1ua_awJ.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Chris Stratton

unread,
Apr 20, 2012, 1:46:23 PM4/20/12
to android...@googlegroups.com
On Friday, April 20, 2012 3:57:16 AM UTC-4, Vikas KM wrote:
Hi,

Works with busybox..

By itself what you have posted accomplishes nothing, so the fact that it runs is of little importance

Any other way of doing this without buybox..

As I said before, tell us what you are trying to accomplish, and we can discuss alternatives - writing in a way that will work with toolbox, writing a small executable, etc...

You might try browsing around on the device and see if you can find how things similar to what you want to accomplish are accomplished.

IssamuX _

unread,
Apr 20, 2012, 3:38:57 PM4/20/12
to cs0...@gmail.com, android...@googlegroups.com

Alvin Wong

unread,
Apr 21, 2012, 9:36:03 PM4/21/12
to android-porting
Hi,

If you're using it in init, perhaps you can check init.goldfish.rc and
system/etc/init.goldfish.sh? It's there in every build and is an
example of shell scripts.

Perhaps you are missing a shebang?

On 4月9日, 上午8時20分, Vikas KM <vikki...@gmail.com> wrote:
> Hi All,
>
> I want to execute a shell script in android
>
> *************** SHELL SCRIPT ********************
>
>  if [ ! -d "/sys/devices/platform/ehci-omap.0/usb1/1-2/1-2.4" ]; then
>     if [ -d "/sys/devices/platform/ehci-omap.0/usb1/1-2" ]; then
>         NUMINTERFACE=`cat
> /sys/devices/platform/ehci-omap.0/usb1/1-2/bNumInterfaces`
>     fi
>  fi
>
> ********************************************************
>
> That is based on the path if it exists, I want to run another script...
>
> But i m unable to run the below script any idea what might be wrong?
>
> I have root shell...
>
> *# sh ($PATH)/script_name.sh*   Command i m using.
Reply all
Reply to author
Forward
0 new messages