tags:

views:

28

answers:

2

Hi everyone,

i am trying to make a bash shell script that can add a name value pair to a text file, for example TEST=true. I am trying to make it so if the user tries to add a name that already exists for example TEST=false it does not let them do it. Can anyone tell me how to use the expr command to extract any text before the '=' character????? any help would be greatly appreciated

thanks

A: 

is that what you need?

if [[ $input =~ (.?*)= ]]

then

    echo $BASH_REMATCH is what I wanted    

    echo but just ${BASH_REMATCH[1]} 

fi

http://aplawrence.com/Linux/bash-regex.html

tarrasch
A: 

expr is an external command. you can just use bash to do it

s="TEST=true"
echo ${s%%=*}


OLDIFS="$IFS"
IFS="="
set -- $s
echo $1
IFS="$OLDIFS"
ghostdog74