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
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!")
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:
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!
As much as I love to write, I don't read nearly as much as I should. That's why when I recommend an article, you should probably check it out.
If you're looking to learn some Python, I have plenty of practice problems to get you started.