FORUMS
Remove All Ads from XDA

Is there a .bashrc equivalent for android?

35 posts
Thanks Meter: 2
 
By cyricc, Member on 12th May 2009, 09:02 AM
Post Reply Email Thread
See title. Mostly I just want to have some aliases set every time I open terminal emulator or adb shell. Does anyone know if this is possible?
 
 
12th May 2009, 10:28 AM |#2  
Member
Flag Nanjing
Thanks Meter: 0
 
More
Just dig /init.rc then you may find the way.
12th May 2009, 12:13 PM |#3  
OP Member
Thanks Meter: 2
 
More
Quote:
Originally Posted by biAji

Just dig /init.rc then you may find the way.

I don't think that works, init.rc looks like it's executed on boot... I'm looking for a file that executes every time a shell is started.
9th June 2009, 10:57 AM |#4  
Junior Member
Flag Perpignan
Thanks Meter: 0
 
More
Hi there,
I'm wondering the same thing.
I've tried to create a bashrc
(/.bashrc ; /system/etc/bash.bashrc ; /root/.bashrc ) But none is working.

I'm about to try a different way,
I've cp /system/bin/sh to /system/bin/sh1
then I'll try to replace /system/bin/sh by a shell script that will launch my aliases then sh1

Something like:
Code:
#!/system/bin/sh1
alias  lsa='ls -Alh '
[...]
/system/bin/sh1
But i'm not pretty sure It could work properly. Firstly because I remember a gain-super-user manipulation that requires to copy and modify rights on sh. (but it could be ok if the script and the copy of sh have the same rights).
Secondly, because I'm not really OK with this; When I'll remove /system/bin/sh in order to replace it, I'll have no shell for a time (if it crashes, I'll not be able to use sh anymore, even with adb).

So if anybody have an other solution it could be damn cool
Thank you all

EDIT: I've just tried this. It's ok, I've not lost my shell, but the modifications (one alias, and a path export), are not applied.
9th June 2009, 02:33 PM |#5  
Account currently disabled
Thanks Meter: 99
 
More
There is no such file. In fact, the default shell is sh, not bash.

However, there is a solution. Read my post in this thread: http://forum.xda-developers.com/showthread.php?t=518959
9th June 2009, 02:38 PM |#6  
Senior Member
Thanks Meter: 1
 
More
Quote:
Originally Posted by lbcoder

There is no such file. In fact, the default shell is sh, not bash.

However, there is a solution. Read my post in this thread: http://forum.xda-developers.com/showthread.php?t=518959

That is interesting. I'll have to try it. I assume it won't work with ADB? Or am I wrong (please say yes)?
9th June 2009, 07:12 PM |#7  
Account currently disabled
Thanks Meter: 99
 
More
I would have thought that it would work with adb, but when I try this:
adb shell /path/to/bash --rcfile /path/to/bashrc
it seems that its a 1-way shell...

well you can always run bash after connecting....
adb shell
/path/to/bash --rcfile /path/to/bashrc

Alternatively, with a little bit of craftiness, you may be able to replace the sh binary with a script that runs bash.
9th June 2009, 07:21 PM |#8  
Senior Member
Thanks Meter: 1
 
More
Sweet, can't wait until I get home.
9th June 2009, 07:32 PM |#9  
Senior Member
Flag Austin,TX
Thanks Meter: 98
 
More
The best way, and what a lot of the ROM devs are doing now is putting a check/call to /system/init.rc and /data/init.rc so we can add our own customizations. This would include boot time chmod/chowns or aliases if need be. Hell we could put a call to /etc/.profile if we wanted and put all our aliases in there. But we can't do any of that till ROM devs put that call in boot.img->boot.ramdisk->init.rc
15th March 2015, 07:52 PM |#10  
alanthehat's Avatar
Member
Thanks Meter: 10
 
More
Sign
Android's default shell /system/bin/sh is a link to mksh in the same directory. It reads /system/etc/mkshrc & ~/.mkshrc
I think it also reads ~/.profile & /etc/profile but I'm not sure & I don't know what order.
See https://www.mirbsd.org/mksh.htm for the documentation.

Also worth noting is that most, if not all, shells read /etc/profile & ~/.profile so anything in there should be very general.
The Following User Says Thank You to alanthehat For This Useful Post: [ View ] Gift alanthehat Ad-Free
14th June 2015, 07:36 PM |#11  
elfaure's Avatar
Senior Member
Flag San Francisco Bay Area
Thanks Meter: 107
 
More
Wink Yes there is
Quote:
Originally Posted by lbcoder

There is no such file. In fact, the default shell is sh, not bash.

However, there is a solution. Read my post in this thread: http://forum.xda-developers.com/showthread.php?t=518959

Edit /system/etc/mkshrc. You can add your aliases there after the defaults. Type 'alias' from the terminal to see the default aliases that are defined in this file. I believe this file is the master, and when a shell is envoked, the mksh command pipes a hidden copy of this file into the users home directory as .mkshrc for the terminal session.

Also, this is the file to edit to append to your $PATH.
Attached Thumbnails
Click image for larger version

Name:	Screenshot_2015-06-14-11-47-23.jpg
Views:	750
Size:	163.7 KB
ID:	3362689  
The Following 2 Users Say Thank You to elfaure For This Useful Post: [ View ] Gift elfaure Ad-Free
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes