Shell management: Difference between revisions
Prabuanand (talk | contribs) m (clarified sentence) |
Prabuanand (talk | contribs) (added method 2 based on https://stackoverflow.com/questions/38024160/how-to-get-etc-profile-to-run-automatically-in-alpine-docker/38025686#38025686) |
||
Line 5: | Line 5: | ||
Alpine Linux uses [[Busybox]] Ash shell for its default shell. It is a standard POSIX shell derived from Debian Ash variant. | 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|~/.config/ash/ashrc}} file, reviewing it carefully for syntax/cli variants against that of Ash shell. | One's ~/.bashrc file (or, alternatively, a different shell alias file) could be considered as a basis, say, for an {{Path|~/.ashrc}} or {{Path|~/.config/ash/ashrc}} file, reviewing it carefully for syntax/cli variants against that of Ash shell. | ||
=== Setting alias === | === Setting alias === | ||
When using Ash shell, one can’t set aliases in the {{Path|~/.profile}}. | When using Ash shell, one can’t set aliases directly in the {{Path|~/.profile}} file. There are various ways to use aliases with Ash. | ||
==== Method 1 ==== | |||
Once can set '''ENV''' environment variable in {{Path|~/.profile}} file to refer the aliases file. The following steps does not affect existing {{Path|~/.profile}} and uses {{path|~/.config/ash/profile}} file : | |||
# First create the file {{Path|/etc/profile.d/profile.sh}} as follows: {{Cat|/etc/profile.d/profile.sh|if [ -f "$HOME/.config/ash/profile" ]; then | # First create the file {{Path|/etc/profile.d/profile.sh}} as follows: {{Cat|/etc/profile.d/profile.sh|if [ -f "$HOME/.config/ash/profile" ]; then | ||
Line 20: | Line 24: | ||
}} | }} | ||
==== Method 2 ==== | |||
This method uses {{Path|~/.profile}}: | |||
# Edit the {{Path|~/.profile}} as follows:{{Cat|~/.profile|# Alias | |||
if [ -f ~/.ash_aliases ]; then | |||
. ~/.ash_aliases | |||
fi}} | |||
# Edit {{Path|~/.ash_aliases}} file as follows:{{Cat|~/.ash_aliases|<nowiki>alias a=alias | |||
alias c=clear | |||
alias f=file | |||
alias g=grep | |||
alias l='ls -lh'</nowiki>}} | |||
=== Checkbashisms === | === Checkbashisms === | ||
Revision as of 07:12, 20 July 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 or ~/.config/ash/ashrc file, reviewing it carefully for syntax/cli variants against that of Ash shell.
Setting alias
When using Ash shell, one can’t set aliases directly in the ~/.profile file. There are various ways to use aliases with Ash.
Method 1
Once can set ENV environment variable in ~/.profile file to refer the aliases file. The following steps does not affect existing ~/.profile and uses ~/.config/ash/profile file :
- First create the file /etc/profile.d/profile.sh as follows:
Contents of /etc/profile.d/profile.sh
if [ -f "$HOME/.config/ash/profile" ]; then . "$HOME/.config/ash/profile" fi - Next create the file ~/.config/ash/profile as follows:
Contents of ~/.config/ash/profile
export ENV="$HOME/.config/ash/ashrc" - Now aliases can be added in the file ~/.config/ash/ashrc:
Contents of ~/.config/ash/ashrc
su="doas -s"
Method 2
This method uses ~/.profile:
- Edit the ~/.profile as follows:
Contents of ~/.profile
# Alias if [ -f ~/.ash_aliases ]; then . ~/.ash_aliases fi
- Edit ~/.ash_aliases file as follows:
Contents of ~/.ash_aliases
alias a=alias alias c=clear alias f=file alias g=grep alias l='ls -lh'
Checkbashisms
Perl based checkbashisms
utility from checkbashisms package can be used to perform basic checks for the presence of bashisms in /bin/sh scripts and help remove them.
Available shells
All popular shells are available in Alpine Linux. Refer to the following list:
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 shell in Alpine Linux. You can revert back to ash shell at anytime with the same steps.
By hand
Edit /etc/passwd manually using an editor of your choice. An example line for a user named user
is:
Contents of /etc/passwd
Change /bin/ash to point to the path of a shell from /etc/shells. Take care to not delete/mangle the line, as it would make you unable to log in again. The user
should be the user you are changing the default login shell for.
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.