Monday, February 2, 2009

Using variables in bash script.

#!/bin/bash
#===============================================================================
#
# FILE: vars_bash.sh
#
# USAGE: ./vars_bash.sh
#
# DESCRIPTION: Using variables in bash script.
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Parag Kalra (), paragkalra@gmail.com, www.paragkalra.com
# COMPANY: As of now Persistent System LTD, www.persistentsys.com
# VERSION: 1.0
# CREATED: Sunday 01 February 2009 11:16:38 IST IST
# REVISION: ---
#===============================================================================

echo "uninitialized_variable = $uni_var"

null_variable=
echo "null_variable = $null_variable"

let "num_var2 += 2"
echo "$num_var2"

num_var1=1
let "num_var1 += 4"
echo "$num_var1"

#-------------------------------------------------------------------------------
# Unsetting a variable
#-------------------------------------------------------------------------------
num_var=13
echo "$num_var"
unset num_var
echo "$num_var"


#-------------------------------------------------------------------------------
# Different ways a variable can be assigned
#-------------------------------------------------------------------------------
a=13;
echo $a

let a=a+13
echo $a

echo "Enter the value you want to assign to variable a: "
#read a

for a in 1 2 3
do
echo $a
done

list1=`ls -l`
echo $list1

list2=$(ls -l)
echo $list2

#-------------------------------------------------------------------------------
# Converting integers to strings and vice-versa
#-------------------------------------------------------------------------------
a=1234
echo $a

let a=a+1
echo $a

a=${a/35/TF}
echo $a

a=${a/TF/13}
echo $a

No comments: