10

I am new to a lot of tools on Linux. A quick search did not help, I only got more about bash or sh, and searching for it somehow leans towards bash in the search results. There are quite a few different shell types out there, I have even seen zsh, thus I guess they are all forks from sh.

There is already a question What is the difference between using bash and sh to run a script? that is similar:

  • but I could not find out what the "a" stands for in a shell
  • and this question is also not just about running a script, but the shell as such - since I can choose to take ash or sh for a docker container at hand.

I remember ash would be more comfortable though still very slim, and I have forgotten why.

What is the main difference between ash and sh? size, handling, ...?

Base image was python:3-alpine, even the one with the latest tag (2022-07) has both /bin/ash and /bin/sh. There should be a reason why the two are there in the alpine image that is made to be the most compact of all. I call it with docker-compose -f docker-compose-develop.yaml run --rm MY_CONTAINER ash.

2 Answers2

11

Historically, ash is the Almquist Shell. What does it mean to be "sh compatible"? gives its history in the overall context of sh-style shells, and Where to find the source code for the Almquist Shell? explains where to find it.

Nowadays, on Linux systems providing a shell named ash, it’s either dash or Busybox ash, both of which derive from the Almquist Shell but have significant differences.

On current Linux systems, including in containers, there are three common scenarios:

  • sh is Bash (in sh mode) — this will always be larger and more featureful than ash
  • sh is dash (Debian derivatives) — in such systems, installing ash will result in a symlink from ash to dash, so ash and sh have the same size
  • sh is Busybox — the specifics will depend on the options used when building Busybox, but by default now Busybox sh is ash, so ash and sh have the same size

(On Android, which is also Linux, sh is mksh, and the same comment applies as for Bash.)

Shells can vary their behaviour depending on how they are invoked, so starting the shell as ash or sh can result in a different experience. However as far as I can determine, that is not the case for Busybox sh when ash is the default (as is the case in your container image).

Stephen Kitt
  • 434,908
  • I will check for a different behaviour over time and come back. I heard that it ash was in some way more comfortable. Your answer is helpful since it might also - on top of my general question - depend on the base image. And you might be right that it will not change anything, but that needs to be checked. I will tell, cannot say when. – questionto42 Mar 04 '22 at 13:32
  • It may be more correct to say that dash and busybox are based on ash as there have been several strands of shells based on the original Almquist shell with years of independent development done on top. IIRC dash was initially based on a port of NetBSD sh to Linux. You'll find major differences between dash, busybox ash, NetBSD sh, FreeBSD sh all based on ash. – Stéphane Chazelas Mar 04 '22 at 13:46
  • @StéphaneChazelas right, my point is really that on Linux nowadays, if you install ash (using the system’s package manager), you’ll get dash or Busybox ash. – Stephen Kitt Mar 04 '22 at 13:48
  • 1
    Ash-based shells can also be built with or without a line editor (which may be what the OP's comfortable is about). – Stéphane Chazelas Mar 04 '22 at 13:48
  • @StéphaneChazelas yes, I thought that might be what was going on, but in all the systems I tried, sh and ash behave the same way (for example in Debian, neither support exploring history using cursor keys). – Stephen Kitt Mar 04 '22 at 13:54
  • @StéphaneChazelas I found an answer. It is by hearsay, untested. – questionto42 Mar 30 '22 at 19:55
1

The difference that I had vaguely in mind and that made me ask what would make ash perhaps more comfortable was that in some containers, sh might not have auto-completion. This cannot be shown with the given example container.

Auto-completion means that you can write the start of something and press <Tab> to get it as the full name. For example when aiming at cd MY_FOLDER, cd M+<Tab> is enough, or when you open a file in another folder and you add the child paths step by step.

It is by hearsay, it is unknown in which container this ever happens. I could also be a trick that is just outdated, but then some old images should still be out there with the outdated version.

  • 1
    In your container image, sh also provides tab-completion: run docker -it --rm --entrypoint /bin/sh python:3-alpine, type cd /m then tab twice... – Stephen Kitt Mar 30 '22 at 20:54
  • @StephenKitt I got the hint from someone. Thank you for testing, and you had already said that it might depend on the container - which is right then! I will accept your answer then. This answer is still what I was heading to: there are some (old?/outdated?/strange?) containers out there where you do have this auto-completion difference. The question was not asked for this detailed container, I added that later, and as I said, I had never seen the difference anyway. The message of this answer might still be right for some, as is yours. Yours seems more relevant today. – questionto42 Mar 30 '22 at 21:08
  • 1
    Yes, it’s a plausible difference; Bash at least behaves like that. The source code of the current version of Busybox indicates that Busybox ash doesn’t make this distinction nowadays, but perhaps it did in the past. – Stephen Kitt Mar 31 '22 at 02:46