-
Can you not do
exit
at the bottom, and putecho Finished!
? We will find it easier to know that the program works correctly. Add -S or --show-error so that we see what went wrong. Makecurl
's response include the query (so that when it fails, we know what it failed for, imagine you got just a HTTP failure code in the logs - not helpful to work with). -
Instead of
tr -d '"'
dojq -r
, “raw” - it does what you want :) -
https://www.shellcheck.net/ tells you things about the program -and that it's mostly fine, no warnings and merely notes- could you apply at least the one about $() instead of ``?
-
I've been collecting useful JQ programs on https://www.ebi.ac.uk/seqdb/confluence/display/GXA/JQ+tips I've just put exactly the one you want (get all baseline experiments) as:
curl http://www.ebi.ac.uk/gxa/json/experiments | jq -r '.aaData | map(select(.experimentType=="RNASEQ_MRNA_BASELINE")) | map(.experimentAccession)[]'
- instead of a for loop you can
curl http://www.ebi.ac.uk/gxa/json/experiments | jq -r '.aaData | map(select(.experimentType=="RNASEQ_MRNA_BASELINE")) | map(.experimentAccession)[]' | while read -r experimentAccession {
// the program goes here
echo "$experimentAccession"
}
Feel free to not apply the last two comments, the solution with iterating through indices is unusual for bash but it should work. At the very least apply 0) the rest would've helped you before you started, now that you have a working program it's mostly so you can get productive with shell scripting / jq if you want to.
Well done for solving the problem! I think it will work. I like that the script has:
- a clear usage message
- clear usage of variables
- the program's reporting on its progress, so when it fails we will know
- good usage of curl's options (e.g. -o to /dev/null because we don't need it)