cancel
Showing results for 
Search instead for 
Did you mean: 
Andres_Tarallo
Flight Engineer
Flight Engineer
  • 3,786 Views

/bin/bash or /usr/bin/bash?

Jump to solution

I've noticed that many exercices on RH124 and RH134 user /usr/bin/bash.

I've been working with Linux, and other UNIXes (mostly AIX and Solaris), for many years. Most of my scripts use start with "#!/bin/bash"

Are there reasons to favor one over the other?

 

 

Labels (2)
1 Solution

Accepted Solutions
the_Shadowman
Mission Specialist
Mission Specialist
  • 3,615 Views

Well, first of all, that's great to see such questions because it shows a specialist not wanting to just write scripts, but striving to master their skills.

Second, we should consider if we are going to take portability into account.

If not, then yeah, no real difference between this two options.

But in my personal worldview a good production-ready script == portable script, meahwhile we aren't going to see /usr/bin/bash on Linux Mint for example.

$ ls -la /usr/bin/bash
ls: cannot access '/usr/bin/bash': No such file or directory

Even if we are all agree that Red Hat is better, still there's a lot of debian-based installations all around the world, right?

So the anwer becomes more particular, while the question itself starts to be even more interesting while we are diving deeper into this.

Did I mention how I love bash\zsh for this?)

According to wonderful "Bash idioms" book -- unsure if I can post link here, and my personal expirience, the best shebang-strings solutions are:

  1. /usr/bin/env bash # Still not ideal but is the best what humanity have for now. Side note: remember "#!/usr/bin/env python" form.
  2. /bin/bash - # The dash protects user from running your script on older versions of bash.
  3. /bin/bash.

I hope that helps!

View solution in original post

2 Replies
shura
Flight Engineer
Flight Engineer
  • 3,775 Views

Hello @Andres_Tarallo 

Look, please, at:

root@notebook:~# ls -ldi /bin
24 lrwxrwxrwx. 1 root root 7 Jul 21 2023 /bin -> usr/bin
root@notebook:~# ls -ldi /usr/bin
7340035 dr-xr-xr-x. 2 root root 77824 Feb 7 08:29 /usr/bin
root@notebook:~# ls -ldi /bin/
7340035 dr-xr-xr-x. 2 root root 77824 Feb 7 08:29 /bin/
root@notebook:~#

So it is variant of hard or soft link, So no diff which one to use.

Good luck

the_Shadowman
Mission Specialist
Mission Specialist
  • 3,616 Views

Well, first of all, that's great to see such questions because it shows a specialist not wanting to just write scripts, but striving to master their skills.

Second, we should consider if we are going to take portability into account.

If not, then yeah, no real difference between this two options.

But in my personal worldview a good production-ready script == portable script, meahwhile we aren't going to see /usr/bin/bash on Linux Mint for example.

$ ls -la /usr/bin/bash
ls: cannot access '/usr/bin/bash': No such file or directory

Even if we are all agree that Red Hat is better, still there's a lot of debian-based installations all around the world, right?

So the anwer becomes more particular, while the question itself starts to be even more interesting while we are diving deeper into this.

Did I mention how I love bash\zsh for this?)

According to wonderful "Bash idioms" book -- unsure if I can post link here, and my personal expirience, the best shebang-strings solutions are:

  1. /usr/bin/env bash # Still not ideal but is the best what humanity have for now. Side note: remember "#!/usr/bin/env python" form.
  2. /bin/bash - # The dash protects user from running your script on older versions of bash.
  3. /bin/bash.

I hope that helps!

Join the discussion
You must log in to join this conversation.