LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Mobile
User Name
Password
Linux - Mobile This forum is for the discussion of all topics relating to Mobile Linux. This includes Android, Tizen, Sailfish OS, Replicant, Ubuntu Touch, webOS, and other similar projects and products.

Notices


Reply
  Search this Thread
Old 08-31-2022, 08:49 PM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,434

Rep: Reputation: 110Reputation: 110
What is the shell on my phone?


I installed an SSH server on my Android phone. I can ssh into it. Cool.

Then I wanted to get a list of files and directories and typed 'ls' of course.
It works, but I definitely prefer the output of 'ls -la'...

which also works, but I am used to having 'ls -la' aliased to 'ls' so I just have to type 'ls'. We're all lazy, aren't we?

So I tried this:
$ alias ls='ls -la'

It works, but only during that session. If I log out and log in again, the alias has been lost.

OK. The app's documentation says it supports a .profile file, but that is not working. I don't get the alias when I log in. Even explicitly running 'sh .profile' doesn't work.

But that doesn't matter so much anymore. Now I am more curious about other things.

First, what shell is my phone running?
$ echo $SHELL
/system/bin/sh

Not very informative. Any ideas about how I can make this shell identify itself?

Second, I can type letters, tab-tab and find some available commands. But not all of them are listed by tab-tab. For example, m tab-tab gives me no output (other letters do), but the mkdir command is available. I know, I tested it. So what other commands are available? How can I find out what they are? Looks like I am back to the first question, what shell is my phone running?

Thank you for any pointers.
 
Old 09-01-2022, 12:25 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
Code:
sh --version
or something similar the "usual" way.
from the other hand 'sh .profile' cannot work because that will process that .profile in another shell (which will be immediately closed after reading .profile). You ought to use
Code:
source .profile
instead.
 
1 members found this post helpful.
Old 09-01-2022, 08:35 AM   #3
rkelsen
Senior Member
 
Registered: Sep 2004
Distribution: slackware
Posts: 4,474
Blog Entries: 7

Rep: Reputation: 2573Reputation: 2573Reputation: 2573Reputation: 2573Reputation: 2573Reputation: 2573Reputation: 2573Reputation: 2573Reputation: 2573Reputation: 2573Reputation: 2573
What is the shell on my phone?

AFAIK, Android uses a cut-down version of ksh... it's quite limiting.

If you can get a busybox binary for your phone, it might have bash built in.
 
1 members found this post helpful.
Old 09-01-2022, 09:08 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,628

Rep: Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557

Searching for "android shell" reveals that it used to be Almquist (ash) and is now MirBSD Korn Shell (mksh)
Quote:
Originally Posted by https://android.googlesource.com/platform/system/core/+/master/shell_and_utilities/README.md
Since IceCreamSandwich Android has used mksh as its shell. Before then it used ash (which actually remained unused in the tree up to and including KitKat).

Initially Android had a very limited command-line provided by its own “toolbox” binary. Since Marshmallow almost everything is supplied by toybox instead.

Quote:
Originally Posted by rkelsen View Post
If you can get a busybox binary for your phone, it might have bash built in.
Huh? Busybox does not have Bash built-in.

 
1 members found this post helpful.
Old 09-02-2022, 01:08 AM   #5
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,434

Original Poster
Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by pan64 View Post
Code:
sh --version
or something similar the "usual" way.
That does not work.

Code:
:/storage/emulated/0 $ sh --version
sh: sh: --: unknown option
1|:/storage/emulated/0 $ echo $SHELL                                                                                                                                         
/system/bin/sh
:/storage/emulated/0 $ /system/bin/sh --version
/system/bin/sh: /system/bin/sh: --: unknown option
1|:/storage/emulated/0 $ sh -version
sh: n: unknown option
Quote:
Originally Posted by rkelsen View Post
If you can get a busybox binary for your phone, it might have bash built in.
There is a busybox package on Google Play, but I checked the list of busybox commands and I noticed that my phone already has some of them, and I am afraid of overwriting something. I guess busybox is just one executable, right? Still, I'm afraid the phone might try to execute one thing and execute another. I don't know, I'm not sure it's a good idea. I just wanted to be able to source my .profile file and have aliases, and then I got curious about what shell is running.

Quote:
Originally Posted by boughtonp View Post
Searching for "android shell" reveals that it used to be Almquist (ash) and is now MirBSD Korn Shell (mksh)
I used to be familiar with mksh... a very long time ago. I even subscribed to the mailing list. I will catch up on some reading and see if I can find some interesting feature I'd like to try on the phone.

Many thanks!
 
Old 09-02-2022, 06:25 AM   #6
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,628

Rep: Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557
Quote:
Originally Posted by lucmove View Post
There is a busybox package on Google Play, but I checked the list of busybox commands and I noticed that my phone already has some of them, and I am afraid of overwriting something. I guess busybox is just one executable, right? Still, I'm afraid the phone might try to execute one thing and execute another. I don't know, I'm not sure it's a good idea.
As per the page I quoted, Android mostly uses Toybox, which is basically an inferior version of Busybox. (The page lists what commands come from where.)

Since Toybox claims to be "reasonably standards compliant", you'll probably be ok switching to Busybox once the software on the device sticks to POSIX and doesn't rely on any places where Toybox has bugs/quirks that aren't compliant, but depending on what features you want, you might be able to get away with just using Toybox.


Last edited by boughtonp; 09-02-2022 at 07:00 AM.
 
Old 09-14-2022, 04:33 AM   #7
thugtomas
LQ Newbie
 
Registered: Sep 2022
Posts: 6

Rep: Reputation: 0
Application shell (or app shell) architecture in an Android is a way to create a progressive web app that loads on your users' screens reliably and instantly as you would see in a native application
 
Old 09-14-2022, 09:19 AM   #8
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,818

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by lucmove View Post
Even explicitly running 'sh .profile' doesn't work.
Try "source .profile" and see if your alias is still defined. I would expect that "sh" command you tried to create a new process, execute the contents or .profile, and then exit. After that process disappears, so does anything set up by .profile.

On my Android phone, if I issue "sh -v", I get a bit of text telling me that the shell is based on mksh and that I have several aliases defined around 'ls':
Code:
l='ls'
la='l -a'
ll='l -l'
lo='l -a -l'

I haven't tried installing an SSH server on my phone but I have a couple of terminal emulators that I've used (rarely) in the past. Sadly, after either my switch to another carrier or the recent upgrade to Android 12 they don't seem to work as I remember. Most everything I try to "ls" simply gives me a "Permission denied" error. That's not what I used to see. YMMV, I guess.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Buy This Phone! Great Phone On Ebay! :-) x_freeride_x General 5 01-22-2007 02:33 PM
How do I setup Phone <->PC <-Internet->PC <->Phone in Linux cmisip Linux - Networking 1 10-26-2003 12:58 PM
Modem + phone + phone line Griffon26 General 1 10-11-2001 11:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Mobile

All times are GMT -5. The time now is 08:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration