bash 如何在 Windows 中从 gitbash 运行 jq?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53967693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run jq from gitbash in windows?
提问by DotNetDeveloper
I have gitbash
in Windows. I am trying to run jq
but its giving me error.
我gitbash
在 Windows 中有。我正在尝试运行,jq
但它给了我错误。
$ ./jq-win64.exe
jq
parse error: Invalid numeric literal at line 2, column 0
Intention: I want to use jq
to parse json.
意图:我想jq
用来解析json。
回答by VonC
Using jq-win64.exe
from github.com/stedolan/jq/releases
, I get
使用jq-win64.exe
from github.com/stedolan/jq/releases
,我得到
vonc@voncav MINGW64 /d/prgs/dl
$ ./jq-win64.exe --version
jq-1.6
vonc@voncav MINGW64 /d/prgs/dl
$ echo '{"foo": 0}' | ./jq-win64.exe .
{
"foo": 0
}
So it does work, but it then depends on the json document you are parsing with it.
If that json document is not well-formed, that would generate the error you see.
所以它确实有效,但它取决于你正在解析的 json 文档。
如果该 json 文档格式不正确,则会生成您看到的错误。
In your bash session, you can define (or add to your ~/.bashrc
) an alias:
在您的 bash 会话中,您可以定义(或添加到您的~/.bashrc
)别名:
alias jq=/path/to/jq-win64.exe
That way, you don't need to use ./jq
, but directly jq
.
这样,您就不需要使用./jq
,而是直接使用jq
。
$ echo '{"foo": 0}' | jq
In my case:
就我而言:
vonc@voncav:/$ alias jq=/mnt/d/dwnl/jq-win64.exe
vonc@voncav:/$ echo '{"foo": 0}' | jq
{
"foo": 0
}
回答by bryanbcook
I hate answers that say you need another to use another tool to download, but using https://chocolatey.org/made this incredibly simple for me.
我讨厌那些说您需要另一个工具才能使用其他工具下载的答案,但使用https://chocolatey.org/使这对我来说非常简单。
From an elevated command-prompt, run:
从提升的命令提示符运行:
choco install jq
jq
magically works from bash going forward.
jq
从 bash 开始神奇地工作。
回答by kidbrax
I just downloaded the binary to %HOMEPATH%/bin/jq-win64
and it worked right away via jq
我刚刚下载了二进制文件%HOMEPATH%/bin/jq-win64
,它立即通过jq