Aug 30, 2010

MOre on bash

Functions
function my_function{
my_code}

Eg:
#!/bin/bash
function quit{
exit}
function hello{
echo Hello World!
}
hello
echo foo
quit

functions with parametrs
function my_function{
echo $1
echo $2
}
my_function para1 para2

In this the parametrs we are sending are assigned in the order of $1, $2, $3 ....
The $0 will give the script name that we excecute.

Options
#!/bin/bash
OPTIONS="Hello Quit"
select opt in $OPTIONS; do
if["$opt"="Quit"]; then
echo Done
exit
elif["$opt"="Hello"]; then
echo Hello World
else
clear
echo bad option
fi
done

No comments:

Post a Comment

Your comments are always welcome ...