2

In a former question, I was suggested to execute:

sudo bash start-dfs.sh

why not

sudo start-dfs.sh

? I mean, what difference does bash makes?

gsamaras
  • 605

1 Answers1

1

A script in any (interpreted) language, like bash or python, needs to be "interpreted" by the interpreter of the corresponding language.

On Linux, this can be done in different ways:

  1. The interpreter is "asked" to run the script by including the language in the command to run the script:

    <language> <script>
    

    or in your example:

    sudo bash start-dfs.sh
    
  2. The script is executable, and has the permission to "ask" the interpreter itself to run the code inside the script. from your example:

    sudo start-dfs.sh
    

    In this case, the script must start with the shebang, else there is no information what interpreter to call, like:

    #!/bin/bash
    

    or:

    #!/usr/bin/env python
    

Notes

  • In case the first option is used, the language information in the command always overrules a possible shebang, no matter if the script is executble or not.
  • The extension on a script (.sh, .py etc) makes clear what type of script it is, but plays no role whatsoever in the execution of a script, unlike in windows.
Jacob Vlijm
  • 83,767