Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 5733  / 2 Years ago, mon, september 19, 2022, 8:32:53

Which would be advised as the first line in a bash script:



#! /usr/bin/env bash


or



#! /bin/bash

More From » bash

 Answers
1

As a general rule, using env is more portable. It is unlikely but theoretically conceivable to find a system that has no bash at /bin/bash. It is also possible that the user running the script has their own bash version that is somehow different.



Using env means that the first bash instance in the user's path will be chosen. This means that #!/usr/bin/env bash will always work with the user's chosen bash version and it should always evaluate to an available bash even in non-standard systems. This becomes much more important if you are using another interpreter, not bash. Perl for example, can be installed to different locations on different systems but env will find it regardless.



So, using #!/usr/bin/env PROGRAM is a good habit to get into since it makes your scripts more portable to different *nix versions.


[#26184] Tuesday, September 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cretanol

Total Points: 320
Total Questions: 99
Total Answers: 115

Location: Australia
Member since Sat, May 27, 2023
1 Year ago
cretanol questions
Fri, Dec 2, 22, 13:30, 1 Year ago
Thu, Dec 8, 22, 03:00, 1 Year ago
Mon, Aug 1, 22, 03:21, 2 Years ago
Fri, Sep 24, 21, 16:28, 3 Years ago
Sun, Apr 24, 22, 06:37, 2 Years ago
;