I know many have asked similar questions, but I can't make it work.
I have a file called Dependencies:
Accounts
Aggregates
Blog
Configuration
Contacts
Contents
DataTypes
Forms
Geo
Globalization
Media
Modules
Navigation
Podcast
Seo
Social
Taxonomy
Tracking
Vlog
And I have this code to turn it into a JSON array string:
DependenciesPath=/$Organization/Common/Dependencies
mapfile -t DependenciesArray < $DependenciesPath
DependenciesArray+=('Infra')
export dependencies=$(echo '%s\n' "${DependenciesArray[@]}" | jq -R . | jq -s .)
Then I have this code to pass it to node.js:
node /$Organization/$Repository/LocalizationHelper.js $File $astFile "$dependencies"
The problem is that I get this in my LocalizationHelper.js file:
[
"%s\\n Accounts Aggregates Blog Configuration Contacts Contents DataTypes Forms Geo Globalization Media Modules Navigation Podcast Seo Social Taxonomy Tracking Vlog Infra"
]
As you can see items are not separate from each other and that %s\\n is also redundant at the beginning. Those is what I want (a valid JSON array):
[ "Accounts", "Aggregates", "Blog", ...]
I'm stuck here. What should I do? I want to use const dependencies = JSON.parse(process.argv[4]) to convert it into a JavaScript Array in my code.
echo '%s\n' "${DependenciesArray[@]}"? Did you mean to useprintf?