0

var="some_command" the output of this command is "Error writing something to blah blah"

what I want is capturing the first word "Error" and save to another variable if this variable is equal to "Error" do something.

I searched stackoverflow and googled, found some similar/same questions but didn't work for me.

var="vault capabilities secret/test/data"

#suppose the output of this command is "Error read has some problem blah" and 
#I want to capture the first word (i.e. "Error" ) of this output 
#and save into another variable var3

var2="echo $var | cut -d' ' -f1"
var3=`eval $var2`
$var3

$var3 prints "vault" instead of "Error"

can anyone help?

user2761895
  • 1,431
  • 4
  • 22
  • 38

1 Answers1

0

The double quotes alone won’t run the commands. You need to use “$(command)”.

Thiago Barcala
  • 6,463
  • 2
  • 20
  • 23