I created a bash script that, amongst other things, modifies a json file with jq
.
The line doing that is:
cat <<< $(jq '.eslintConfig.extends="@gbrachetta/eslint-config" | .+ {prettier: "@gbrachetta/prettier-config"}' package.json) > package.json
This works great, and running this bash script (MacOS) produces a perfectly formatted json file:
{
"name": "test",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "10.1.3",
"prop-types": "^15.7.2",
"react": "17.0.2",
"react-dom": "17.0.2"
},
"devDependencies": {
"@gbrachetta/eslint-config": "1.3.0",
"eslint": "^7.24.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^4.2.0",
"prettier": "^2.2.1"
},
"eslintConfig": {
"extends": "@gbrachetta/eslint-config"
},
"prettier": "@gbrachetta/prettier-config"
}
I wanted to improve my script and created a bash script with functions.
The result is great, and the cat
command modifies the json file as expected, but the resulting file isn't formatted and it's outputted in a single line.
This is what I get with my functional script:
{ "name": "test", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start" }, "dependencies": { "next": "10.1.3", "prop-types": "^15.7.2", "react": "17.0.2", "react-dom": "17.0.2" }, "devDependencies": { "@gbrachetta/eslint-config": "1.3.0", "eslint": "^7.24.0", "eslint-config-airbnb": "^18.2.1", "eslint-config-prettier": "^8.2.0", "eslint-plugin-import": "^2.22.1", "eslint-plugin-jsx-a11y": "^6.4.1", "eslint-plugin-prettier": "^3.4.0", "eslint-plugin-react": "^7.23.2", "eslint-plugin-react-hooks": "^4.2.0", "prettier": "^2.2.1" }, "eslintConfig": { "extends": "@gbrachetta/eslint-config" }, "prettier": "@gbrachetta/prettier-config" }
The cat
line is identical in both scripts, and the resulting json (except for the formatting) is the same in both cases, but I don't understand why running the cat command from a function outputs the file in one line.
I'm really curious to know what I could be doing wrong!