You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 via os.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 to export the NODE variable to the environment and then reference it within jello using os.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 using ast or even eval.
Do you know of any other cool tricks or ways to accomplish this task? I'm also thinking about possibly adding a --var argument to jello in the future so you can assign a variable directly in the jello command instead of using the environment. I'll have to noodle on that to see if it's something users really want.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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