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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -