Main Menu

friends

Latest articles

if then else in BASH - the basics
13/05/2010 | mad mad mod

If then else in bash is not very difficult. However, there is something that can cause problems:Please note the spacing inside the brackets! It won't work without! string comparison
simple example:



 [ ... ]


How to boot into rescue mode on a paravirtualized XEN guest
13/03/2009 | mad mad mod

How to boot into rescue mode on a paravirtualized XEN guest
- or -
How to access a virtual machines filesystems from Domain-0

Sometimes you have to access the filesystems of a virtual machine without boo [ ... ]


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