Bash Scripting on Linux (The Complete Guide) Class 02 - Hello World

Originally published at: Bash Scripting on Linux (The Complete Guide) Class 02 – Hello World – Learn Linux TV

Moore’s Law of computing is very debatable nowadays, but one tech-related concept that’s absolutely NOT debatable is that everyone learning any scripting or programming language should start with the classic “Hello World” example. And you know what? LearnLinuxTV is a sucker for tradition. So in this episode, you’ll write your very own Hello World script in Bash!

My take away from this lesson is that I didn’t realise the shebang/hashbang was optional for a bash script. Every other video/tutorial on the subject I’ve seen to date infers that it is mandatory.

Thanks for the clarity :+1:

It’s not mandatory when you run a script from Bash itself - but in all other cases it’s needed. Consider the following other scenarios, where you would always want to include a shebang in your scripts:

  • You’ve changed your default shell to something else (Zsh, Fish etc.), but still wants to run your Bash script.
  • You want to run your script from an environment that is not Bash (like a the Desktop, Cron, Systemd service etc.)

And I’m sure there are other scenarios as well, where this is relevant. As soon as you enter the server/automation space, there is better reason to always include the shebang.