解析命令输出并保存到bash脚本中的var

时间:2018-01-05 22:01:14

标签: bash

VAR = “some_command” 这个命令的输出是“写错了等等的错误”

我想要的是什么 捕获第一个单词“Error”并保存到另一个变量 如果此变量等于“错误”,则执行某些操作。

我搜索了stackoverflow并用Google搜索,发现了一些相似/相同的问题,但对我没有用。

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打印“vault”而不是“Error”

任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

单引号不会运行命令。你需要使用“$(命令)”。

相关问题