Comments (3)
Based on your php.ini
and the errors you got, I'm 100% certain that you've fallen prey to the word-splitting that happens after command substitution (see https://man7.org/linux/man-pages/man1/bash.1.html#EXPANSION for details). Remembering the order of expansions seems to be the #1 problem for most bash scripters.
I strongly suggest you use shellcheck
to error-check your script. I use it religiously on all my scripts, and running it on your script surfaced almost a dozen issues, including several places where you should've double-quoted to prevent unwanted word-splitting that caused your errors. If you don't have the shellcheck
binary on your system, use the online checker instead: shellcheck.net.
from jo.
Does anyone have an idea what I'm doing wrong or what I could do to fix it?
Not without knowing exactly how you invoked jc
in your script.
from jo.
I've tried everything I can think of, for example using a pipe:
cat "/etc/php/7.4/fpm/php.ini" | jc -m --ini | jo state=present conf:=-
This works fine on it's own, you can use a minimal file for testing, for example create /tmp/php.ini
[PHP]
engine = On
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
[CLI Server]
cli_server.color = On
Then run:
cat "/tmp/php.ini" | jc -m --ini | jo state=present conf:=- | jq
and you get:
{
"state": "present",
"conf": {
"PHP": {
"engine": "On",
"error_reporting": "E_ALL & ~E_DEPRECATED & ~E_STRICT"
},
"CLI Server": {
"cli_server.color": "On"
}
}
}
But with a more complicated example:
#!/usr/bin/env bash
versions=(7.4 8.0)
sapis=(cli fpm)
jo state=present versions=$(
for v in ${versions[@]}
do
echo ${v}=$(
jo state=present $(
for s in ${sapis[@]}
do
echo sapis[${s}]=$(
cat "/tmp/php.ini" | jc -m --ini | jo state=present conf:=-
)
done
)
)
done
)
I get:
Argument `&' is neither k=v nor k@v
Argument `~E_DEPRECATED' is neither k=v nor k@v
Argument `&' is neither k=v nor k@v
Argument `~E_STRICT"},"CLI' is neither k=v nor k@v
Argument `&' is neither k=v nor k@v
Argument `~E_DEPRECATED' is neither k=v nor k@v
Argument `&' is neither k=v nor k@v
Argument `~E_STRICT"},"CLI' is neither k=v nor k@v
Argument `&' is neither k=v nor k@v
Argument `~E_DEPRECATED' is neither k=v nor k@v
Argument `&' is neither k=v nor k@v
Argument `~E_STRICT"},"CLI' is neither k=v nor k@v
Argument `&' is neither k=v nor k@v
Argument `~E_DEPRECATED' is neither k=v nor k@v
Argument `&' is neither k=v nor k@v
Argument `~E_STRICT"},"CLI' is neither k=v nor k@v
{"state":"present","versions":"7.4={\"state\":\"present\",\"sapis\":{\"cli\":\"{\\\"state\\\":\\\"present\\\",\\\"conf\\\":{\\\"PHP\\\":{\\\"engine\\\":\\\"On\\\",\\\"error_reporting\\\":\\\"E_ALL\",\"fpm\":\"{\\\"state\\\":\\\"present\\\",\\\"conf\\\":{\\\"PHP\\\":{\\\"engine\\\":\\\"On\\\",\\\"error_reporting\\\":\\\"E_ALL\"}}","8.0":{"state":"present","sapis":{"cli":"{\"state\":\"present\",\"conf\":{\"PHP\":{\"engine\":\"On\",\"error_reporting\":\"E_ALL","fpm":"{\"state\":\"present\",\"conf\":{\"PHP\":{\"engine\":\"On\",\"error_reporting\":\"E_ALL"}}}
If I amend the /tmp/php.ini
file so there are no spaces in sections or special characters in values (removing ~
and &
), for example:
[PHP]
engine = On
[Session]
session.save_handler = files
[apc]
apc.enabled = 1
I still get:
{"state":"present","versions":"7.4={\"state\":\"present\",\"sapis\":{\"cli\":{\"state\":\"present\",\"conf\":{\"PHP\":{\"engine\":\"On\"},\"Session\":{\"session.save_handler\":\"files\"},\"apc\":{\"apc.enabled\":\"1\"}}},\"fpm\":{\"state\":\"present\",\"conf\":{\"PHP\":{\"engine\":\"On\"},\"Session\":{\"session.save_handler\":\"files\"},\"apc\":{\"apc.enabled\":\"1\"}}}}}","8.0":{"state":"present","sapis":{"cli":{"state":"present","conf":{"PHP":{"engine":"On"},"Session":{"session.save_handler":"files"},"apc":{"apc.enabled":"1"}}},"fpm":{"state":"present","conf":{"PHP":{"engine":"On"},"Session":{"session.save_handler":"files"},"apc":{"apc.enabled":"1"}}}}}}
Based on past experience I strongly suspect this is caused by an error in my poor Bash scripting...
from jo.
Related Issues (20)
- Embedded spaces not working. HOT 2
- Suggestion: Automatic pretty printing if stdout is a tty HOT 4
- How to get jo installed on Ubuntu? HOT 4
- Nest jo in an array HOT 3
- Tests failing (Ubuntu 20.04) HOT 8
- RFE: jo x=1 x=2 to create lists HOT 2
- Request: Add ability to not interpret file substitution chars with arg instead of only escaping. HOT 18
- Reading words from variable in shell script? HOT 1
- RFE: Do not split quoted keys with -d HOT 2
- Gaps in variable HOT 2
- Delete nested element HOT 5
- Assertion `utf8_validate(str)' failed - again? HOT 9
- Suberflous `\` if try to escape `}` in value HOT 8
- feature allow string vals with spaces deep nested HOT 1
- Question: how to produce multiline strings? HOT 2
- UTF-8 crash - `Assertion failed: (utf8_validate(str))` HOT 5
- Passing an empty file with `@` syntax now throws an error on 1.7 HOT 5
- FAIL: tests/jo.test 20 - read json array elements HOT 7
- 1.9 build for Windows missing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jo.