Displaying posts categorized under

BASH Shell Scripts

BASH Script for copying files recursively form one directory to another

#!/bin/bash   # Author : Antony # Date : 19/07/2008 # Description : Script for copying files recursively form one directory to another   # Get Source and Destination Directory Paths echo "Enter the source path" read src echo "Enter the Destination path" read dest   for file in `find $src -name "*.*"` do echo [...]

BASH Script – Swapping Two Values

#!/bin/bash # Author : A.Antony # Date : 08/10/2007   echo "Enter First Value(a) : " read a echo "Enter Second Value (b): " read b echo "Before swap, a = $a and y = $b" c=$a a=$b b=$c echo "After swap, a = $a and b = $b"

BASH Script – Arithmetic Manipulations

Three options are used for arithmatic manipulations 1) expr 2) bc 3) (( )) Example #Program for Arithmetic Operations #!/bin/bash #Author : Antony #Date : 05/10/2007   echo "Enter the first Number " read x echo "Enter the second Number " read y #Method 1 add=<span style="font-weight: bold; font-style: italic;">$(( $x + $y ))</span> echo [...]

BASH Script : Displaying Text in BOLD format

#!/bin/bash#Author : Antony#Date : 05/10/2007 echo “Enter the text “read texttput boldecho $texttput reset Output of this ProgramEnter the text Antony Antony

BASH Scripts – Program for 'while' loop

#Program for ‘while’ loop# Author : Antony# Last date of modification : 29/07/2007#Syntax# while [ condition ]# do# statement# done x=1while [ ! $x -ge 5 ]doecho $xx=`echo “$x+1″ | bc`done y=1until [ $y -ge 5 ]doecho $yy=`echo “$y+1″ | bc`done

BASH Scripts – Program for 'case' statement

#Program for ‘case’ statement# Author : Antony# Last date of modification : 29/07/2007#Syntax# case word in# pattern1)# list1 ; ;# pattern2)# list2 ; ;# esac #Simple Exampleecho “Select the Option”echo “1.Terminal”echo “2.Firefox”echo “3.Text editor” read name case $name in 1) echo “Terminal is running…” echo “`xterm`” ;; 2) echo “Firefox is running…” echo “`firefox`” ;; [...]

BASH Scripts – Displaying output using echo

#Displaying Various Output Formats# Author :Antony# Last Date of Modification :27/07/2007 #Three Types of quotes are# 1.Single quote# 2.Double quote# 3.Backslash #Examples echo “Current Date is `date`” echo This \’song\’ is so nice echo The Movie \”Gladiator\” won 7 oscar awardsecho ‘The total amount is $10000′ echo “The total amount is \$1000″ echo “Wow! This [...]

BASH Scripts – Program for Environment Variables

#Use of Environment Variables# Author:Antony# Last Modification Date :27/07/2007 #Indicates the Current working directoryecho “The Current Working directory is $PWD” # Display User IDecho “Current User ID is $UID” #Generating random integers between 1 and 32767echo “The random number is $RANDOM” #Information about pathecho “The Path details”echo $PATH #Home Directory informationecho “Your Home directory is [...]

Shell Script Basics – Program for variables

#Program for variables# Author:Antony# Last Date of Modification :27/07/2007#Variable name can contain # a-z / A-Z # 0-9 # – (underscore)# can start with only _ or a-z/A-Z #Two types of variables # 1. Scalar variables/name value pairs # 2. Array Variables # 1.Scalar variables var=”This is the Demo Program for Variables” #To diplay the [...]

Hoe to run shell script in Linux terminal

Shell Scripting is one of the powerful tool for administrator . few types of shell are available in Linux OS (like sh, csh, tcsh, ksh,BASH) .Bash is the default shell for all Linux ox . For Creating Shell programs# vi filename.sh For Running Shell Programs# sh filename.sh or# chmod 744 filename.sh#./filename.sh