2

On a brand new Ubuntu 22.10 installation I tried the command

sudo dpkg-reconfigure dash

That he did nothing

I learned from this post that this feature has been removed.

So what is the right and clean way to make bash the system shell (eg. /bin/sh)? I hope I don't have to do hands on symbolic links of executable, manpage and all that is needed....

2
  • I wouldn't recommend changing the symlink /bin/sh. The point of /bin/sh is that it should be POSIX compliant, which Dash is - and it's also faster than Bash. So you don't gain anything by pointing /bin/sh to Bash - on the other hand you probably loose speed of execution for POSIX scripts. Jan 20, 2023 at 13:44
  • Related: What is the point of sh being linked to dash? Jan 20, 2023 at 13:51

1 Answer 1

2

I assume you know there are differences between dash and bash ... Although dash scripts should generally run without issues in bash... (But, not vice versa), it's advised to not change the system's default shell as system scripts are written for the default shell and differences/issues might arise in the future.

It's also good to know and comply with the current version of FHS(Filesystem Hierarchy Standard), definition of /bin/sh:

sh POSIX compatible command shell

If /bin/sh is not the POSIX compatible shell command itself, it must be a hard or symbolic link to the real shell command.

That said ... sudo dpkg-reconfigure dash when choosing no, changes these symlinks:

$ ls -l /bin/sh /bin/sh.distrib /usr/share/man/man1/sh.1.gz 
lrwxrwxrwx 1 root root 4 Jan 20 16:10 /bin/sh -> dash
lrwxrwxrwx 1 root root 4 Jan 20 15:42 /bin/sh.distrib -> bash
lrwxrwxrwx 1 root root 9 Jan 20 16:10 /usr/share/man/man1/sh.1.gz -> dash.1.gz

to these symlinks:

$ ls -l /bin/sh /bin/sh.distrib /usr/share/man/man1/sh.1.gz 
lrwxrwxrwx 1 root root 4 Jan 20 16:10 /bin/sh -> bash
lrwxrwxrwx 1 root root 4 Jan 20 16:10 /bin/sh.distrib -> dash
lrwxrwxrwx 1 root root 9 Jan 20 16:10 /usr/share/man/man1/sh.1.gz -> bash.1.gz

and vice versa when choosing yes.

That said again ... Although merely creating symlinks will have the same system shell and man sh behavior results, it's worth noting that sudo dpkg-reconfigure dash does that as well with dpkg diversions ... Hence the existence of sh.distrib ... This will have the added effect of dpkg recognizing the change and handling those files accordingly:

File diversions are a way of forcing dpkg(1) not to install a file into its location, but to a diverted location. Diversions can be used through the Debian package scripts to move a file away when it causes a conflict. System administrators can also use it to override some package's configuration file, or whenever some files (which aren't marked as 'conffiles') need to be preserved by dpkg, when installing a newer version of a package
which contains those files.

The diversion when choosing no happens as follows:

Removing 'diversion of /bin/sh to /bin/sh.distrib by dash'
Adding 'diversion of /bin/sh to /bin/sh.distrib by bash'
Removing 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by dash'
Adding 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by bash'

That is done like so:

$ sudo dpkg-divert --package dash --remove /bin/sh
$ sudo dpkg-divert --package bash --divert /bin/sh.distrib --add /bin/sh
$ sudo dpkg-divert --package dash --remove /usr/share/man/man1/sh.1.gz
$ sudo dpkg-divert --package bash --divert /usr/share/man/man1/sh.distrib.1.gz --add /usr/share/man/man1/sh.1.gz

and when choosing yes happens as follows:

Removing 'diversion of /bin/sh to /bin/sh.distrib by bash'
Adding 'diversion of /bin/sh to /bin/sh.distrib by dash'
Removing 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by bash'
Adding 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by dash'

That is done like so:

$ sudo dpkg-divert --package bash --remove /bin/sh
$ sudo dpkg-divert --package dash --divert /bin/sh.distrib --add /bin/sh
$ sudo dpkg-divert --package bash --remove /usr/share/man/man1/sh.1.gz
$ sudo dpkg-divert --package dash --divert /usr/share/man/man1/sh.distrib.1.gz --add /usr/share/man/man1/sh.1.gz

So, if you do the symlinks and then the diversions accordingly, you should get the same end result of running sudo dpkg-reconfigure dash.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .