Revese String Shell Scripting Linux - COFPROG

Revese String Shell Scripting Linux

Revese String Shell Scripting Linux

#!/bin/bash
var1=$1
length=`echo ${#var1}`
while [ $length -ne 0 ]
do
temp=$temp`echo $var1 | cut -c $length`
((length--))
done
echo $temp
------------------------------------------
Need to explore temp=$temp and cut commandEg. Revese String
To understand how temp=$temp works
Try following to append to existing value of variable
var1=1234
var1=$var1”56”
// to append 56 to 1234
Or
var1=$var1'56'
//
var2=56
var1=$var1`echo $varr2` // with help of command
var1=cdac
var2=acts
var1=$var1$var2Eg. Revese String
Using rev command
var1=$1
temp=`echo $var1 | rev`
echo $temp
// try tac command to display file content in reverse
orderstr=cdac
echo ${str:0:1}
echo ${str:0:2}
str=acts
i=0
while [ $i -lt ${#str} ]
do
arr[$i]=${str:$i:1}
let ++i
done
echo ${arr[2]}
echo ${arr[*]}

Previous
Next Post »

BOOK OF THE DAY