Contrary to common assumption, Busybox doesn't default to GNU bash. Instead, it implements ash (Almquist Shell) as its default shell, which is a lightweight POSIX-compliant shell designed for embedded systems.
You can check the current shell in Busybox with:
echo $SHELL
# Or alternatively:
ls -l /bin/sh
Typical output will show:
/bin/sh -> busybox
- No command history by default
- Simpler syntax highlighting
- Fewer built-in commands
- Smaller memory footprint (~100KB vs bash's ~1MB)
While ash is the default, you can compile Busybox with different shell options:
make menuconfig
# Then navigate to:
# Shells -> Choose your default shell
Available options typically include:
- ash (default)
- hush (simpler alternative)
- msh (minimal shell)
- lsh (larger shell)
When writing scripts for Busybox, use POSIX-compliant syntax:
#!/bin/sh
# This works in both ash and bash
for i in 1 2 3; do
echo "Count: $i"
done
Avoid bashisms like:
#!/bin/bash
# This might fail in Busybox's ash
echo {1..10}
You can temporarily switch shells in a running Busybox system:
busybox ash
# or
busybox hush
Contrary to common assumption, Busybox does not default to Bash. The default shell is actually ash
, a lightweight Bourne-compatible shell that's compiled directly into the Busybox binary. This design choice reflects Busybox's philosophy of minimalism for embedded systems.
Busybox prioritizes small footprint over feature richness:
- Ash typically requires just 60-100KB compared to Bash's 1MB+
- No dynamic library dependencies (pure static linking)
- Sufficient for most recovery/initramfs operations
Run these commands to verify:
# Method 1: Check symlinks
ls -l /bin/sh
# Method 2: Busybox shell detection
busybox --list | grep -E 'ash|sh|bash'
# Method 3: Shell self-report
echo $0
To override the default, modify Busybox compilation:
# .config file modification example
CONFIG_ASH=y
CONFIG_FEATURE_SH_MATH=y
CONFIG_HUSH=n
When porting Bash scripts to Busybox:
# Problematic Bash-ism:
array=(item1 item2)
# Busybox-compatible alternative:
i=0
array="item1 item2"
for item in $array; do
echo "Item $((i+=1)): $item"
done
In speed-critical scenarios:
- Ash executes simple scripts 20-30% faster than Bash
- Significantly lower memory overhead during init sequences
- No shell initialization files (.bashrc overhead)