Solved script bash

hello people!

I wrote a cute script, it start with #!/bin/bash. The shell I use is bash, but the script only works if I change the she-bang for #!/bin/sh.
May someone explain to me why? Is that because the root shell is still sh?

Thank you.

Fabien
 
Just keep in mind that it's a bit different than Linux. The reason #!/bin/sh would work is because that is a shell on FreeBSD. You can type sh at a command prompt and you can use it and see what it does. It's missing some things that bash has but it is the default shell for a user--that is a non root new user.
For example, it does't have history, nor $UID

As has been typed, to use bash in a script you would use, on FreeBSD, #!/usr/local/bin/bash
You *could* depending upon circumstances, make your script more portable by using

#!/usr/bin/env bash


This will use the bash environment on any machine that has bash. However take a look at
https://unix.stackexchange.com/ques...sr-bin-env-name-instead-of-path-to-name-as-my first, it gives some disadvantages as well, such as passing arguments to the script can be a problem.
 
Thank you everybody for you help and advises.

It works now. I have been away from FreeBSD for a while and forgot some basics...
 
Back
Top