Main Menu

friends

Banner

Latest articles

The Budget Traveller's Guide to Sleeping in Airports
20/04/2010 | mad mad mod

The Budget Traveller's Guide to Sleeping in Airports:  www.sleepinginairports.net  "For travellers who are REALLY on a budget and are looking for a way to skim a few bucks off their travel e [ ... ]


How to get the current network bandwidth usage on Linux
07/04/2010 | mad mad mod

There are many ways how to get the current bandwidth usage on Linux. This is a very simple shell script that lists the network statistic every second: #!/bin/bash
if [ -z "$1" ]; then
       [ ... ]


Other Articles
Facebook MySpace Twitter Digg Delicious Stumbleupon Google Bookmarks 

Designed by:
SiteGround web hosting Joomla Templates
Hello World in BASH E-mail
programming

This article describes how to write and execute a "Hello World" bash script on Linux (Fedora).

 

1. the prerequisites

  • a text editor of your choice (e.g. vi)
  • the bash shell


make sure you have installed the bash shell:

# rpm -qa|grep bash
bash-3.2-20.fc8

 

If it is not installed yet, you can install it with yum (you need to be root to do that):

# yum install bash

 

Well, I bet it is already installed :-)

 

 

2. write the code


open an empty file with a text editor (e.g. vi):


# vi helloworld.sh



now write the following lines into it:


#!/bin/bash
echo "Hello World!"



save the file and exit vi with ":wq + enter"

 

explanation


#!/bin/bash

This tells the system to use the /bin/bash interpreter to execute the script. You can find out the full path of your bash interpreter by entering the following command:


# which bash
/bin/bash





echo "Hello World!

This prints out the string "Hello World!".

 


3. make the script executable



# chmod u+x helloworld.sh




4. run the program


you can now execute the script program with:


# ./helloworld.sh

Hello World!

 

- or -

 


# bash helloworld.sh

Hello World!

Comments (0)
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:angry::angry-red::evil::idea::love::x:no-comments::ooo::pirate::?::(
:sleep::););)):0
Security
Please input the anti-spam code that you can read in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."

 
mad mad mod, Powered by Joomla! and designed by SiteGround web hosting