Manipulate string in shell script

I am writing a shell script for some purpose. I have a variable of the form -- var1 = "policy=set policy"

Now I need to manipulate the variable var to get the string after index =. that is i should have "set polcy". Also I need to to this for many other variables where the value of "=" is not constant. Like

var2 = "bgroup = set bgroup port"
var3 = "utm = set security utm"
Please give an idea how to do it.

You can use the cut command for this

var1="policy=set policy"
var1value=`echo $var1 | cut -d"=" -f2`

Note : There should not be any space between the shell variable and it assignment value.

var1 = something => incorrect
var1=something => correct

regards,
Ahamed

Could you elaborate what exactly you need.

#!/bin/bash
##!/bin/bash
var2="bgroup = set bgroup port"
var3="utm = set security utm"
echo "$var2 --> '${var2# = }'"
echo "$var3 --> '${var3# = }'"
# You can also
for V in var2 var3; do
echo "${!V} --> '${!V# = }'"
done#

1 Like