Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 JSON 格式的文件,它有一个 Event 字段
for file in /home/ec2-user/Workspace/events_parts/* do cat $file | jq '.Event' done
我得到了从 JSON 文件中提取的“事件”值列表。我想将此值分配给 bash 变量,以便以后可以使用它进行比较。我怎么做?
您myVar=$(some bash commands)用来将标准输出存储到变量中,然后将其称为echo "$myVar";假装shell预处理你的字符串(修剪,换行,“” "")$myVar
myVar=$(some bash commands)
echo "$myVar"
""
$myVar
甚至您可以将它放入这样的数组中:myArray=( $(some bash commands) )
myArray=( $(some bash commands) )