maybe you can spare the escaping of " if you mix ' (single quotes) and " (double quotes).
simple shell scripting will suffice for what you want to achieve, jq seems not necessary(but hey! Read the docs maybe it's way simpler! I'm not an jq expert, I just use it occasionally)
if you want to know if jq accepts the input, in other words to validate json, just pipe your data into jq . like echo "$data" | jq .. jq will complain if the data is not well formed.
But I cannot do it this way because this "com_params" variable that I set to store the command parameters is seen as a single long string, and if I do it this way, the app that parses the command to JSON complains.
How do you say this can be done with a simple bash script without using 'jq' ? Please give me a hint because I'm not getting there. I'm around this for like 2 or 3 weeks and I can't find a way to make the command to be accepted by the daemon that parses the command!
Note:
This is the code I actually have:
(I can't post links yet)
Search for my nick in Github anf for "TugaRevoBTC" repository if you want to see the code!
Check my github repository named TugaRevoBTC for the entire code.
I just hope bitcoin-cli accepts the command the way I did it here! I haven't tested it yet. Bed time for now!
Any suggestions/corrections are greatly appreciated.
Thanks
Psy
Edited;
I just noticed something I can improve, at least visually. I can just add the leading ' " ' and the trailing ' " ' statically in that printf instead of passing each one as parameters.
These 2 Users Gave Thanks to psysc0rpi0n For This Post:
@psysc0rpi0n Great! You did it! Your code is good.
One of my goal in programming is trying to create code which is readable well. So I encapsule code into functions, even at the cost (in bash) to make code less resource efficient. Here the function for the creation of a json object:
This function operates on the given parameters($1, $2, ...):
use it like this:
Since it is bash it's a bit of a quoting and eval mess here.
Since you have a special object where all values are equal, I create another function, so the main call stays simple:
use it like this:
mydata will contain: { "key1": "value","key2": "value","key3": "value" }
The quoting is different from yours, but escaping the " with \ is not necessary, if you use the mydata variable in quotes this way "$mydata", since the content of mydata will not be parsed by the shell again.
Note: The function can not cope with values containing whitespace characters.
@psysc0rpi0n Great! You did it! Your code is good.
One of my goal in programming is trying to create code which is readable well. So I encapsule code into functions, even at the cost (in bash) to make code less resource efficient. Here the function for the creation of a json object:
This function operates on the given parameters($1, $2, ...):
use it like this:
Since it is bash it's a bit of a quoting and eval mess here.
Since you have a special object where all values are equal, I create another function, so the main call stays simple:
use it like this:
mydata will contain: { "key1": "value","key2": "value","key3": "value" }
The quoting is different from yours, but escaping the " with \ is not necessary, if you use the mydata variable in quotes this way "$mydata", since the content of mydata will not be parsed by the shell again.
Note: The function can not cope with values containing whitespace characters.
Hello.
I'm trying to apply the code to my specific case, and I think I have the same problem.
How can I add as many item pairs as lines that are loaded from the file?
The examples you posted are like static, right? You need to write each item pairs by hand as needed, right?
I tried my version of the code, but somehow I think there might be escaping issues because bitcoin-cli is still finding "json parsing errors" or "wrong amount" (wrong value in item pair), wrong number of arguments, etc.
I tried to change "", add escaping chars, replacing "" by ' ' but I just can't make it work. I need to make sure that each of the 8 parameters are seen as strings. Param1 one string, param 2 another string, param3 another string and so on! I would like to try to make my version to work and then I could try your version and adapt it to load and create as many item pairs as needed, dynamically!
Thanks
Psy
Edited;
I know you already told me I can avoi escaping double quotes. But as I'm still trying to memorize the special chars that must be escaped and the ones that need no escaping, the way to save command outputs, the way to run commands in a nested way, etc, it's still too many details to just keep in mind at the same time and in a short period of time, I'll be escaping them because as of now that's the way I'm more comfortable with it.
--- Post updated at 11:00 PM ---
I tried something else and things gets even more weird.
Send multiple times. Amounts are double-precision floating point numbers.
Arguments:
1. dummy (string, required) Must be set to "" for backwards compatibility.
2. amounts (json object, required) A json object with addresses and amounts
{
"address": amount, (numeric or string, required) The bitcoin address is the key, the numeric amount (can be string) in BTC is the value
}
3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.
4. comment (string, optional) A comment
5. subtractfeefrom (json array, optional) A json array with addresses.
The fee will be equally deducted from the amount of each selected address.
Those recipients will receive less bitcoins than you enter in their corresponding amount field.
If no addresses are specified here, the sender pays the fee.
[
"address", (string) Subtract fee from this address
...
]
6. replaceable (boolean, optional, default=fallback to wallet's default) Allow this transaction to be replaced by a transaction with higher fees via BIP 125
7. conf_target (numeric, optional, default=fallback to wallet's default) Confirmation target (in blocks)
8. estimate_mode (string, optional, default=UNSET) The fee estimate mode, must be one of:
"UNSET"
"ECONOMICAL"
"CONSERVATIVE"
Result:
"txid" (string) The transaction id for the send. Only 1 transaction is created regardless of
the number of addresses.
and knowing that the bitcoin-cli command syntax is (from bitcoin core docs):
Quote:
Examples:
Send two amounts to two different addresses:
> bitcoin-cli sendmany "" "{\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\":0.01,\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\":0.02}"
Send two amounts to two different addresses setting the confirmation and comment:
> bitcoin-cli sendmany "" "{\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\":0.01,\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\":0.02}" 6 "testing"
Send two amounts to two different addresses, subtract fee from amount:
> bitcoin-cli sendmany "" "{\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\":0.01,\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\":0.02}" 1 "" "[\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\",\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\"]"
I decided to try to set all 8 parameters by hand directly on terminal.
After playing a while with incluing/excluding '' and "" and \ I get to a point where the only way 'jq' validates the objects and non-ordered lists is as follows:
Then I used 'jq' to validate the object and list:
This looks perfect, however, when I try to issue the command with all these parameters:
Looks like the command is broken on variable $comment.
But to be honest, and as I said I'm still grasping about the escapings, expansions and etc, so I either try all possible combinations of escaping and expansions to see when it works or you guys help me figuring this out!
Just use the function with the same var as in your code:
That doesn't work. Single quotes do not execute variable substitution. You need double quotes for that.
(Did not read your full post)
You mean to add double quotes when I run the command? Because I have already added double quotes when I assigned the variable due to the existence of 2 separate words.
Won't "$comment" expand to ""Periodic payments""? Or should I remove the double quotes at the assignment of the comment variable?
Last edited by psysc0rpi0n; 09-20-2019 at 06:08 AM..
Hi All,
I am new to shell scripting, Need your help in creating a shell script which converts any unix command output to JSON format output.
example:
sample df -h command ouput :
Filesystem size used avail capacity Mounted
/dev/dsk/c1t0d0s0 8.1G 4.0G 4.0G 50% /... (13 Replies)
One of the great thing about unix is the ability to pipe multiple programs together to manipulate data. Plain, unstructured text is the most common type of data that is passed between programs, but these days JSON is becoming more popular.
I thought it would be fun to pipe together some command... (1 Reply)
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 have a json data that looks like this:
{
"ip": "16.66.35.10",
"hostname": "No Hostname",
"city": "Stepney",
"region": "England",
"country": "GB",
"loc": "51.57,-0.0333",
"org": "AS6871 British Telecommunications PLC",
"postal": "E1"
}
im looking for a way to assign... (9 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)
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)
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.Download/versions/versions.json
Within that JSON, I 'm looking for... (4 Replies)
I need help in writing a BASH SCRIPT of ls command.
for example:
$ ./do_ls.sh files
f1.txt
f2.jpeg
f3.doc
$ ./do_ls.sh dirs
folder1
folder2
folder3
My attempt:
#!/bin/bash
#
if test $# -d file
then
echo $dirs
else (3 Replies)
I couldn't find an existing thread that addressed this question, so hopefully this isn't redundant with anything previously posted. Here goes:
I am writing a C-Shell script that runs a program that takes an arbitrary number of parameters:
myprog -a file1 \
-b file2 \
-c file3 ... \
-n... (2 Replies)