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

Root terminal commands....

Cool cool. I'm using the new .bashrc file and I am still getting the whoami: unknown uid 10066 {I'm guessing its just my user?, because su returns unknown uid 0 (root i believe)}, but bash does seem to be working for the most part. The only thing that I can think of (based only on reading this thread though) is that I need to type ls $sd instead of ls sd.

Also, I am not getting the colors any more. I'm looking at the file in Notepad ++ to see if anything pops out at me (not that it will lol)


On a side note, does anyone know if the sense camera app will work on aosp roms?
(I do have to agree with you guys about miui looking too much like an iphone, but i'm using adw so it doesn't bother me too much -it's only in the menus now-)
 
Cool cool. I'm using the new .bashrc file and I am still getting the whoami: unknown uid 10066 {I'm guessing its just my user?, because su returns unknown uid 0 (root i believe)}, but bash does seem to be working for the most part. The only thing that I can think of (based only on reading this thread though) is that I need to type ls $sd instead of ls sd.

Also, I am not getting the colors any more. I'm looking at the file in Notepad ++ to see if anything pops out at me (not that it will lol)


On a side note, does anyone know if the sense camera app will work on aosp roms?
(I do have to agree with you guys about miui looking too much like an iphone, but i'm using adw so it doesn't bother me too much -it's only in the menus now-)

Ah, ok, well I was wrong about why it didn't work. Who knows why my typo actually worked. That's kind of funny. Anyway, let's do two things here. First, open the terminal and type whoami, then do the same after typing su and enter. Let me know the exact output for both. As for ls sd, you can't do that. The shopt option only allows you to cd to a variable path, so cd sd works, but ls sd doesn't. Otherwise, you just have to do ls $sd.

As for the camera, I don't know off hand, but my initial response would be that it wouldn't work. You're welcome to try it, though. It really depends on how integrated into the system the particular app is. Some Sense apps rely heavily on the modifications HTC made to Android. Others may not. You can try copying the apk to CM and see if it works. Just make a backup, first.
 
Ah, ok, well I was wrong about why it didn't work. Who knows why my typo actually worked. That's kind of funny. Anyway, let's do two things here. First, open the terminal and type whoami, then do the same after typing su and enter. Let me know the exact output for both. As for ls sd, you can't do that. The shopt option only allows you to cd to a variable path, so cd sd works, but ls sd doesn't. Otherwise, you just have to do ls $sd.

As for the camera, I don't know off hand, but my initial response would be that it wouldn't work. You're welcome to try it, though. It really depends on how integrated into the system the particular app is. Some Sense apps rely heavily on the modifications HTC made to Android. Others may not. You can try copying the apk to CM and see if it works. Just make a backup, first.

Okay...
$ whoami : uid 10066
# whoami: uid 0

Ahh.. yup, that makes sense, cd works!


I tried the htc camera from Myn's last night, but now it just force closes, but I probably did something wrong anyway (I think I just replaced the Camera.apk file the Htc Camera.apk file)

I'll keep trying for a bit. I am looking into the shell scripting tutorials, reading up on some old pdfs I have floating around the hard drive.

Thanks, the bashrc file is really a big time saver, especially with the virtual keyboard we are all using.
 
And I think I only get the Urary operator expected the first time ( when it pops up saying that Terminal Emulator has been granted su permissions.)

su permissions... super missions ?

EDIT:

Nope, I was wrong, I get the urary operator expected everytime I jump to su. Strange.
 
Hah! Okay, so MIUI reports UID 0 (aka root) rather than the actual name of the user. That's funny. I'll have to fix that. Is that the *exact* spelling and case? Can you actually give me a screenshot of what it returned? It's a pretty easy fix.

EDIT: hehe, yeah, it's going to give that error every time .bashrc has to load, so it'll do it when you first open the terminal, and right after you type su. You probably won't get it again unless you exit out of su, then go back again.
 
Hah! Okay, so MIUI reports UID 0 (aka root) rather than the actual name of the user. That's funny. I'll have to fix that. Is that the *exact* spelling and case? Can you actually give me a screenshot of what it returned? It's a pretty easy fix.

EDIT: hehe, yeah, it's going to give that error every time .bashrc has to load, so it'll do it when you first open the terminal, and right after you type su. You probably won't get it again unless you exit out of su, then go back again.
Okay, here's the screen shot. If bash is at /system/xbin/bash, where should the PATH be?

20110501_222232.jpg

(never attached something before, hope it works)
 
Okay, here's the screen shot. If bash is at /system/xbin/bash, where should the PATH be?

View attachment 18075

(never attached something before, hope it works)

Type:

echo $PATH

if you want to see what's in it. I'm sure it includes /system/bin and /system/xbin, at the very least. If you can run bash by just typing bash, then it's definitely there. I'd be extremely surprised if it wasn't. BTW, you can add whatever you want to $PATH in your .bashrc. There's little need to in Android, but it's a common practice in a normal Linux environment.

Anyway, is that you typing whoami, or is that output after loading the terminal and typing su? What happens if you actually type "whoami" from the terminal, yourself?

EDIT: I think whoami is a bit confused here. Let me know what happens when you actually run "whoami"
 
Type:

echo $PATH

if you want to see what's in it. I'm sure it includes /system/bin and /system/xbin, at the very least. If you can run bash by just typing bash, then it's definitely there. I'd be extremely surprised if it wasn't. BTW, you can add whatever you want to $PATH in your .bashrc. There's little need to in Android, but it's a common practice in a normal Linux environment.

Anyway, is that you typing whoami, or is that output after loading the terminal and typing su? What happens if you actually type "whoami" from the terminal, yourself?

EDIT: I think whoami is a bit confused here. Let me know what happens when you actually run "whoami"

Damn, looks like I snapshot the wrong thing!
Here ya go.
20110501_223936.jpg
 
Damn, looks like I snapshot the wrong thing!
Here ya go.
View attachment 18076

Interesting. I suppose I can work with that, but can you really quickly just run this for me:

where whoami
whoami -h

EDIT: here is a temporary fix that will at least get rid of the error, and show the green highlight for all users (normal and root just like it does now). I'll fix it to show yellow when you're root later. It shouldn't be a hard fix.
 

Attachments


Okay, well you have a slightly different version of busybox than me. I don't know if it's has something to do with that version of busybox or MIUI's implementation. I can't tell without doing some testing. So, I'll go ahead and make a version that can detect both kinds of output. I might not have it ready until tomorrow. Until then, go ahead and use the version I posted above. That will just show the green highlight for all users, but without the error.
 
Okay, well you have a slightly different version of busybox than me. I don't know if it's has something to do with that version of busybox or MIUI's implementation. I can't tell without doing some testing. So, I'll go ahead and make a version that can detect both kinds of output. I might not have it ready until tomorrow. Until then, go ahead and use the version I posted above. That will just show the green highlight for all users, but without the error.

Cool, works great. The error message is gone, and the color really isn't a big deal, so no rush on that. Again, this is a huge time saver, especially the sr and sw aliases, huge time saver.

(I actually have been turning the phone off, booting into recovery and mounting system through amon ra becasue I could never remember the exact command for that)
:/
 
Cool, works great. The error message is gone, and the color really isn't a big deal, so no rush on that. Again, this is a huge time saver, especially the sr and sw aliases, huge time saver.

(I actually have been turning the phone off, booting into recovery and mounting system through amon ra becasue I could never remember the exact command for that)
:/

Hehe, yeah it's not an easy one to remember. How would mounting it in recovery help? That just mounts it while you're boot in recovery. It shouldn't stick once you boot up. I'm glad you're actually using this and its helpful :). I'll try to get it fixed so the color changes for you. I'm sure you're not the only one who could have this problem. If my make any more modifications, I'll be sure to post an update here.
 
Hehe, yeah it's not an easy one to remember. How would mounting it in recovery help? That just mounts it while you're boot in recovery. It shouldn't stick once you boot up. I'm glad you're actually using this and its helpful :). I'll try to get it fixed so the color changes for you. I'm sure you're not the only one who could have this problem. If my make any more modifications, I'll be sure to post an update here.

Yeah, well that was the thing. Anytime I would ADB something, I'd boot into recover first, so I could mount /system. Talk about wasting time. I'm sure I'll find some way to remember it. >.>

I went into n++ and tried changing the line ...
Code:
`whoami` == "root"
to
Code:
 `whoami` == '0'
but that didn't work. I figured I didn't want the back quotes cuz 0 isn't a command and I figured that the double quotes would be wrong (but I am still just making echo scripts right now ..total noob...)
Even if it did work, it would probably only work for this one issue. Eh... I'll go back to my echo "Today is `date`" scripts. lol
 
Yeah, well that was the thing. Anytime I would ADB something, I'd boot into recover first, so I could mount /system. Talk about wasting time. I'm sure I'll find some way to remember it. >.>

I went into n++ and tried changing the line ...
Code:
`whoami` == "root"
to
Code:
 `whoami` == '0'
but that didn't work. I figured I didn't want the back quotes cuz 0 isn't a command and I figured that the double quotes would be wrong (but I am still just making echo scripts right now ..total noob...)
Even if it did work, it would probably only work for this one issue. Eh... I'll go back to my echo "Today is `date`" scripts. lol

Ah, ok, I see what you were doing :). If you're using adb, and you need to change something in /system, you can just run:

adb remount

That should take care of it. Anyway, this is very handy, too :). I got so tired of typing out that long command (or leaving the terminal and coming back) which is why I made that alias.

Anyway, that won't quite work for the modification, but you can definitely learn things by tinkering with scripts. I encourage you to play around with it. Anyway, what we're doing is something called process substitution. It means that you're taking the results of a command, and using it in place of that command.

So, when I say:

$variable = `whoami`

$variable would contain a string containing the current username. Now, if I tried to run:

`whoami`

it would literally be trying to run a command with the name of the user, which wouldn't do anything. In your case, the output from whoami is this exact string:

"whoami: unknown uid 0"

When you're root. So, we're doing a comparison here. It looks like this:

[ `whoami` == "root" ]

Here's the first problem with that. Since the string is more than just one word, it get's all #$%ed up, and bash gets confused. A good way around that would be to do:

WHOAMI=`whoami`
if [ "$WHOAMI` == "root" ];then ...

Now, that will make the silly error go away, but it still won't work in your case. replacing "root" with "0" won't work either. The reason is that the variable $WHOAMI contains that particular string. So, if we wrote it out, expanding the actual variable, the comparison would look like this:

if [ "whoami: unknown uid 0" == "root" ];then ...

As you can see, those two aren't even remotely the same, so it will always do what's under the else. Before, it just got confused, threw the error, then did what was under the else.

Now, to fix it, it's going to take some string manipulation. What needs to happen is the uid (just the number) needs to be extracted, then compared. It isn't too complicated to do that, but it will take a tad more work. Feel free to play around with it, though :). The easiest thing to do will probably be to use sed (or awk).
 
Ahh okay. Yeah I'll definitely be looking around with it.
Googleing sed and awk right now lol

By the way, when I adb shell, then ls, all my results are like this...

[1;34macct(arrow < that way)[0m

any idea about that? lol
 
Ahh okay. Yeah I'll definitely be looking around with it.
Googleing sed and awk right now lol

By the way, when I adb shell, then ls, all my results are like this...

[1;34macct(arrow < that way)[0m

any idea about that? lol

Oh, that's funny. I don't have adb set up on this computer, anymore, but if you run adb shell, what happens if you run this:

echo $SHELL

If is says bash, then...well...that's weird. If it says sh, then just run bash. That's weird that it knew to use your .bashrc. Basically, sh can't interpret the codes in PS1 meant for bash, which is what I'm guessing the problem.
 
Oh, that's funny. I don't have adb set up on this computer, anymore, but if you run adb shell, what happens if you run this:

echo $SHELL

If is says bash, then...well...that's weird. If it says sh, then just run bash. That's weird that it knew to use your .bashrc. Basically, sh can't interpret the codes in PS1 meant for bash, which is what I'm guessing the problem.
I actually get nothing..?

Code:
# echo $SHELL
echo $SHELL

#


And the id -u == 0 didn't work.

Code:
[~]$ su
bash: [: too many arguments
[~]#
 
1) Okay, what happens if you just run bash?
2) id -u doesn't work because the output isn't *exactly* "0", and it still has too many actual strings, so it can't be used that way (at least, without quotes to make it one string). You're close, though :). The output of that is a little easier to parse than that weird output from whoami. We can probably use this.
 
1) Okay, what happens if you just run bash?
2) id -u doesn't work because the output isn't *exactly* "0", and it still has too many actual strings, so it can't be used that way (at least, without quotes to make it one string). You're close, though :). The output of that is a little easier to parse than that weird output from whoami. We can probably use this.

1. I actually get the same thing as I get on my phone with bash (the whole bash [: too many arguments thing, but unlike my phone, it also displays the weird PS1 related characters.

2. Ahh, that makes me kinda happy, being a bit closer. I was testing it on a vm, just typing in some commands (actually trying whoami | wc -? something I forget now, but that wasn't even close.), but the id -u for my account gave 1000, but for su gave 0 so i thought i must be kinda close... And I stumbled upon that (id -u ) from the whoami help, I love help files.
 
1. I actually get the same thing as I get on my phone with bash (the whole bash [: too many arguments thing, but unlike my phone, it also displays the weird PS1 related characters.

2. Ahh, that makes me kinda happy, being a bit closer. I was testing it on a vm, just typing in some commands (actually trying whoami | wc -? something I forget now, but that wasn't even close.), but the id -u for my account gave 1000, but for su gave 0 so i thought i must be kinda close... And I stumbled upon that (id -u ) from the whoami help, I love help files.

1. Okay, that's really weird. I guess adb shell doesn't like that too much :). We can probably find a way to detect that it's adb, and to display something else for the prompt. For the time being, if it annoys you, when you go to adb shell, just run this:

PS1=\$

That ought to take care of it.

2. Yep, I love help files as well :). It doesn't exist on android, but if you're in a Unix/Linux setup, the man command is your friend. Anyway, I'm going to guess you ran wc -l. What that does is count the number of lines in a file. When piped to (command|wc -l) it will count the number of lines in the output passed to it. Likely, you just got 1. Anyway, I'm not sure how id reacts in normal Linux (I'll have to check that out; id -u probably does something similar to what we want), but in android it just shows all (uid and gid) with output that is a little more than we want. That being said, I threw together a quick hack to get the output we want, and it seems to work on my phone. Please try the attached file and let me know if it works.
 

Attachments

1. Okay, that's really weird. I guess adb shell doesn't like that too much :). We can probably find a way to detect that it's adb, and to display something else for the prompt. For the time being, if it annoys you, when you go to adb shell, just run this:

PS1=\$

That ought to take care of it.

2. Yep, I love help files as well :). It doesn't exist on android, but if you're in a Unix/Linux setup, the man command is your friend. Anyway, I'm going to guess you ran wc -l. What that does is count the number of lines in a file. When piped to (command|wc -l) it will count the number of lines in the output passed to it. Likely, you just got 1. Anyway, I'm not sure how id reacts in normal Linux (I'll have to check that out; id -u probably does something similar to what we want), but in android it just shows all (uid and gid) with output that is a little more than we want. That being said, I threw together a quick hack to get the output we want, and it seems to work on my phone. Please try the attached file and let me know if it works.

Hmm, well the PS1=\$ is doing anything for me, but should I just be running it form the adb shell prompt?
Yeah, man files have been doing almost as much of my homework help this last semester as google has lol.

Well, id -u is giving me 0 for root, but I'm testing it on some scripts, I guess that feature is just a bit too advanced for me at this point lol (thought I'd make a script to check uid and if 0 display the word root, if not display something else, some sort of insult). I'll keep following these tutorials and pdf files until I get it.

I am going to try and switch my terminal emulator back to /bin/sh and see if that clears up adb. I don't really use adb much, so it's not a big issue.
 
Hmm, well the PS1=\$ is doing anything for me, but should I just be running it form the adb shell prompt?
Yeah, man files have been doing almost as much of my homework help this last semester as google has lol.

Well, id -u is giving me 0 for root, but I'm testing it on some scripts, I guess that feature is just a bit too advanced for me at this point lol (thought I'd make a script to check uid and if 0 display the word root, if not display something else, some sort of insult). I'll keep following these tutorials and pdf files until I get it.

I am going to try and switch my terminal emulator back to /bin/sh and see if that clears up adb. I don't really use adb much, so it's not a big issue.

Yes, you're on the right track. Where are you testing, though? Are you using Linux? I'm sure id -u does what you want, but it doesn't work in Android, or at least not with the version of busybox that I have. I just displays the same thing as id, without any arguments. Did you try the other bashrc that I uploaded? I kinda hacked it together, but it worked for me, and it uses id instead of whoami.

As for PS1, yeah, run that from adb shell. It should change your prompt into something slightly more readable (just the $ for normal user and # for root). What is the shell you're first using after you run adb shell, in the first place? I would think it'd still be sh, not bash.

EDIT: If id -u did what you're saying (displays 0 for root or some other number for other users), this is what I'd do:

Code:
if [ `id -u` == 0 ];then
    echo "root"
else
    echo "some other user"
fi

My guess though, is that it would still have a string that looks like this:

uid=0(root) or uid=0

or something like that. I'll be in front of a real linux box tomorrow to test that. Until then, it doesn't work quite right in Android, hence my silly little hack. It does seem to work, though. Try it out (the bashrc I posted a few posts up) and let me know if it works. If it does, I suggest you take a look at what I did. When I was learning all this stuff, I found that reading real script was the best way to learn things. Tutorials are wonderful, but seeing how this stuff is used practically is the best way to learn, in my opinion. That being said, my fix is sort of a weird hack, and it can probably be done in a cleaner way.
 
Back
Top Bottom