Sponsored Content
Top Forums Shell Programming and Scripting Building JSON command with bash script Post 303039151 by stomp on Tuesday 24th of September 2019 11:56:02 AM
Old 09-24-2019
A short comment on debugging:

To check if a function does what it should do, the easiest method is to simply put the function in a small extra program, call it with some valid test data and just print the result to terminal and check if it matches the expectations, or generally speaking, check if the function succesfully executed the expected actions causing the expected results.
This User Gave Thanks to stomp For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Building command line parameters of arbitrary length

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)
Discussion started by: cmcnorgan
2 Replies

2. Shell Programming and Scripting

BASH SCRIPT of LS command

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)
Discussion started by: above8k
3 Replies

3. Shell Programming and Scripting

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.Download/versions/versions.json Within that JSON, I 'm looking for... (4 Replies)
Discussion started by: nbsparks
4 Replies

4. Shell Programming and Scripting

Bash script - cygwin (powershell?) pull from GitHub API Parse JSON

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)
Discussion started by: ChocoTaco
9 Replies

5. Shell Programming and Scripting

UNIX or Perl script to convert JSON to CSV

Is there a Unix or Perl script that converts JSON files to CSV or tab delimited format? We are running AIX 6.1. Thanks in advance! (1 Reply)
Discussion started by: warpmail
1 Replies

6. Shell Programming and Scripting

Parsing and Editing a json file with bash script

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)
Discussion started by: Junaid Subhani
5 Replies

7. UNIX for Beginners Questions & Answers

Json field grap via shell script/awk

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)
Discussion started by: SkySmart
9 Replies

8. Shell Programming and Scripting

JSON structure to table form in awk, bash

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)
Discussion started by: Gescad
6 Replies

9. Shell Programming and Scripting

Fun with terminal plotting JSON data at the command line

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)
Discussion started by: kbrazil
1 Replies

10. UNIX for Beginners Questions & Answers

How to convert any shell command output to JSON format?

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)
Discussion started by: balu1234
13 Replies
Test::Builder::Tester(3pm)				 Perl Programmers Reference Guide				Test::Builder::Tester(3pm)

NAME
Test::Builder::Tester - test testsuites that have been built with Test::Builder SYNOPSIS
use Test::Builder::Tester tests => 1; use Test::More; test_out("not ok 1 - foo"); test_fail(+1); fail("foo"); test_test("fail works"); DESCRIPTION
A module that helps you test testing modules that are built with Test::Builder. The testing system is designed to be used by performing a three step process for each test you wish to test. This process starts with using "test_out" and "test_err" in advance to declare what the testsuite you are testing will output with Test::Builder to stdout and stderr. You then can run the test(s) from your test suite that call Test::Builder. At this point the output of Test::Builder is safely captured by Test::Builder::Tester rather than being interpreted as real test output. The final stage is to call "test_test" that will simply compare what you predeclared to what Test::Builder actually outputted, and report the results back with a "ok" or "not ok" (with debugging) to the normal output. Functions These are the six methods that are exported as default. test_out test_err Procedures for predeclaring the output that your test suite is expected to produce until "test_test" is called. These procedures automatically assume that each line terminates with " ". So test_out("ok 1","ok 2"); is the same as test_out("ok 1 ok 2"); which is even the same as test_out("ok 1"); test_out("ok 2"); Once "test_out" or "test_err" (or "test_fail" or "test_diag") have been called, all further output from Test::Builder will be captured by Test::Builder::Tester. This means that you will not be able perform further tests to the normal output in the normal way until you call "test_test" (well, unless you manually meddle with the output filehandles) test_fail Because the standard failure message that Test::Builder produces whenever a test fails will be a common occurrence in your test error output, and because it has changed between Test::Builder versions, rather than forcing you to call "test_err" with the string all the time like so test_err("# Failed test ($0 at line ".line_num(+1).")"); "test_fail" exists as a convenience function that can be called instead. It takes one argument, the offset from the current line that the line that causes the fail is on. test_fail(+1); This means that the example in the synopsis could be rewritten more simply as: test_out("not ok 1 - foo"); test_fail(+1); fail("foo"); test_test("fail works"); test_diag As most of the remaining expected output to the error stream will be created by Test::Builder's "diag" function, Test::Builder::Tester provides a convenience function "test_diag" that you can use instead of "test_err". The "test_diag" function prepends comment hashes and spacing to the start and newlines to the end of the expected output passed to it and adds it to the list of expected error output. So, instead of writing test_err("# Couldn't open file"); you can write test_diag("Couldn't open file"); Remember that Test::Builder's diag function will not add newlines to the end of output and test_diag will. So to check Test::Builder->new->diag("foo ","bar "); You would do test_diag("foo","bar") without the newlines. test_test Actually performs the output check testing the tests, comparing the data (with "eq") that we have captured from Test::Builder against that that was declared with "test_out" and "test_err". This takes name/value pairs that effect how the test is run. title (synonym 'name', 'label') The name of the test that will be displayed after the "ok" or "not ok". skip_out Setting this to a true value will cause the test to ignore if the output sent by the test to the output stream does not match that declared with "test_out". skip_err Setting this to a true value will cause the test to ignore if the output sent by the test to the error stream does not match that declared with "test_err". As a convenience, if only one argument is passed then this argument is assumed to be the name of the test (as in the above examples.) Once "test_test" has been run test output will be redirected back to the original filehandles that Test::Builder was connected to (probably STDOUT and STDERR,) meaning any further tests you run will function normally and cause success/errors for Test::Harness. line_num A utility function that returns the line number that the function was called on. You can pass it an offset which will be added to the result. This is very useful for working out the correct text of diagnostic functions that contain line numbers. Essentially this is the same as the "__LINE__" macro, but the "line_num(+3)" idiom is arguably nicer. In addition to the six exported functions there exists one function that can only be accessed with a fully qualified function call. color When "test_test" is called and the output that your tests generate does not match that which you declared, "test_test" will print out debug information showing the two conflicting versions. As this output itself is debug information it can be confusing which part of the output is from "test_test" and which was the original output from your original tests. Also, it may be hard to spot things like extraneous whitespace at the end of lines that may cause your test to fail even though the output looks similar. To assist you "test_test" can colour the background of the debug information to disambiguate the different types of output. The debug output will have its background coloured green and red. The green part represents the text which is the same between the executed and actual output, the red shows which part differs. The "color" function determines if colouring should occur or not. Passing it a true or false value will enable or disable colouring respectively, and the function called with no argument will return the current setting. To enable colouring from the command line, you can use the Text::Builder::Tester::Color module like so: perl -Mlib=Text::Builder::Tester::Color test.t Or by including the Test::Builder::Tester::Color module directly in the PERL5LIB. BUGS
Calls "<Test::Builder-"no_ending>> turning off the ending tests. This is needed as otherwise it will trip out because we've run more tests than we strictly should have and it'll register any failures we had that we were testing for as real failures. The color function doesn't work unless Term::ANSIColor is compatible with your terminal. Bugs (and requests for new features) can be reported to the author though the CPAN RT system: <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Builder-Tester> AUTHOR
Copyright Mark Fowler <mark@twoshortplanks.com> 2002, 2004. Some code taken from Test::More and Test::Catch, written by by Michael G Schwern <schwern@pobox.com>. Hence, those parts Copyright Micheal G Schwern 2001. Used and distributed with permission. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. NOTES
Thanks to Richard Clamp <richardc@unixbeard.net> for letting me use his testing system to try this module out on. SEE ALSO
Test::Builder, Test::Builder::Tester::Color, Test::More. perl v5.18.2 2014-01-06 Test::Builder::Tester(3pm)
All times are GMT -4. The time now is 08:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy