From the course: Learning Linux Shell Scripting

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

The shebang

The shebang - Linux Tutorial

From the course: Learning Linux Shell Scripting

Start my 1-month free trial

The shebang

- [Instructor] Let's open hello.sh again. It has a problem which we should take care of before we forget. Our script code is written specifically for the Bash shell. While Bash is incredibly popular, it is not the only shell around. If someone tried to run it on one of those other shells, the results are unpredictable and that's not good. We want our scripts to run as we designed them. We need to make sure that our script only runs on Bash. Luckily there's an easy way to do that. So, we go to the top of the page, we insert a new line. Every shell script should be begin with the interpreter line colorfully known as the shebang. This line tells the system which command processor should handle this script. For Bash, it is #!/usr/bin and then /env space bash. The shebang must be the first line of the file or it will simply be ignored like a comment. You may also see the Basher bang written as #!/bin/bash. While both will work, the form is a bit more portable since it will search for Bash…

Contents