How to define a variable in a BASH script by using a JSON file online?
Hello,
I would like to modify an existing script of mine that uses a manually defined "MCVERSION" variable and make it define that variable instead based on this JSON file stored online: https://s3.amazonaws.com/Minecraft.D.../versions.json
Within that JSON, I 'm looking for this information:
I want $MCVERSION to equal the "latest/release" value above (in this case, MCVERSION=1.7.2). I'm perfectly OK with pulling the JSON file down locally first via "wget" command. In fact, I'd prefer that so I can reference it if needed if my script fails (in case they change their JSON file format).
Here is my script (not that it matters too much for this example, I doubt).
Currently, the script results in creating this file:
/home/mcmaps/.minecraft/versions/1.7.2/1.7.2.jar
The goal is to do that without ever having to manually modify the MCVERSION variable in this script.
To do so generically might be beyond even bash variables. But you could always smash the paths, just might have to have counters for multiple contructs at a level... so you might have
Might not be horrible writing something in awk or sed to produce this type of output so it can be sourced into a program. Due to the counters, awk is the better candidate.
In your case, it could be very simple if you are just needing the one thing though. Just pull the line out, and do a simple translate.
(I guess I'm trying to push you toward a solution without handing one to you)
This is a hack but will give you the latest version from the URL you posted.
The command "curl" IS required otherwise the default builtins are used...
Note this is on a Macbook Pro 13 inch, circa August 2012, OSX 10.7.5, Default bash terminal.
I have left the commented out commands so that you can re-edit them in again to see
how it works...
The results on this machine...
It is now up to you to modify as required...
Hello.
I'm new to bash script and I'm learning the basics by writing some scripts.
Recently a friend of mine asked me if I could try to write a script to him to automate a couple of processes that uses JSON RPCs.
I'll try to explain in few words the workflow just to contextualize the problem.... (48 Replies)
Hello guys,
I want to parse a JSON file in order to get the data in a table form.
My JSON file is like this:
{
"document":{
"page":
},
{
"column":
}
]
},
{
... (6 Replies)
I am trying to automate editing of a json file using bash script.
The file I initially receive is
{
"appMap": {
"URL1": {
"name": "a"
},
"URL2": {
"name": "b"
},
"URL3": {
"name": "c"
},
}
WHat I would like to do is replace... (5 Replies)
Dear Shell script Experts,
I am working on shell script which is defined here, qsub_seq.csh . The purpose of this script is to read few input files (with defined starting index and last index) and make processing faster over server.
For some task, I had 1064 of input files, so I wrote another... (8 Replies)
All,
Have a weird issue where i need to generate a report from GitHub monthly detailing user accounts and the last time they logged in. I'm using a windows box to do this (work issued) and would like to know if anyone has any experience scripting for GitAPI using windows / cygwin / powershell?... (9 Replies)
HI
I have file A.txt
_1A
_2A
_3A
_4A
I want define all as different variable.
$1A=_1A
$2B=_2A
$3C=_3A
$4D=_4A
Now i can use any variable in my script. (3 Replies)
Hi, Unix Gurus,
In our existing file, there is a script like
#!/bin/sh
step=${1:-0}
cur_step=10
if
...
My question is what's "${1:-0}" mean? I know it defines a variable but I don't know what's (1:-0) mean?
:wall:
Thanks in advance. (2 Replies)
Hello,
I would like to define a variable based on another variable:
a=5
b$a=100
This does not work. What is the right way to do it?
Thanks
---------- Post updated at 07:37 PM ---------- Previous update was at 07:33 PM ----------
Found my answer with the search function (did not... (0 Replies)
Hi all,
I have a variable say var1 (output from somewhere, which I can't change)which store something like this:
echo $var1
name=fred
age=25
address="123 abc"
password=pass1234
how can I make the variable $name, $age, $address and $password contain the info?
I mean do this in a... (1 Reply)