简体   繁体   English

BASH 脚本从 another.txt 文件中读取变量

[英]BASH script reading variable from another .txt file

I have output.txt file, where my script is storing some outputs, I just need to get the output of ID which is in the 1st line of the output.txt in myscript.sh file, can someone suggest a way to do that我有 output.txt 文件,我的脚本在其中存储一些输出,我只需要获取 ID 的 output,它位于 Z78E6221F6393D1356681.txt 的第一行中,有人建议在 myscript.txt 文件中使用一种方式。

{"id":"**dad04f6d-4e06-4420-b0bc-cb2dcfee2dcf**","name":"new","url":"https://dev.azure.com/vishalmishra2424/82c93136-470c-4be0-b6da-a8234f49a695/_apis/git/repositories/dad04f6d-4e06-4420-b0bc-cb2dcfee2dcf","project":{"id":"82c93136-470c-4be0-b6da-a8234f49a695","name":"vishalmishra","url":"https://dev.azure.com/vishalmishra2424/_apis/projects/82c93136-470c-4be0-b6da-a8234f49a695","state":"wellFormed","revision":12,"visibility":"public","lastUpdateTime":"2021-04-22T14:24:47.2Z"},"size":0,"remoteUrl":"https://vishalmishra2424@dev.azure.com/vishalmishra2424/vishalmishra/_git/new","sshUrl":"git@ssh.dev.azure.com:v3/vishalmishra2424/vishalmishra/new","webUrl":"https://dev.azure.com/vishalmishra2424/vishalmishra/_git/new","isDisabled":false}

The snippet you posted looks like JSON and a utility named file which can guess different types of file says that too:您发布的代码片段看起来像JSON和一个名为file的实用程序,它可以猜测不同类型的文件也说:

$ file output.txt
output.txt: JSON data

You should use JSON-aware tools to extract value of id , for example jq :您应该使用 JSON 感知工具来提取id的值,例如jq

$ jq -r '.id' output.txt
**dad04f6d-4e06-4420-b0bc-cb2dcfee2dcf**

or jshon :jshon

$ jshon -e id < output.txt
"**dad04f6d-4e06-4420-b0bc-cb2dcfee2dcf**"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM