Hello World in Bash

Hello World in Bash Featured Image

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 AzadOpens in a new tab..

Table of Contents

Bash Background

According to WikipediaOpens in a new tab., Bash is a command language first released back in 1989. Despite its age, Bash is till heavily maintained with changes tracked in gitOpens in a new tab..

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 shellOpens in a new tab. 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 shellOpens in a new tab.. 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 scriptOpens in a new tab., 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 10Opens in a new tab.. 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 repositoryOpens in a new tab. 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!

Sample Programs in Every Language (44 Articles)—Series Navigation

For 100 Days of Code, I’ve decided to implement a few sample programs in as many languages as possible. Each implementation details a brief history of the language and a description of the code.

The plan for the series is to explore the major general-purpose language like Java, Python, C, C++, and C#. From there, we’ll take a look at some sample programs in web development languages like Ruby, PHP, and JavaScript. As we continue, we’ll cover proprietary languages like Swift and Objective-C. Eventually, we’ll start to tackle less popular languages like Rust, x86, and Verilog. Finally, we’ll play around with some of the esoteric languages like Brainf*ck and LOLCODE.

Who knows? Maybe the Sample Programs in Every Language series will become so popular it’ll never end. To help this series grow, consider sharing it on social media with your friends. Or, if you have a language you want to see, drop your suggestion in the comments.

Jeremy Grifski

Jeremy grew up in a small town where he enjoyed playing soccer and video games, practicing taekwondo, and trading Pokémon cards. Once out of the nest, he pursued a Bachelors in Computer Engineering with a minor in Game Design. After college, he spent about two years writing software for a major engineering company. Then, he earned a master's in Computer Science and Engineering. Today, he pursues a PhD in Engineering Education in order to ultimately land a teaching gig. In his spare time, Jeremy enjoys spending time with his wife, playing Overwatch and Phantasy Star Online 2, practicing trombone, watching Penguins hockey, and traveling the world.

Recent Posts