• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Root terminal commands....

Okay, I'm back. Thanks akaza for that tasker info, I'll definitely look into it. Also looking into ncurses, because I reflashed MIUI, no restore. Still no libncurses.so, so I'm thinking, make a backup, push the file, and chmod it.

I just couldn't give up the awesome notification toggles from miui. I am also digging through a backup on my comp to see if I can find that file and maybe just use it on other roms.

I'll get back to you guys if I get this bash stuff working.
 
Upvote 0
Okay, I'm back. Thanks akaza for that tasker info, I'll definitely look into it. Also looking into ncurses, because I reflashed MIUI, no restore. Still no libncurses.so, so I'm thinking, make a backup, push the file, and chmod it.

I just couldn't give up the awesome notification toggles from miui. I am also digging through a backup on my comp to see if I can find that file and maybe just use it on other roms.

I'll get back to you guys if I get this bash stuff working.

Give me some time to look into it. I've never actually used MIUI. We might need to talk to novox. I seem to recall him talking about getting bash working, and I'm pretty sure he's a MIUI user. Otherwise, if it's notification toggles you want, CM7 has those, too.
 
Upvote 0
Give me some time to look into it. I've never actually used MIUI. We might need to talk to novox. I seem to recall him talking about getting bash working, and I'm pretty sure he's a MIUI user. Otherwise, if it's notification toggles you want, CM7 has those, too.

Okay, I'm digging through it now (thanks to your Read/Copy thread), and I've come across /etc/bash/ directory, but it looks like it just has bash_logout and bashrc in it....

Okay, enough digging, I'm gonna push that file now.

Mulit tasking too much.
 
Upvote 0
Okay, I'm digging through it now (thanks to your Read/Copy thread), and I've come across /etc/bash/ directory, but it looks like it just has bash_logout and bashrc in it....

Okay, enough digging, I'm gonna push that file now.

Mulit tasking too much.

/etc generally contains system config type stuff. Bash itself should be in either /system/bin/ or /system/xbin, as far as Android is concerned.
 
Upvote 0
/etc generally contains system config type stuff. Bash itself should be in either /system/bin/ or /system/xbin, as far as Android is concerned.
MIUI has it in /system/xbin, I'm hoping that the adb push works this time.

updating...

Phone is rebooting now...
checking on libncurses.so
Looks like it is working!
From term I typed bash and the prompted changed from $ to app_66@localhost / $

And, if anyone else is having this issue, here's what I did (based on advice throughout this thread)

from adb
adb push libncurses.so /system/lib
adb shell
cd /system/lib
chmod 644 libncurses.so
ls -l libncurses.so

from term
which bash
bash
bash --rcfile /sdcard/bashrc

--- Okay, form there I got this message (probably most useful for akaza, and the post where he asked to see if the bashrc file worked for the rest of us
WhoAmI: unknown uid 10066
bash: [: =: unary operator expected
[~]$
 
  • Like
Reactions: akazabam
Upvote 0
Thanks for the update. Glad to know it worked that second time around. Maybe it was a permissions issue before or something. In any case, that error you're getting is due to a typo in my .bashrc. To be honest, I'm surprised it worked at all for me. The version of bash I have must have figured out what I meant. In any case, try the one I've attached.

EDIT: Oh, and make sure to rename it to .bashrc :).
 

Attachments

  • bashrc.txt
    1.1 KB · Views: 56
Upvote 0
Meh you should try it at least once. Though my sd card fried while on it so I'll never go back :)

Lol. I don't see how a ROM could actually fry your sdcard, unless there was some low level corruption, some how, which is pretty unlikely. Either way, if I wanted my phone to look like an iphone, I'd have bought an iphone. Yeah, I said it :p.
 
Upvote 0
Lol. I don't see how a ROM could actually fry your sdcard, unless there was some low level corruption, some how, which is pretty unlikely. Either way, if I wanted my phone to look like an iphone, I'd have bought an iphone. Yeah, I said it :p.


I wasn't blaming it just bad memories lol. Also I hate the iphone look, I changed the theme IMMEDIATELY.
 
Upvote 0
Lol, yes you are. I'll go ahead and explain what exactly happened (probably - assuming it does work for everyone now). Either way, it was a mistake, and I'll explain it briefly. I'll also go over a few things I forgot to mention earlier.

So, one very important thing to understand when dealing wit the command line is that if you're executing action commands (commands that are going to do something, such as cp, mv, etc.), if the command is successful, you'll almost never get output. It's generally understood that no output means a command was successful. Of course, if you're running a command that is suppose to give you output (e.g. ls, cat, etc.) and you get no output, then there is a problem. Generally speaking (but not always) if there is a problem with either of those types of commands, though, you'll get some kind of error. Take a commonly used one, for example, that we use with Android (it's dangerous in a normal Linux system) - su. When you type su, if it worked, you get no output. Granted, since you're changing users, it changes the prompt, but the fact of the matter is, if it worked, you go no output. Contrast that with when it doesn't work. You get a permission denied error. Generally, an error will be somewhat descriptive. Of course, some commands have the option to be "verbose" which means give output even when successful or not successful.

So, since relying on output isn't *always* successful, bash has something called return codes. A return code (also called an exit status) is a number between 0 and 255 that basically means that a command either ran successfully or didn't, and why. In bash, specifically, a return code of 0 means that the command ran successfully. Any other number means it wasn't successful, and since there are many options, there is usually a reason that can be determined by the number. Here[/URL is a list of reserved return codes. So, this return code is not something you normally see. When you execute a command, you have to actually "ask" for the return code if you want to see it. The last return code is stored in a variable called $?. To see the contents of a variable from the command line, you use "echo", so you can type:

echo $?

And that will tell you the return code of the last executed command. This variable can also be placed in your $PS1 variable, which means you can always see the return code of the last executed command. If anyone is interested in that, I'll make the change to the .bashrc file, and you can see what it looks like. So, go ahead and try it some time. Type these commands:

ls
echo $?

The output from the second command will be 0, as it's almost impossible for the ls command to be unsuccessful when run without arguments. Now try this:

ls 345q345e45qeasdqertAWF
echo $?

Assuming that first command is running ls on a directory or file that doesn't exist, it will fail. If you run that second command, you'll get a number other than 0.

This concept is actually used heavily in bash scripting, where you don't always want the output of a command to go to the screen, but you want to make a decision based on whether or not the command was successful. You can use a kind of IO redirection that will send output to nowhere, basically, then use the return status to make a decision. That is getting a bit complicated, though. I'll start with something a little simpler.

Let's take this part of my .bashrc for example:


This is a typical if/then/else statement. It's pretty simple, and it needs no explanation if you know even the smallest amount of programming. It means, if these conditions are met, do this; otherwise, do something else. In this case, we're using these brackets "[]". In bash, these are used for comparisons. So, let's take a slightly simpler command:

[ $TEST == 1 ]

Assuming you have a variable defined that is named $TEST, this command will be a comparison, which means, does $TEST equal 1? If you ran that from the command line, you'd get no output, as this is designed to be quiet. You would, however get a return code. If $TEST did equal 1, the return code would be 0. If not, it would be 1. An if statement is designed to execute the part right after "then" if the return status from the condition is 0, or the part under "else" if the return status was 1. So, in the case above, if the user is root, it runs the part that makes the prompt a certain color and makes the home directory /. If the return status was 1, meaning you're not root, it runs the part under else, which will make the color something else, and make the home directory /sdcard.

So, if you're wondering what the mistake was that I made, I used an assignment operator instead of the comparison operator. What that means is, is that the "=" is used to assign a value to something (usually a variable). A "==" is used to compare already set values, which can be variables. That shouldn't have worked at all, so who knows why it didn't throw an error for everybody.


So, you'll start finding that as you start using things like what is described above that you want to run multiple commands from the command line (or even from a bash script, which basically runs a bunch of commands from a prewrtten script). This is the most basic way to do that, as an example:

ls;cat somefile

That will run two commands, one right after the other. It will run ls, then it will cat that file. It's nice for you, because you only ran one thing from the command line, and only had to hit enter once. This can be useful for a number of reason, but let's say for example that you only want to run the second command if the first one was successful. For example, if you want to copy a file, then only cat the file in the new location if it successfully copied, you could run this:

cp /sdcard/somefile /sdcard/directory/somefile && cat /sdcard/directory/somefile

That attempt to copy the file. If it successfully copies, it then cats the file. If it's not successful, it does nothing. The "&&" is basically an operator that means, if the return status of the previous command is 0, continue. It basically mean AND. This can be used to combine comparison operators, too, to say if some condition is true AND some other condition is true, then do something. Sometimes you want to do the opposite, and only do something if another command failed. So, you could say:

cp /sdcard/somefile /sdcard/directory/somefile || echo "failed!!"

That would try to copy the file, then return nothing if it did, or print the output "failed!!" to the screen if it didn't work. It's using the || operator, which means OR. If the return status is anything BUT 0, it will continue with everything after the "||".
 
Upvote 0
Quick exercise for you.

I'm trying to rename the bootanimation.zip file in /system/media.

mv bootanimation.zip bootanimation2.zip

I get mv: can't rename bootanimation.zip : read-only file system.

I try to make a permissions change.
chmod 755 bootanimation.zip

And I get something of the same.
chmod: read-only file system.

There's a difference between how a file system is mounted (read-only or read/write) and the permissions for the file/directory itself. In this case, /system is a mounted partition that has been mounted in read-only mode so that you cannot write to it, despite you having root and having permissions to modify the file. You must remount /system as rw before you can make changes to files in /system. It's like that so that you don't break something :). Of course, I'm sure you know to make backups before changing things there ;).

If you're downloaded my .bashrc and set it up the way I described, you can simply run this command, first:

sw

If you haven't set up .bashrc, run this:

mount -o remount,rw -t yaffs2 /dev/block/mtdblock4 /system

Then, you can rename to your heart's content (just don't break anything ;)). You shouldn't need to do chmod, first, as the permissions are probably fine. You'd have gotten a permission denied error if that was the problem, but that wouldn't make sense. In order to copy a file to the same location, you need read permission on the file, and write permission to the directory, both of which you have with root. It'd be a big problem if you didn't.
 
  • Like
Reactions: geewhiz
Upvote 0
Woot woot. Nah I haven't gotten to bash on this thing yet.

Would the following put things back to normal when I'm done?

mount -o remount,ro -t yaffs2 /dev/block/mtdblock4 /system

Yep! It's good practice to remount /system as ro once you're done. There is an app in the market that will do it with the press of a button (the name of the app escapes me at the moment), or you can just run that command from the terminal. A reboot will take care of it, as well.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones