bash scripts issue

Hi!
I have several bash scripts from projects I worked on using Linux that I would like to use.
Some of these projects use external packages containing bash scripts too.
The problem is that most of scripts start with
#!/bin/bash
and bash in freebsd is located at
#!/usr/local/bin/bash

I could just simply create a symbolic link on /bin/bash > /usr/local/bin/bash
Is this recommended? If not, why?
Or instead I should start using
#!/usr/bin/env bash
and it will be compatible to both?
The problem of this last one is that in downloaded scripts from git projects etc nobody uses it that way, so I will always have to adapt.

Thank you.
 
If these are scripts in packages that you update regularly I would symlink.

I would also submit patches upstream to switch to /usr/bin/env
 
It would be nice to have a definitive website (or forum) for helping to iron out any problems in trying to port Linux specific code to FreeBSD.

If there is such a thing can people help point it out?
 
Do the scripts rely on bash(1) features? If not use
Bash:
#!/bin/sh
This pathname is the same on FreeBSD and (presumably) all Linux distributions. The
Bash:
#!/usr/bin/env bash
workaround can be tricky if $PATH contains, say, /home/user/bin at the start and /home/user/bin/bash exists (e. g., I don’t know, a symbolic link to zsh(1) cos nobody uses bash(1) anymore 😜).​
 
Do the scripts rely on bash(1) features? If not use
Bash:
#!/bin/sh
This pathname is the same on FreeBSD and (presumably) all Linux distributions. The
Bash:
#!/usr/bin/env bash
workaround can be tricky if $PATH contains, say, /home/user/bin at the start and /home/user/bin/bash exists (e. g., I don’t know, a symbolic link to zsh(1) cos nobody uses bash(1) anymore 😜).​
I did try zsh sometime ago and didn't like it and any system that comes with zsh as default shell the first thing I do is switch to bash, I like to keep it simple.
I don't use sh because I can't live without command history and I have it in bash and of course in zsh too.
But I'm talking about development, there are several scripts everywhere, good and useful scripts that are written in bash.
Lately I installed a java software and the package contains bash scripts to init the service,start, stop, etc, so I had to change those scripts one by one.
I was looking for the correct way to run these scripts.
 
It would be nice to have a definitive website (or forum) for helping to iron out any problems in trying to port Linux specific code to FreeBSD.

If there is such a thing can people help point it out?
I can bet that users with macOS have the same problem.
FreeBSD comes with sh in /bin/ and bash is a "port" software that gets installed in /usr/local/ which I totally agree.
But maybe it's a good idea that such shells packages should include a symbolic link on /bin/ just because it's categorized as shell software.
Linux have it's way and BSD does it other way, it's acceptable.
There' s no right nor wrong here, it's just different ways.
From now on I will use
#!/usr/bin/env bash
in my scripts to be compatible with both but will still have to deal with everyone else scripts.
 
Do the scripts rely on bash(1) features? If not use
Bash:
#!/bin/sh
This pathname is the same on FreeBSD and (presumably) all Linux distributions. The
Bash:
#!/usr/bin/env bash
workaround can be tricky if $PATH contains, say, /home/user/bin at the start and /home/user/bin/bash exists (e. g., I don’t know, a symbolic link to zsh(1) cos nobody uses bash(1) anymore 😜).​
yes you're right, most of times it doesn't even use bash in the script but if the script is long it probably does.
 
Software that does that might not be worth running.
why?
bash turns to be better for scripting than sh so it's quite obvious that people will go for bash.
mostly if you need to have some job control in the script mostly used to start/stop service scripts.
 
why?
bash turns to be better for scripting than sh so it's quite obvious that people will go for bash.
mostly if you need to have some job control in the script mostly used to start/stop service scripts.

I meant
- declaring #!/bin/bash when no actual bash features are used
- not using /usr/bin/env

Those are signs of low quality software.
 
Back
Top