0

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

marcell
  • 1,498
  • 1
  • 10
  • 22
mrblippy
  • 311
  • 2
  • 3
  • 10

2 Answers2

1

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
  • 327,991
  • 56
  • 259
  • 343
0

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
  • 2,630
  • 8
  • 37
  • 61