Tuesday, 6 November 2012

shell script to perform operations on string

shell script to perform operations on string

*day.sh

#!/bin/bash
day=`date "+%a"`
if [ "$day"=="mon" ]
then
echo "weekend is over"
fi
~   

OUTPUT:[root@domain30 fourth]# sh day.sh 

weekend is over


*cmp.sh

#!/bin/bash
com="wipro"
if [ "$com" \< "z" ]
then
echo "the comapny name being with the letter less than z"
fi

OUTPUT:[root@domain30 fourth]# sh cmp.sh 

the comapny name being with the letter less than z


*strmerg.sh

#!/bin/bash
echo "enter the first name-->"
read fst

echo "enter the last name-->"

read lst

echo "the complete string is--> $fst$lst"



OUTPUT:

[root@domain30 fourth]# sh strmerg.sh 
enter the first name-->
mahesh
enter the last name-->
maske
the complete string is--> maheshmaske
                                                                                                                                              
                                                                                                                                              
                                                                                                                                                                                                                                                                                           
                                                                                                                              
*strlength.sh

#!/bin/bash
str=mahesh
echo ${#str}
echo `expr length $str`
echo `expr "$str"`


OUTPUT:

[root@domain30 fourth]# sh mahesh.sh 
6
6
mahesh                                                                                                                                              
                                                                                                                                              
                                                                                                                                              
                                                                                                                                              
      


No comments:

Post a Comment