Linux

Shebang #! in Linux Scripts

1. Introduction

When you write scripts in Linux you have to know the meaning of the first line from a bash script and why you need it. In a non-computer science environment phrase “the whole shebang” means “everything”.

In computer science, a shebang is a sequence of characters. The first character is a number sign (#) and the second is an exclamation mark (!). This is also known as sharp-exclamation, sha-bang, hashbang, pund-bang, or hash ping.

2. Why do we use the shebang?

The first line from a file is an executable in the Unix operating system. The program loader parser will know that the first line will be interpreted as a directive. The loader will execute the specified interpreter program set in the first shebang line and as a first parameter will pass the path of the initial script. That program may use the file as input data. So basically the shebang line is a way to declare what interpreter the operating system will use to parse the script file.

E.g: We have a script test.sh and the first line is #!/bin/sh then the program loader will know to run the program /bin/sh and pass the test.sh as a first argument.

The syntax of the shebang is:

#!<path to interpreter> [optional-arg]

For more information about the shebang concept, you can check out Sign up

Iulian Timis

My name is Iulian and I graduated Faculty of Electronics, Telecommunications, and Information Technology. My master's degree was in Computer Science, Information Security. I am passionate about technology and the security area. During my career I was working as a Java Developer, on the backend and frontend side, sometimes doing some DevOps tasks.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button