AlpineLinux 3.8: Install bash for shell

This article will describe installing bash instead of /bin/ash of busybox.

1 Install bash

  • Install bash and bash-completion.
  • Change existing user's shell to /bin/bash.
  • Some application uses ~/.bashrc directly without /etc/profile.d. Add PS1 setting to ~/.bashrc.
  • Load ~/.bashrc from ~/.profile.
#!/bin/sh -e


# Install bash and bash-completion.
sudo apk add bash bash-completion

# Change shell of existing users.
sudo sed -e 's;/bin/ash$;/bin/bash;g' -i /etc/passwd

# Create ~/.bashrc and add PS1 setting.
# Some application like byobu loads ~/.bashrc directly.
cat <<EOF > ~/.bashrc
PS1="\[\e[1;32m\]\u@\h:\[\e[0m\]\w\[\e[1;32m\]$ \[\e[0m\]"
EOF

# Make ~/.profile to load ~/.bashrc.
cat <<EOF >> ~/.profile
if [ "\${SHELL}x" = "/bin/bashx" ]; then
  if [ -f "\${HOME}/.bashrc" ]; then
    . "\${HOME}/.bashrc"
  fi
fi
EOF

2 Excution result

0001_bash.png