/ Ubuntu

Hello World Linux

Introduction

Hi, guys today we will be learning how to program a simple Hello World program in multiple languages that we can run from the bash shell in Linux. This is important for System Administration as it lets us create scripts that can be easily run with CRON (time-based job scheduler in Linux) and perform automated tasks for us.

Note

Most of this programs can be run in Ubuntu straight from the command line


Scripting Languages

Python

Python is a great scripting language that can be really powerful and has a big community for learning and support.

First we need to create a new file

nano hello_world.py

We write some code

#!/usr/bin/env python
print "Hello World Linux"

Note that the first line just tells to run the script using the python interpreter

With this command we make the file executable.

chmod +x hello_world.py

Now we run the file

./hello_world.py

Bash (Unix shell)

Bash is simple command language that is standard to most linux distributions, a must learn for linux system administration.

First we create a new file

nano hello_world.sh

We write some code

#!/bin/bash          
echo 'Hello World Linux'  

Note that the first line just tells to run the script using the bash interpreter

With this command we make the file executable.

chmod +x hello_world.sh

Now we run the file

./hello_world.sh

Perl

Perl has been nicknamed "the Swiss Army chainsaw of scripting languages" because of its flexibility and power.

First we create a new file

nano hello_world.pl

We write some code

#!/usr/bin/perl      
print "Hello World Linux"; 

Note that the first line just tells to run the code using perl

With this command we make the file executable.

chmod +x hello_world.pl

Now we run the file

./hello_world.pl

Ruby

Ruby is an object-oriented, general-purpose programming language.

First we need to create a new file

nano hello_world.rb

We write some code

#!/usr/bin/ruby
puts 'Hello World Linux'

Note that the first line just tells to run the code using perl

With this command we make the file executable.

chmod +x hello_world.rb

Now we run the file

./hello_world.rb

That's it enjoy.

10$ off on me with This Link, if you don't have your own server visit DigitalOcean servers starting at 5$ a month
10$ off on me with

Jaco Toledo

Jaco Toledo

Hi, I am a System Administrator that Lives in Jacksonville Florida and loves to experiment with anything IT, my favorite Linux Distro is Ubuntu I Love its simplicity.

Read More