Welcome back to yet another article in the Hello World in Every Language series! Today, we’re going to continue the trend of community submissions with Hello World in Bash, a solution shared by Abdus Samad Azad.
Table of Contents
Bash Background
According to Wikipedia, Bash is a command language first released back in 1989. Despite its age, Bash is till heavily maintained with changes tracked in git
.
In terms of features, Bash supports variables, piping, globbing, control flow, and even iteration. Of those features, perhaps the coolest is globbing—also known as wildcard matching. Globbing can be used to retrieves sets of files that match a wildcard expression.
Beyond that, Bash is ubiquitous in the Linux/Unix/Mac communities. After all, it’s the standard shell on most systems. In fact, it even has support on Windows 10. That means shell scripts are fairly portable. However, users will have to pay attention to code that doesn’t conform the Bourne shell standards.
You’d be hard pressed to find a popular system that doesn’t support Bash today. Even Jenkins, a continuous integration utility, supports Bash scripting during builds.
Hello World in Bash
At any rate, let’s implement Hello World in Bash:
echo Hello, World!
Or, if we want to be a bit more verbose:
#!/bin/bash echo Hello, World!
As we can see, printing “Hello, World!” in Bash is quite simple. All we do is call the echo command to print the string.
As an added note, the shebang (#!) tells the environment how to run the script. In this case, we want to run the script using Bash. But, we can use this same notation for other languages as well:
#!/usr/bin/env python print("Hello, World!")
#!/usr/bin/env ruby puts "Hello, World!"
#!/usr/bin/env node console.log("Hello, World!")
Here, we have Hello World in Python, Ruby, and Node.js, respectively. Each of these scripting languages can leverage the shebang syntax for easy execution in Unix, Linux, and Mac environments.
How to Run the Solution
If we want to run the solution, we can easily leverage an online Bash shell. To use the tool, we just have to drop our solution into the editor and hit run.
Alternatively, if we have a bash shell available, we can easily download the script, navigate to its folder from the command line, and run it:
./hello-world.sh
In fact, even Windows 10 users can leverage Bash. How-To Geek has a nice tutorial on how to use Bash on Windows 10. If that sounds interesting, check it out!
Sample Programs in Every Language
And, that’s it for Hello World in Bash. If you’re interested in any languages that haven’t made it in the series yet, don’t be afraid to share one in the comments. I’m always looking for new languages to expand the series.
Again, I have to thank Abdus Samad Azad for their contribution to the series. If you’d like to be mentioned in a future article, hop on over to the repository and make your contribution. I always make sure to give my contributors credit.
Oh, one last thing: make sure you share this article if you enjoyed it. I’m sure others will as well!
Recent Posts
It seems I'm in my mentorship arc because I can't stop writing about how to support students. Today, we're going to tackle one of the more heartbreaking concerns that students have: the idea that...
For my friends in the humanities, it probably comes as a surprise, but our STEM programs are really allergic to open-ended projects. As a result, I figured I would pitch them today.