1

I want to make a bash file that reads a parameter from a config file. In Debian based linux it works fine by:

my.config:

MYVARIABLE=12345

my.sh:

#!/bin/bash

source my.config echo $MYVARIABLE

But I am not able to achieve this in FreeBSD. Do you have any idea?

Samto
  • 13

1 Answers1

4

You do not supply any errors or what you have done. This then leaves us guessing:

  1. Bash is not installed by default. You might need to add it yourself:

    pkg install bash

  2. As with Debian you need to make the script executable:

    chmod +x my.sh

  3. The first line of your script should point to the location of bash. It is not located in /bin by default. You can make it work using a link but I would prefer to change the first line of your script to:

    #!/usr/bin/env bash
    

    source my.config echo $MYVARIABLE

The above will make you script OS agnostic. Or you can use the explicit path:

#!/usr/local/bin/bash

source my.config echo $MYVARIABLE

Why?

See Why is it better to use “#!/usr/bin/env NAME” instead of “#!/path/to/NAME” as my shebang?