What does #!/bin/bash mean

script

If you have ever written, downloaded, or opened a bash script, surely you have come across a somewhat strange first line that not everyone knows what it means and why it should be put there. I am referring to #!/bin/bash. Well, in this article you will be able to know all the details about what it is called, what it is for, and if it is always the same or if there are some changes.

What is an interpreted language?

programming language V

Un interpreted programming language it is one that does not need to be compiled to run, but can be run directly from the source code using an interpreter, which is nothing more than a program that can translate the code into machine-understandable instructions. This brings some advantages:

  • Multiplatform: as it is not binary, it can be run on various platforms without modification, which is a clear advantage if we want the code to work on any system.
  • Portability: if the interpreter is platform-ready, then the interpreted script or language will work on that platform.

However, these interpreted languages ​​also have its disadvantages:

  • One is performance, as they need the interpreter always running in the background for it to work.
  • The own dependence of the interpreter.

As an example of interpreted languages Some can be mentioned, such as Java, C#, JavaScript, Visual Basic .NET and VBScript, Perl, Python, Lips, Ruby, PHP, ASP, etc.

What is a script?

Shell Scripting: Practical Examples

Shell Scripting: Practical Examples

Un script is just code created with an interpreted programming language to perform a task. It is generally a simple program, with an event of commands or orders that are executed sequentially.

What is #!/bin/bash (shebang)?

Script content on Mousepad

Script content on Mousepad

Finally, the subject of this article is that famous #!/bin/bash, which is known in Unix parlance as Shebang. Although this is the most common, it is not always necessary to use it for the script to work. Other projects also have their own shebangs, such as #!/usr/bin/env python3, #!/bin/sh, etc.

The aim of shebang is simply giving the full path of the shell, so that it can be located wherever the script is run. Also, as you can see, not only the path is determined in it, but also the interpreter, in these cases Bash, Python 3, and other interpreters to work with.


Be the first to comment

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.