MediaWiki API result

This is the HTML representation of the JSON format. HTML is good for debugging, but is unsuitable for application use.

Specify the format parameter to change the output format. To see the non-HTML representation of the JSON format, set format=json.

See the complete documentation, or the API help for more information.

{
    "batchcomplete": "",
    "continue": {
        "gapcontinue": "Solution_0_1_2",
        "continue": "gapcontinue||"
    },
    "warnings": {
        "main": {
            "*": "Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes."
        },
        "revisions": {
            "*": "Because \"rvslots\" was not specified, a legacy format has been used for the output. This format is deprecated, and in the future the new format will always be used."
        }
    },
    "query": {
        "pages": {
            "18": {
                "pageid": 18,
                "ns": 0,
                "title": "Scripting",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "\n\n* Prev: [[Warming up with Unix commands]]\n* Next: [[LabQSM#Link to Selected Laboratories]]\n\n\n[[File:Bash.png|left| 180px]]\n\nCommands (to be interpreted and executed) can be placed in a text file, called script, to be executed by means of an interpreter\n\nThe interpreter is specified in the first line of the script, e.g. by:\n  #! /bin/sh\n  #! /bin/bash\n  #! /bin/tcsh\n  #! /usr/bin/awk -f\n  #! /usr/bin/env python\n  ...\n(Note that while # is in all the above languages a comment, #! is actually used to identify the interpreter).\n\n== Bash scripting ==\n\nAmong the many, '''bash scripting''' is particularly relevant to us (bash is also the interpreter of the command-line shell\nwe have been using so far).\n\nUnix commands (enriched by bash built-in functions & structures) can be used in bash scripts:\n\n $> vi ./get_users.sh\n \n #! /bin/bash  -x\n filein=/etc/passwd\n #\n # extract user names\n cat $filein | awk -v FS=\":\" '{print $1}'\n\nNote that in order to execute <code>get_users.sh</code>, we need to change its permissions,\n  $> chmod a+x ./get_users.sh\nWhen executing, the output fo the script can also be redirected to a file, \n  $> ./get_users.sh > users.dat\n\nWithin the script, $0 corresponds to the invocation name (./get_users.sh, in the example above), $1, $2, .. $n\nto the n-th arguments if present. $# is the number of command line arguments passed to the script.\n\n $> cat ./get_users2.sh\n \n #! /bin/bash\n if [ $# == 0 ] ; then echo \"Usage:  ./get_users2.sh  <filename>\" ; exit 1 ; fi\n filein=$1\n # \n # extract user names\n cat $filein | awk -v FS=\":\" '{print $1}'\n\nNow, this second version of the script needs to be run as:\n $> ./get_users2.sh /etc/passwd\n\n== Sed & Awk ==\n\nThese two commands, available almost everywhere, are extremely used in bash scripting.\n\n=== sed ===  \nsubstitutes regular expressions in files or strings. Examples follow:\n\n $> echo \u201cCiao Ciao\u201d | sed \u2018s/C/M/\u2019\n      ->  \u201cMiao Ciao\u201d\n $> echo \u201cCiao Ciao\u201d | sed \u2018s/C/M/g\u2019\n      ->  \u201cMiao Miao\u201d                  # g stands for \u201cglobal substitution\u201d\n\nRegular expressions can also be used in the search. \n\n* \".\"  in the regular expr means all characters (wild card) and needs to be protected as \\. to be treated as a regular character\n* \\n   means newline\n* \\t   tab\n\n\n=== awk ===\nline by line operations (number & strings, syntax similar to c)\n $> echo 10 4.0 | awk '{print $1 * sqrt($2)}'\n $> echo \u201cLabQSM 2020\u201d | awk '{print $1; print \"Year\", $2}'\n\nAwk has its own scripting, useful eg for parsing or data post-processing (the same operation/search is done line by line)\n\nActions are automatically performed line by line.\n* NR      current line number\n* NF      current number of fields, separated by FS \n* FS      field separator, space by default, can be changed e.g. to , or :, or tab\n* $1, $2, ... $NF   refer to different fields in the parsed line\n* Arithmetic, string (and many more) operations.\n* next    skips to the next line\n\nTake eg the file <code>apt.txt</code> with the list of tennis players that we have used in previous examples:\n  9850, Nadal,  Rafael \n  6630, Federer,  Roger\n  3075, Berrettini,  Matteo \n 12030, Djokovic,  Novak\n\nThe problem can be solved by awk as follows:\n\n #! /usr/bin/awk -f\n BEGIN{ i=ind; nlines=0; FS=\",\" }\n {\n   if (NF != 3) next\n   nlines++\n   if (nlines == i) {printf \"%s, %s\\n\", $3,$2}\n }\n END{\n # place here any operation to be done at the end\n }\n\nRun as:\n $> ./solution.awk -v ind=2  apt.txt\n\nNote that comma-separated columns are no longer needed, and one can avoid using commas by simply dropping the redefinition of the field-separator FS=\",\".\n\n== Bash control statements ==\n\n'''Conditionals'''\n\n if [ \"$var1\" = \"$var2\" ] ; then\n    <some-statements>\n else\n    <some-statements>\n fi\n \n if [ -n \"$var\" ] ; then echo \"var is non-empty\" ; fi \n if [ -z \"$var\" ] ; then echo \"var is empty\" ; fi\n if [ -e \"$file\" ] ; then echo \"File exists\" ; fi\n if [ ! -e \"$file\" ] ; then echo \"File does not exist\" ; fi\n if [ -d \"$dir\" ] ;  then echo \"Dir exists\" ; fi\n if [ -x \"$file\" ] ; then echo \"File exists and is exec\" ; fi\n\n'''Loops'''\n list=\"item1 item2 item3\"\n for item in $list\n do\n    echo $item\n done\n\n'''Input from command line'''\n\n #! /bin/bash\n echo \"number of arguments : $#\"\n echo \"        \tcommand : $0\"\n echo \"        \t1st arg : $1\"\n echo \"        \t2nd arg : $2\"\n echo \"            \t... \"\n echo \"       \tall args : $*\"\n\n Execute as:\n $> ./example.sh  p1 p2 p3\n\n'''Dealing with extended text'''\n(Useful eg to write input files)\n\nThis can be used for a few lines\n echo line1 >  file.txt \n echo line2 >> file.txt\n echo line3 >> file.txt\n\nInstead, when text becomes extended\n cat >file.txt << EOF\n    line1\n    line2\n    line3\n EOF\n\n== Exercises ==\n\n=== Exercise 1 ===\nJob Script: Write a script (run.sh) to run <code>pw.x</code> once an input file is provided\n\n[[Solution_1_1 | Solution 1]]\n\n[[Solution_1_2 | Solution 2]]\n\n\n=== Exercise 2 ===\n\n* Modify the ruh.sh script of Problem 1 to loop over different lattice parameters.\n* Consider the grid:  -3%, -2%, -1%, 0, +1%, +2%, + 3%\n* Keep trace of the parameters used in the file names\n\n* '''Hint1''': create a template input file, where the <code>celldm1</code> field is assigned <code>@alat@</code>, which you will substitute in the script\n* '''Hint2''': save both input and output files;    \n* '''Hint3''':   <code>$ basename <name>.dat  .dat   ->  <name></code>\n\n'''Solution''': have a look at   \n* [https://github.com/max-centre/LabQSM/blob/main/LAB_1/test_diamond/run_lattice.sh LAB_1/test_diamond/run_lattice.sh]    and\n* [https://github.com/max-centre/LabQSM/blob/main/LAB_1/test_diamond/scf.tmpl LAB_1/test_diamond/scf.tmpl]\n\n\n\n=== Exercise 3 ===\n\nLattice parameter revised\n* Same at Exercise 2\n* Include the input file in the script, meaning that the substitution of parameters in the template input file can be done via shell variables and loops\n\n'''Solution''': have a look at \n* [https://github.com/max-centre/LabQSM/blob/main/LAB_1/test_diamond/run_lattice_with_input.sh LAB_1/test_diamond/run_lattice_with_input.sh]"
                    }
                ]
            },
            "22": {
                "pageid": 22,
                "ns": 0,
                "title": "Solution 0 1 1",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "* Back to the previous page: [[Scripting#Exercises|Exercises]]\n\n #! /bin/bash -x\n filein=scf.diamond.in\n bindir=/usr/local/bin\n #\n # fileout=scf.diamond.out\n fileout=`echo $filein | sed 's/\\.in/\\.out/' `\n #\n $bindir/pw.x < $filein > $fileout\n exit 0"
                    }
                ]
            }
        }
    }
}