3

I have seen some bash scripts start with /user/bin/bash and others/bin/bash

I did a check-sum with cksum

2695035772 1392424 /usr/bin/bash
2695035772 1392424 /bin/bash

they look exactly the same, so what's the difference.Is it more appropriate to use one than one another in bash scripts?

2

3 Answers 3

7

/bin is linked to /usr/bin so the two are literally the same. Same goes for sbin. It is due to historical, compatibility reasons. bash predates Linux so to be more compatible we still use both.

$ ls -l  / | grep bin 
lrwxrwxrwx   1 root     root              7 apr  3 00:13 bin -> usr/bin
lrwxrwxrwx   1 root     root              8 apr  3 00:13 sbin -> usr/sbin

We are going towards /usr/bin/bash. Fedora is ahead of Debian/Ubuntu and OpenSUSE on this (those use /bin/bash).

1
  • Debian uses /bin symlink to /usr/bin too, for new installs (I think since buster). For upgraded installs, you must temporarily install usrmerge package, which does the conversion in post install hook. See wiki.debian.org/UsrMerge May 15, 2022 at 11:24
4

As ubfan1 said in a comment, the /bin directory is now (not sure when this happened, but it's unimportant) simply a link to /usr/bin, so /bin/bash and /usr/bin/bash point to the exact same place in the system, thus the identical checksums.

3

There is only a single "bash" executable. The directory /bin is now replaced by a symbolic link to /usr/bin. Therefore, both /bin/bash and /usr/bin/bash are the same executable.

Historically, bash as a core utility used to be in /bin. Hard drives were small, so there was a need to keep the system partition small. Core binaries were collected in /bin, which resided on the hard drive from which the system booted. A directory /usr/bin was then designed to host other binaries, that eventually were present on a partition on another drive, mounted later in the boot process.

Storage is nowadays plenty, so there is a tendency to do away with the historical split between /bin and /usr/bin. Many distributions started to move any executable to /usr/bin instead, but, for compatibility reasons, still have a /bin, which really is only a symbolic link to /usr/bin. This way, the traditional shebang #!/bin/bash continues to work, although /bin my disappear completely in the future.

You must log in to answer this question.