Shell management: Difference between revisions

From Alpine Linux
(added links to busybox and ash shell)
m (rearranged headings)
 
(27 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Alpine Linux uses the [[BusyBox]] variant of the [[BusyBox#Ash_shell|ash]] shell. This page explains various ways to change the default shell in Alpine Linux to other popular shells like {{Pkg|bash}}, {{Pkg|zsh}}, {{Pkg|fish}} etc..
The default shell used by Alpine Linux is the [[BusyBox]] variant of the [[BusyBox#Ash_shell|ash]] shell. This page explains how to use the default shell and various ways to change the default shell in Alpine Linux.  


== By hand ==
== Ash shell ==  
Edit {{Path|/etc/passwd}} manually. An example line for a user named <code>user</code> is:


{{Cat|/etc/passwd|...
Alpine Linux uses [[Busybox]] Ash shell for its default shell. It is a standard POSIX shell derived from Debian Ash variant.
 
One's ~/.bashrc file (or, alternatively, a different shell alias file) could be considered as a basis, say, for an {{Path|~/.ashrc}} file, reviewing it carefully for syntax/cli variants against that of Ash shell. For non-login, interactive shells refer to [[#Setting alias|Setting alias]] section.
 
{{Tip|Use {{pkg|checkbashisms}} script to perform basic checks for the presence of bashisms in scripts and help remove them.}}
 
=== Setting alias ===
 
For non-login shells, Busybox Ash and other POSIX shells do NOT automatically read a startup file like {{Path|~/.ashrc}}. To ensure that both login and non-login shells work consistently, use '''ENV''' environment variable in {{Path|~/.profile}} to refer {{Path|~/.ashrc}} file.
 
# Edit the {{Path|~/.profile}} as follows: {{Cat|~/.profile|<nowiki>...
export ENV="$HOME/.ashrc" </nowiki>}}
# Now aliases can be added in the startup file {{Path|~/.ashrc}} as follows: {{Cat|~/.ashrc|<nowiki># ~/.ashrc: interactive shell configuration for BusyBox Ash
 
# Custom Aliases
alias ls='ls --color=auto'
alias grep='grep --color=auto'
 
# You may want to put all your additions into a separate file like
# ~/.ash_aliases, instead of adding them here directly.
 
if [ -f ~/.ash_aliases ]; then
    . ~/.ash_aliases
fi</nowiki>}}
 
== Available shells ==
 
Most of the popular shells are available in Alpine Linux repositories as can be seen from the below list.
{| class="wikitable" align="center" style="width:100%; border:1px #0771a6 solid; background:#f9f9f9; text-align:left; border-collapse:collapse;"
|-style="background:#333333; color:#ffffff; font-size: 1.2em; text-align:center;"
|width="10%" | Name
|width="36%" | URL
|Remarks
|-
|{{Pkg|bash}}|| https://www.gnu.org/software/bash/bash.html||The GNU Bourne Again shell
|-
|{{pkg|dash}} ||http://gondor.apana.org.au/~herbert/dash/||Small and fast POSIX-compliant shell
|-
|{{pkg|elvish}} ||https://elv.sh||Friendly and expressive Unix shell
|-
|{{Pkg|fish}} ||https://fishshell.com/||Modern interactive commandline shell
|-
|{{pkg|loksh}} ||https://github.com/dimkr/loksh||A Linux port of OpenBSD's ksh
|-
|{{pkg|murex}} ||https://murex.rocks/||Intuitive, typed and content aware shell
|-
|{{pkg|nsh}} ||https://github.com/nuta/nsh||A command-line shell like fish, but POSIX compatible
|-
|{{pkg|nushell}} ||https://www.nushell.sh||A new type of shell
|-
|{{pkg|oksh}} ||https://github.com/ibara/oksh||Portable OpenBSD ksh, based on pdksh
|-
|{{pkg|tcsh}} ||https://github.com/tcsh-org/tcsh||extended C-shell
|-
|{{pkg|yash}} ||https://magicant.github.io/yash||Yet another shell
|-
|{{Pkg|zsh}} || https://www.zsh.org/||Very advanced and programmable command interpreter
|}
 
To install any of the above shells, say for eg: {{pkg|bash}} shell: {{Cmd|# apk add {{pkg|bash}} {{pkg|bash-completion}}}}
 
== Change default shell ==
 
There are various ways to change the default user shell in Alpine Linux. You can revert back to [[#ash|ash]] shell at anytime with the same steps.
 
{{Note|You need to log out and login again for these changes to take effect.}}
 
=== Using chsh command ===
 
To use {{ic|chsh}} command, install the {{pkg|shadow}} package: {{Cmd|# apk add shadow}}
And use chsh: {{Cmd|# chsh username}}
Now enter the path for the shell you want to use (e.g {{Path|/bin/zsh}})
and press {{Key|Enter}} to confirm this change. The shell should exist in {{Path|/etc/shells}}.
 
=== By hand ===
 
{{Warning|Take care not to delete/mangle the line, as it would make you unable to log in again.}}
 
Edit {{Path|/etc/passwd}} manually using an editor of your choice. An example line for a user named <code>user</code> is: {{Cat|/etc/passwd|...
user:x:1000:1000:user:/home/user:/bin/ash
user:x:1000:1000:user:/home/user:/bin/ash
...
...
}}
}}


Change {{Path|/bin/ash}} to point to the path of a shell from {{Path|/etc/shells}}. Take care to not delete/mangle the line, as it would make you unable to log in again. The <code>user</code> should be the user you are changing the default login shell for.
Change {{Path|/bin/ash}} to point to the path of a shell from {{Path|/etc/shells}}. The <code>user</code> should be the user you are changing the default login shell for.


== Using shadow ==
== /bin/sh ==


Download the required package:
Most applications expect a POSIX-compliant shell to be present in a standard location, {{Path|/bin/sh}}. In Alpine Linux, {{Path|/bin/sh}} is linked to [[#Ash shell|Busybox ash]] by default, but you can change this by installing an alternate {{pkg|*-binsh}} package. Changing {{Path|/bin/sh}} may lead to a difference in script execution speed.
{{Cmd|# apk add shadow}}
And use chsh:
{{Cmd|# chsh username}}


Now enter the path for the shell you want to use (e.g {{Path|/bin/bash}})
To use {{pkg|dash}} shell as {{Path|/bin/sh}}:{{Cmd|# apk add {{pkg|dash-binsh}}}}
and press {{Key|Enter}} to confirm this change. The shell should exist in {{Path|/etc/shells}}.
 
== See also ==


{{Note|You may need to log out or reboot for this change to take effect, '''ash''' is part of busybox so you can revert back to '''ash''' ({{Path|/bin/ash}}) at anytime with the same steps.}}
* [https://linux.die.net/man/1/dash dash Manual]
* [https://git.busybox.net/busybox/tree/shell/README Ash README]
* [https://git.busybox.net/busybox/tree/shell Ash source code]
* [https://pubs.opengroup.org/onlinepubs/9799919799/ POSIX standard]
* [https://stackoverflow.com/questions/38024160/how-to-get-etc-profile-to-run-automatically-in-alpine-docker/38025686#38025686 stackoverflow on ash shell]


[[Category:Shell]]
[[Category:Shell]]
[[Category:Newbie]]
[[Category:System Administration]]
[[Category:System Administration]]

Latest revision as of 14:42, 16 November 2025

The default shell used by Alpine Linux is the BusyBox variant of the ash shell. This page explains how to use the default shell and various ways to change the default shell in Alpine Linux.

Ash shell

Alpine Linux uses Busybox Ash shell for its default shell. It is a standard POSIX shell derived from Debian Ash variant.

One's ~/.bashrc file (or, alternatively, a different shell alias file) could be considered as a basis, say, for an ~/.ashrc file, reviewing it carefully for syntax/cli variants against that of Ash shell. For non-login, interactive shells refer to Setting alias section.

Tip: Use checkbashisms script to perform basic checks for the presence of bashisms in scripts and help remove them.

Setting alias

For non-login shells, Busybox Ash and other POSIX shells do NOT automatically read a startup file like ~/.ashrc. To ensure that both login and non-login shells work consistently, use ENV environment variable in ~/.profile to refer ~/.ashrc file.

  1. Edit the ~/.profile as follows:

    Contents of ~/.profile

    ... export ENV="$HOME/.ashrc"
  2. Now aliases can be added in the startup file ~/.ashrc as follows:

    Contents of ~/.ashrc

    # ~/.ashrc: interactive shell configuration for BusyBox Ash # Custom Aliases alias ls='ls --color=auto' alias grep='grep --color=auto' # You may want to put all your additions into a separate file like # ~/.ash_aliases, instead of adding them here directly. if [ -f ~/.ash_aliases ]; then . ~/.ash_aliases fi

Available shells

Most of the popular shells are available in Alpine Linux repositories as can be seen from the below list.

Name URL Remarks
bash https://www.gnu.org/software/bash/bash.html The GNU Bourne Again shell
dash http://gondor.apana.org.au/~herbert/dash/ Small and fast POSIX-compliant shell
elvish https://elv.sh Friendly and expressive Unix shell
fish https://fishshell.com/ Modern interactive commandline shell
loksh https://github.com/dimkr/loksh A Linux port of OpenBSD's ksh
murex https://murex.rocks/ Intuitive, typed and content aware shell
nsh https://github.com/nuta/nsh A command-line shell like fish, but POSIX compatible
nushell https://www.nushell.sh A new type of shell
oksh https://github.com/ibara/oksh Portable OpenBSD ksh, based on pdksh
tcsh https://github.com/tcsh-org/tcsh extended C-shell
yash https://magicant.github.io/yash Yet another shell
zsh https://www.zsh.org/ Very advanced and programmable command interpreter

To install any of the above shells, say for eg: bash shell:

# apk add bash bash-completion

Change default shell

There are various ways to change the default user shell in Alpine Linux. You can revert back to ash shell at anytime with the same steps.

Note: You need to log out and login again for these changes to take effect.

Using chsh command

To use chsh command, install the shadow package:

# apk add shadow

And use chsh:

# chsh username

Now enter the path for the shell you want to use (e.g /bin/zsh) and press Enter to confirm this change. The shell should exist in /etc/shells.

By hand

Warning: Take care not to delete/mangle the line, as it would make you unable to log in again.


Edit /etc/passwd manually using an editor of your choice. An example line for a user named user is:

Contents of /etc/passwd

... user:x:1000:1000:user:/home/user:/bin/ash ...

Change /bin/ash to point to the path of a shell from /etc/shells. The user should be the user you are changing the default login shell for.

/bin/sh

Most applications expect a POSIX-compliant shell to be present in a standard location, /bin/sh. In Alpine Linux, /bin/sh is linked to Busybox ash by default, but you can change this by installing an alternate *-binsh package. Changing /bin/sh may lead to a difference in script execution speed.

To use dash shell as /bin/sh:

# apk add dash-binsh

See also