Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not open file lol.json: Permission denied using Jq?

I am facing some kind of permission issue here. I am able to read a file with cat, make changes to it using nano but for some reason, jq is having permission issues. Here is what I am facing:

msp@coolpad:~/projects/lol$ jq .name lol.json
jq: error: Could not open file lol.json: Permission denied

On checking permissions, this is what I get:

msp@coolpad:~/projects/lol$ ls -l
total 4
-rw-rw-r-- 1 msp msp   0 Sep 27 04:04 lol-domains.txt
-rwxrwxrwx 1 msp msp 593 Sep 27 04:38 lol.json

As you can see, I have tried giving it 777 permission, still it's showing Permission denied. I know this is not a good idea to set 777 permission and I fully intend to change it back to 664 once the issue is resolved. Anyhelp would be appriciated.

Update 1: I have tried re-installing jq from snap but still, it doesn't solve the problem.

Update 2: Output of cat lol.json

msp@coolpad:~$ cat lol.json
{"name":"lol"}

Update 3: Output of echo '{"name":"lol"}' | jq .name

msp@coolpad:~$ echo '{"name":"lol"}' | jq .name
"lol"

Update 4: One work-around that poped up in comments:

cat lol.json | jq .name

like image 793
Panda Avatar asked Sep 27 '19 04:09

Panda


1 Answers

You installed jq through Ubuntu's snap. Uninstall it and re-install it through apt:

sudo snap remove jq
sudo apt install jq

Snap packages have "confinement" which is either "strict" or "classic". In this case jq was packaged as "strict" meaning it has its own /tmp/snap.jq/ directory and cannot read the system /tmp directory and a bunch of other directories. Packages that want to use "classic confinement" have to be manually approved by the people in charge of Snapcraft and you must pass --classic when installing them, like this: sudo snap install <package_name> --classic.

Just never install command line tools with snap, at least without --classic. This error is intended behavior and they're not going to change it.

like image 174
Boris Avatar answered Nov 03 '22 05:11

Boris