Reputation: 311
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 to 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
Upvotes: 0
Views: 729
Reputation: 342849
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"
Upvotes: 1
Reputation: 2680
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
Upvotes: 0