Pages

Showing posts with label Shell script. Show all posts
Showing posts with label Shell script. Show all posts

Saturday, March 19, 2011

Some string manipulations is shell script

var="hai hello world tom"

pattern output
echo ${var%%hello*} //hai
echo ${var%%tom} //hai hello world
echo ${var##*hello} //world tom
echo ${var##hello*} //hai hello world tom
echo ${#var} // 19

Some shell script Experiments

1. Capture Ctrl+c Signal using Shell script

trap 'echo pressed c' 2

read f


2. Getting current PID using shell script

#!/bin/sh

echo $$

3. Use of arrays in shell script

newmap['name']="Abc"

newmap['designation']="SSE"

newmap['company']="xyz"


echo ${newmap['company']}

echo ${newmap['name']}

echo "after"

newmap=(Abd SSE HRD)

echo ${newmap[0]}

echo ${newmap[1]}

echo ${newmap[2]}

for i in newmap

do

echo $i

done