When writing shell scripts or running automation tools like Ansible, you’ll often see /bin/sh, /bin/bash, or even errors like:

set: Illegal option -o pipefail

This confusion stems from differences between bash and dash — two popular Unix shells. Let’s explore what they are, how they differ, and when it matters.


What is bash ?

Bash stands for Bourne Again Shell. It’s:

Key Features of Bash:


What is dash ?

dash stands for Debian Almquist Shell. It’s:

What dash lacks:


bash vs dash: A Side-by-Side

Featurebashdash
POSIX compliantMostlyFully
ArraysYesNo
[[ … ]]YesNo
set -o pipefailYesNo
Brace expansion ( {1..5} )YesNo
SpeedSlowerFaster
Installed by defaultMost distrosDebian/Ubuntu

Example That Works in Bash but Fails in Dash

#!/bin/sh
set -o pipefail
echo "Hello"

This will fail in dash (/bin/sh on Ubuntu) with:

/bin/sh: 1: set: Illegal option -o pipefail

It works fine in bash.


Why This Matters in DevOps & Ansible ?

In tools like Ansible, the shell module runs commands via /bin/sh by default. On Ubuntu/Debian systems, /bin/shdash, which means:

shell: |
  set -o pipefail
  command
args:
  executable: /bin/bash

How to Switch /bin/sh to Bash (if needed)

echo "dash dash/sh boolean false" | sudo debconf-set-selections
sudo dpkg-reconfigure -f noninteractive dash

This will update /bin/sh/bin/bash.


Best Practices

  1. Use #!/bin/bash when using bash features
  2. Use #!/bin/sh only for strictly POSIX-compliant scripts
  3. Always test scripts on the actual shell being used
  4. For Ansible, use args: executable: /bin/bash when needed

#ansible #skillupwithsachin #blogs #bash #dash

Youtube: https://www.youtube.com/@skillupwithsachin

Leave a Reply

Your email address will not be published. Required fields are marked *