Hello World in Bash

Published on (Updated: 02 May 2020)

Hello World in Bash

Welcome to the Hello World in Bash page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

#!/bin/bash

echo Hello, World!

Hello World in Bash was written by:

If you see anything you'd like to change or update, please consider contributing.

Note: The solution shown above is the current solution in the Sample Programs repository as of May 09 2018 12:47:13. The solution was first committed on May 09 2018 11:20:08. As a result, documentation below may be outdated.

How to Implement the Solution

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!