Tip: Using BASH variables in jello queries #26
kellyjonbrazil
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here's how to use BASH variables in your
jello
queries. Do you have any other methods?Updating an existing Object with an Object contained in a BASH variable
Referencing the variable via BASH
Let's say you have the following JSON file:
And you want to insert the following Object under
nodes
:You can do it in BASH with the following:
But notice I used double quotes there? I did that so I could reference
$node
without any funky escaping. If we need to put single quotes around our query, then we can do this another way:Referencing the variable within
jello
viaos.getenv()
Let's do the same thing, but this time we'll surround our query in single quotes. When we do that, we no longer have access to the
$node
variable, since it will become a string literal. One way around this is toexport
theNODE
variable to the environment and then reference it withinjello
usingos.getenv()
.os
is conveniently already imported so we can use it right away:Notice the use of
json.loads()
there? Since environment variables are always assigned as strings, we need to convert the string into a dictionary somehow.json.loads()
is an easy way to do it, though there are other methods like usingast
or eveneval
.Do you know of any other cool tricks or ways to accomplish this task? I'm also thinking about possibly adding a
--var
argument tojello
in the future so you can assign a variable directly in thejello
command instead of using the environment. I'll have to noodle on that to see if it's something users really want.Beta Was this translation helpful? Give feedback.
All reactions