linux - How to read parts of a command output (after a certain character) into a bash variable? -
so have command returns output in following form
># command var1=abc var2=def var3=123
and want read var1 , var3 command shell script. logically, run following 2 commands
># command | grep var1 var1=abc ># command | grep var3 var3=123
how capture part comes after first equal sign? (so "${var1}" = "abc" , "${var3}" = "123"). of note, there equal sign in vale of either variable, need keep after first equal sign, including subsequent ones
you can use awk:
command | awk -f = '/var1|var3/{print substr($0, index($0, "=")+1)}' abc 123
breakup:
/var1|var3/ # searches var1 or var3 index($0, "=") # search = in record substr # gets substring after first =
Comments
Post a Comment