Issue
How can i get the values inner depends
in bash script?
manifest.py
# Commented lines
{
'category': 'Sales/Subscription',
'depends': [
'sale_subscription',
'sale_timesheet',
],
'auto_install': True,
}
Expected response:
sale_subscription sale_timesheet
The major problem is linebreak, i have already tried | grep depends
but i can not get the sale_timesheet
value.
Im trying to add this values comming from files into a var, like:
DOWNLOADED_DEPS=($(ls -A $DOWNLOADED_APPS | while read -r file; do cat $DOWNLOADED_APPS/$file/__manifest__.py | [get depends value])
Example updated.
Solution
If this is your JSON file:
{
"category": "Sales/Subscription",
"depends": [
"sale_subscription",
"sale_timesheet"
],
"auto_install": true
}
You can get the desired result using jq
like this:
jq -r '.depends | join(" ")' YOURFILE.json
This uses .depends
to extract the value from the depends
field, pipes it to join(" ")
to join the array with a single space in between, and uses -r
for raw (unquoted) output.
Answered By - Thomas Answer Checked By - David Goodson (WPSolving Volunteer)