How to start bash shell in openwrt

I am new to openwrt
as soon as I login to machine and check shell using below command
echo $SHELL
---> /bin/ash

Then I type the command bash to start bash shell . even after that I check shell and result is same.

echo $SHELL
---> /bin/ash

How to start Bash shell ?

have you installed the bash package ?

yes

root@OpenWrt:~# opkg install bash
Package bash (5.1-2) installed in root is up to date.
root@OpenWrt:~#

Tried running bash?

yes

root@OpenWrt:~#
root@OpenWrt:~# bash
root@OpenWrt:~# echo $SHELL
/bin/ash
root@OpenWrt:~#

If you want to make bash the default shell, change /bin/sh to link to bash.

1 Like

Or edit /etc/passwd so the root shell is bash?

$ grep root /etc/passwd
root:x:0:0:root:/root:/bin/ash
3 Likes

…just be aware that setting a non-default shell as login shell introduces a rather high risk of locking yourself out after a sysupgrade, as your new(ly installed) image won't ship with bash installed, while root's shell references /bin/bash.

Possible, but not recommended (and even less recommended would be touching the /bin/sh symlink, which could end you up in even more tricky situations).

6 Likes

You have to run bash <your command here> for it to work without having to modify anything in your system. For example, bash ./test.sh

But if it's included in a custom image... Why not :person_shrugging:

Maybe if I would write bash scripts... but for OpenWrt I tend to stick and use only posix features.

1 Like
root@turris:~# echo $SHELL
/bin/ash
root@turris:~# /bin/bash
root@turris:~# export SHELL=/bin/bash
root@turris:~# echo $SHELL
/bin/bash
root@turris:~# 

I've been doing this for years on systems that I don't manage myself that have csh as the default shell.

Is there any downside to using the following in ~/.profile:

if [ -x /bin/bash ] && [ "$0" != "/bin/bash" ]; then
    exec /bin/bash
fi