I'm trying to use KM variables in Shell script. See my screenshot below. I have added comments to show what I mean.
"echo" the variable returns the correct string (Green), but when I use it in "jq" command, the return result is not what I wanted (Red as opposed to Yellow).
What did I do wrong and how can I put it in the right way?
Thanks!
Edit: I think I know why it returns 4 instead of 2 names. It is due to the double quotation mark. If I put ".id=='27447',.id=='5439'" in double quotation mark, it will return 4 names (I still know why though).
The problem is, if I delete the quotation mark, the script will return error, and KM gives an error notification below:
Specifically, the double quoted string with $KMVAR_VarTest is itself within a single quoted string, and within single quoted strings, variables are not interpolated by the shell. So everything within the single quoted string is passed to jq as a parameter verbatim, and since it does not process environment variables, it sees the plain text $KMVAR_VarTest as part of it, not whatever is in the VarTest variable.
But still, the double quote poses a problem. the return result is still all names instead of the two wanted names.
I guess this is a Shell Script issue, beyond what Keyboard Maestro can do. Fortunately, I have a workaround.
With all the single quotes removed. So your use of single quotes in VarTest is completely incorrect - the first single quote (before 27477) is actually matching up with the single quote before the . in the parameter.
Thank you so much!
I have to confess that I had almost no programming background. I started learning Python about two weeks ago. Now I'm using Shell script, AppleScript, HTML, JavaScript, RegEx etc. in Keyboard Maestro. Of course, I mostly google for examples or copy codes from elsewhere and revise them to suit my need.
The experience has been amazing. But I could stuck at a very simple issue.
I did not fully understand from the wiki page example that "'"..."'" would become "..."; therefore, if I don't want the double quote, I could do '"..."' -_-!!
Neither did I know that I could remove the single quotes after ".id==". (I just followed the API example provided by a website. )
Thank you so much for your patience and detailed explanation!