Newbie trying to learn bash and jq. I'm on a Windows machine so I thought I'd test with git bash - I thought git bash was identical to bash running on Linux.
For my test, I'm trying to extract a list from JSON into a variable. However, I was getting (what I thought to be) odd results, so I tried the same code on Ubuntu in a Docker container. Ubuntu gave me the expected results.
The left side is Ubuntu running in Docker. The right side is git bash. Can someone explain why the two results are different?
Sorry, here's the text:
Ubuntu:
root@ac88bd1c736e:/usr/local/bin# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.2 LTS"
root@ac88bd1c736e:/usr/local/bin# jq --version
jq-1.6
root@ac88bd1c736e:/usr/local/bin# ls -la
total 20
drwxr-xr-x 1 root root 4096 Mar 8 16:48 .
drwxr-xr-x 1 root root 4096 Mar 1 02:03 ..
-rwxr-xr-x 1 root root 56 Jul 25 2022 service.py
-rwxr-xr-x 1 root root 96 Mar 7 18:21 test.json
root@ac88bd1c736e:/usr/local/bin# cat test.json
{
"foo": "bar",
"access": [
"rangers",
"avs"
],
"blah": {
"bizz": "buzz"
}
}root@ac88bd1c736e:/usr/local/bin# foo=`cat test.json | jq .access`
root@ac88bd1c736e:/usr/local/bin# echo $foo
[ "rangers", "avs" ]
root@ac88bd1c736e:/usr/local/bin#
git bash:
leehenry@PW03T2JD MINGW64 ~/..../bash
$ git --version
git version 2.39.2.windows.1
leehenry@PW03T2JD MINGW64 ~/..../bash
$ jq --version
jq-1.6
leehenry@PW03T2JD MINGW64 ~/..../bash
$ cat test.json
{
"foo": "bar",
"access": [
"rangers",
"avs"
],
"blah": {
"bizz": "buzz"
}
}
leehenry@PW03T2JD MINGW64 ~/..../bash
$ foo=`cat test.json | jq .access`
leehenry@PW03T2JD MINGW64 ~/..../bash
$ echo $foo
]avs"ers",
leehenry@PW03T2JD MINGW64 ~/..../bash
$

$ echo $foo→]avs"ers",is typical of a Windows format file being processed on a UNIX/Linux machinejqoutputs DOS-formatted text on the latter system, while the shell expects Unix-formatted text. Where did you installjqfrom on that system?