Difference between pages "Awk by Example, Part 1" and "Help:Funtoo Editing Guidelines"

From Funtoo
(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
{{Article
'''Thanks for your interest in contributing to the the Funtoo wiki!'''
|Author=Drobbins
__NOTOC__
|Next in Series=Awk by Example, Part 2
=== Types of Edits ===
}}
 
Before we get started, let's review what changes are okay to make, and what changes are not okay:
 
{{TableStart}}
<tr class="active"><th>Type of Change</th><th>Okay?</th></tr>
<tr><td>Grammar/spelling fixes</td><td>Yes</td></tr>
<tr><td>New wiki content</td><td>Yes</td></tr>
<tr><td>New package information</td><td>Yes</td></tr>
<tr><td>Adding to existing article</td><td>Maybe -- see below</td></tr>
<tr><td>Adding missing/incomplete information</td><td>Yes</td></tr>
<tr><td>Making corrections</td><td>Yes</td></tr>
<tr class="danger"><td>Adding work-arounds to problems experienced</td><td>No - open bug first on [http://bugs.funtoo.org bug tracker].</td></tr>
{{TableEnd}}
 
{{important|Note that if you experience some problem with Funtoo Linux, during installation or otherwise, the proper course of action is to not add a work-around to our documentation, but to ''open a bug on our bug tracker.'' This is important because the problem you experienced may be a legitimate bug and the solution may be to fix the bug rather than add a work-around to our documentation. We may end up fixing a bug, making a documentation fix, or possibly both.}}
 
=== Basics ===
 
Here is a list of basic wiki information that you will need to know to get started:


== An intro to the great language with the strange name ==
* First, to perform edits on the wiki, you must {{CreateAccount}} and log in.
* You can create a new page by navigating to http://www.funtoo.org/New_Page_Name. Underscores are the equivalent of spaces. Then select "Create" under the "Actions" menu.
* Whether creating a new page or editing an existing page by clicking "Edit", you will be presented with Web-based text editor that allows you to modify the ''wikitext'' of the page. The wikitext is rendered to produce the document you see when you view the page normally.
* Another fun thing you can do is click on your name under the "Account" menu once you have logged in. This will bring you to your "User" page. Then click "Create with Form" unde the "Actions" menu and enter your geographic and other information. This will allow you to be displayed on our [[Usermap]] and will also allow your full name to be displayed on [[:Category:Ebuilds|Ebuild pages]] for which you are an author. It's generally a good idea to do this.


=== In defense of awk ===
{{tip|The following sections document how to use wikitext and Funtoo templates on the Funtoo wiki.}}
In this series of articles, I'm going to turn you into a proficient awk coder. I'll admit, awk doesn't have a very pretty or particularly "hip" name, and the GNU version of awk, called gawk, sounds downright weird. Those unfamiliar with the language may hear "awk" and think of a mess of code so backwards and antiquated that it's capable of driving even the most knowledgeable UNIX guru to the brink of insanity (causing him to repeatedly yelp "kill -9!" as he runs for coffee machine).


Sure, awk doesn't have a great name. But it is a great language. Awk is geared toward text processing and report generation, yet features many well-designed features that allow for serious programming. And, unlike some languages, awk's syntax is familiar, and borrows some of the best parts of languages like C, python, and bash (although, technically, awk was created before both python and bash). Awk is one of those languages that, once learned, will become a key part of your strategic coding arsenal.
=== Paragraphs ===


=== The first awk ===
To create a new paragraph, insert a blank line between two lines of text. If a blank line doesn't exist between two lines of wikitext, they will be combined into a single flowing paragraph.
Let's go ahead and start playing around with awk to see how it works. At the command line, enter the following command:


<console>$##i## awk '{ print }' /etc/passwd</console>
If you leave leading whitespace at the beginning of a line, MediaWiki will render it as pre-formatted text. Beware of this. Here's an example:


You should see the contents of your /etc/passwd file appear before your eyes. Now, for an explanation of what awk did. When we called awk, we specified /etc/passwd as our input file. When we executed awk, it evaluated the print command for each line in /etc/passwd, in order. All output is sent to stdout, and we get a result identical to catting /etc/passwd.
foobar


Now, for an explanation of the { print } code block. In awk, curly braces are used to group blocks of code together, similar to C. Inside our block of code, we have a single print command. In awk, when a print command appears by itself, the full contents of the current line are printed.
This can rear its ugly head when specifying template parameters, so you will get this:


Here is another awk example that does exactly the same thing:
{{note| ugh!}}


<console>$##i## awk '{ print $0 }' /etc/passwd</console>
...instead of this:


In awk, the $0 variable represents the entire current line, so print and print $0 do exactly the same thing. If you'd like, you can create an awk program that will output data totally unrelated to the input data. Here's an example:
{{note|This looks much better!}}


<console>$##i## awk '{ print "" }' /etc/passwd</console>
=== Page and Section Capitalization ===


Whenever you pass the "" string to the print command, it prints a blank line. If you test this script, you'll find that awk outputs one blank line for every line in your /etc/passwd file. Again, this is because awk executes your script for every line in the input file. Here's another example:
In general, capitalize all words in page names and section heading except:
* Articles: a, an, the
* Coordinating Conjunctions: and, but, or, for, nor, etc.
* Prepositions (fewer than five letters): on, at, to, from, by, etc.


<console>$##i## awk '{ print "hiya" }' /etc/passwd</console>
=== Document Hierarchy ===


Running this script will fill your screen with hiya's. :)
Use section headings to create a document hierarchy for your page. These will define the table of contents that appears at the top of the wiki page. Create chapters, sections and sub-sections as follows:


=== Multiple fields ===
<pre>= Page Title =
Awk is really good at handling text that has been broken into multiple logical fields, and allows you to effortlessly reference each individual field from inside your awk script. The following script will print out a list of all user accounts on your system:


<console>$##i## awk -F":" '{ print $1 }' /etc/passwd</console>
== Chapter Title ==


Above, when we called awk, we use the -F option to specify ":" as the field separator. When awk processes the print $1 command, it will print out the first field that appears on each line in the input file. Here's another example:
=== Section Title ===


<console>$##i## awk -F":" '{ print $1 $3 }' /etc/passwd</console>
==== SubSection Title ====


Here's an excerpt of the output from this script:
<pre>
halt7
operator11
root0
shutdown6
sync5
bin1
....etc.
</pre>
</pre>
As you can see, awk prints out the first and third fields of the /etc/passwd file, which happen to be the username and uid fields respectively. Now, while the script did work, it's not perfect -- there aren't any spaces between the two output fields! If you're used to programming in bash or python, you may have expected the print $1 $3 command to insert a space between the two fields. However, when two strings appear next to each other in an awk program, awk concatenates them without adding an intermediate space. The following command will insert a space between both fields:


<console>$##i## awk -F":" '{ print $1 " " $3 }' /etc/passwd</console>
{{Note|By default, Table of Contents is disabled on the Funtoo wiki. If you would like to enable the TOC, you can place a <code><nowiki>__TOC__</nowiki></code> on a blank line where you'd like the Table of Contents to appear, or place <code><nowiki>__FORCETOC__</nowiki></code> on a blank line anywhere in the wikitext to force the TOC to appear at the top of the page.}}
 
In general, when creating new documents, it's best to use level-3 (three "="'s) Section Titles to break up content. Level-2 Section Titles are best used for major sections of larger documents. Use them infrequently. Level-1 Section Titles generally do not need to be used.
 
=== Links ===
 
Internal links to other wiki pages can be specified as <tt><nowiki>[[pagename]]</nowiki></tt>. To specify an alternate name for the link, use <tt><nowiki>[[pagename|my link name]]</nowiki></tt>.
 
For external links, use <tt><nowiki>[http://funtoo.org my link]</nowiki></tt> to specify a URL. If you want the URL to appear in the wikitext, you can specify it without brackets: http://forums.funtoo.org.
 
=== Lists ===
 
MediaWiki supports a number of list formats:


When you call print this way, it'll concatenate $1, " ", and $3, creating readable output. Of course, we can also insert some text labels if needed:
* Unordered List
* Unordered Item 2
** Unordered sub-item


<console>$##i## awk -F":" '{ print "username: " $1 "\t\tuid:" $3 }' /etc/passwd</console>
# Ordered List
# Ordered Item 2
## Ordered sub-item


This will cause the output to be:
;Term: This is called a "definition list". It is used when defining various terms.
<pre>
 
username: halt    uid:7
If you need to quote a portion of text from another site, use <tt><nowiki><blockquote></nowiki></tt> as follows:
username: operator uid:11
username: root    uid:0
username: shutdown uid:6
username: sync    uid:5
username: bin      uid:1
....etc.
</pre>


=== External Scripts ===
<blockquote>
Passing your scripts to awk as a command line argument can be very handy for small one-liners, but when it comes to complex, multi-line programs, you'll definitely want to compose your script in an external file. Awk can then be told to source this script file by passing it the -f option:
Wikipedia (ˌwɪkɨˈpiːdiə/ or wɪkiˈpiːdiə/ wik-i-pee-dee-ə) is a collaboratively edited, multilingual, free-access, free content Internet encyclopedia that is supported and hosted by the non-profit Wikimedia Foundation. Volunteers worldwide collaboratively write Wikipedia's 30 million articles in 287 languages, including over 4.5 million in the English Wikipedia. Anyone who can access the site can edit almost any of its articles, which on the Internet comprise[4] the largest and most popular general reference work.[5][6][7][8][9] In February 2014, The New York Times reported that Wikipedia is ranked fifth globally among all websites stating, "With 18 billion page views and nearly 500 million unique visitors a month..., Wikipedia trails just Yahoo, Facebook, Microsoft and Google, the largest with 1.2 billion unique visitors."[10]
</blockquote>


<console>$##i## awk -f myscript.awk myfile.in </console>
=== Literal Text and HTML Symbols ===


Putting your scripts in their own text files also allows you to take advantage of additional awk features. For example, this multi-line script does the same thing as one of our earlier one-liners, printing out the first field of each line in /etc/passwd:
Here is wikitext for the section above, which I am displaying by placing the literal wikitext between a &#60;pre&#62; and &#60;/pre&#62; tag. If you want to disable wikitext processing for an inline span of text, use &#60;nowiki&#62; and &#60;/nowiki&#62;. If you want to print out a tag literally, use &amp;#60; and &amp;#62; (In the wikitext, I used &amp;amp;#60; and &amp;amp;#62 to display these!)
<pre>
BEGIN {
        FS=":"
}
{ print $1 }
</pre>
The difference between these two methods has to do with how we set the field separator. In this script, the field separator is specified within the code itself (by setting the FS variable), while our previous example set FS by passing the -F":" option to awk on the command line. It's generally best to set the field separator inside the script itself, simply because it means you have one less command line argument to remember to type. We'll cover the FS variable in more detail later in this article.


It is also possible to make the script directly executable, by placing a "#!/usr/bin/awk -f" at the top of the file, as follows:
<pre>
<pre>
#!/usr/bin/awk -f
* Unordered List
BEGIN {
* Unordered Item 2
FS=":"
** Unordered sub-item
}
{ print $1 }
</pre>
Next, the script must be made executable by setting the script file's execute bit:


<console>$##i## chmod +x myscript.awk</console>
# Ordered List
# Ordered Item 2
## Ordered sub-item


Now, you should be able to execute the script as follows:
;Term: This is called a "definition list". It is used when defining various terms.


<console>$##i## ./myscript.awk myfile.in</console>
If you need to quote a portion of text from another site, use <tt><nowiki><blockquote></nowiki></tt> as follows:


=== The BEGIN and END blocks ===
<blockquote>
Normally, awk executes each block of your script's code once for each input line. However, there are many programming situations where you may need to execute initialization code before awk begins processing the text from the input file. For such situations, awk allows you to define a BEGIN block. We used a BEGIN block in the previous example. Because the BEGIN block is evaluated before awk starts processing the input file, it's an excellent place to initialize the FS (field separator) variable, print a heading, or initialize other global variables that you'll reference later in the program.
Wikipedia (ˌwɪkɨˈpiːdiə/ or wɪkiˈpiːdiə/ wik-i-pee-dee-ə) is a collaboratively edited, multilingual, free-access,
free content Internet encyclopedia that is supported and hosted by the non-profit Wikimedia Foundation. Volunteers
worldwide collaboratively write Wikipedia's 30 million articles in 287 languages, including over 4.5 million in the
English Wikipedia. Anyone who can access the site can edit almost any of its articles, which on the Internet
comprise[4] the largest and most popular general reference work.[5][6][7][8][9] In February 2014, The New York
Times reported that Wikipedia is ranked fifth globally among all websites stating, "With 18 billion page views
and nearly 500 million unique visitors a month..., Wikipedia trails just Yahoo, Facebook, Microsoft and Google,  
the largest with 1.2 billion unique visitors."[10]
</blockquote>
</pre>


Awk also provides another special block, called the END block. Awk executes this block after all lines in the input file have been processed. Typically, the END block is used to perform final calculations or print summaries that should appear at the end of the output stream.
=== Linking to Packages ===


=== Regular expressions and blocks ===
To link to a package page, use the <code>Package</code> template:
Awk allows the use of regular expressions to selectively execute an individual block of code, depending on whether or not the regular expression matches the current line. Here's an example script that outputs only those lines that contain the character sequence foo:


<pre>/foo/ { print }</pre>
<pre><nowiki>
{{Package|sys-apps/portage}}
</nowiki></pre>


Of course, you can use more complicated regular expressions. Here's a script that will print only lines that contain a floating point number:
This template will create a link to the official wiki page for sys-apps/portage, and render using the official "English" page name, as follows:


<pre>/[0-9]+\.[0-9]*/ { print }</pre>
{{Package|sys-apps/portage}}


=== Expressions and blocks ===
If you specify a yet-to-be-documented ebuild, it will render like this (which is okay -- it will encourage people to document it):
There are many other ways to selectively execute a block of code. We can place any kind of boolean expression before a code block to control when a particular block is executed. Awk will execute a code block only if the preceding boolean expression evaluates to true. The following example script will output the third field of all lines that have a first field equal to fred. If the first field of the current line is not equal to fred, awk will continue processing the file and will not execute the print statement for the current line:


<pre>$1 == "fred" { print $3 }</pre>
{{Package|sys-foo/undocumented-ebuild}}


Awk offers a full selection of comparison operators, including the usual "==", "<", ">", "<=", ">=", and "!=". In addition, awk provides the "~" and "!~" operators, which mean "matches" and "does not match". They're used by specifying a variable on the left side of the operator, and a regular expression on the right side. Here's an example that will print only the third field on the line if the fifth field on the same line contains the character sequence root:
=== Tables ===


<pre>$5 ~ /root/ { print $3 }</pre>
Instead of using traditional MediaWiki table wikitext, use the following format:


=== Conditional statements ===
Awk also offers very nice C-like if statements. If you'd like, you could rewrite the previous script using an if statement:
<pre>
<pre>
{  
{{TableStart}}
    if ( $5 ~ /root/ ) {
<tr class="info"><th>Header 1</th><th>Header 2</th></tr>
        print $3  
<tr><td>Value 1</td><td>Value 2</td></tr>
    }
<tr><td>Value 3</td><td>Value 4</td></tr>
}
{{TableEnd}}
</pre>
</pre>
Both scripts function identically. In the first example, the boolean expression is placed outside the block, while in the second example, the block is executed for every input line, and we selectively perform the print command by using an if statement. Both methods are available, and you can choose the one that best meshes with the other parts of your script.


Here's a more complicated example of an awk if statement. As you can see, even with complex, nested conditionals, if statements look identical to their C counterparts:
This wil render as follows:
 
{{TableStart}}
<tr class="info"><th>Header 1</th><th>Header 2</th></tr>
<tr><td>Value 1</td><td>Value 2</td></tr>
<tr><td>Value 3</td><td>Value 4</td></tr>
{{TableEnd}}
 
{{tip|This table syntax has an added benefit of creating a responsive table that renders properly on mobile devices.}}
 
It is possible to use the following CSS classes with <code>tr</code> (rows) and <code>td/th</code> elements to color them as desired:
 
{{TableStart}}
<tr class="active"><td>Class Name</td></tr>
<tr class="success"><td>success</td></tr>
<tr class="info"><td>info</td></tr>
<tr class="warning"><td>warning</td></tr>
<tr class="active"><td>active</td></tr>
<tr class="danger"><td>danger</td></tr>
{{TableEnd}}
 
=== Displaying Source Code ===
 
To display source code, use can use the file template, specifying a <tt>lang=</tt> parameter:
 
<pre>
<pre>
{
{{file|name=foobar|lang=python|desc=foobarosity|body=
    if ( $1 == "foo" ) {
import system
        if ( $2 == "foo" ) {
}}
            print "uno"
        } else {
            print "one"
        }
    } else if ($1 == "bar" ) {
        print "two"
    } else {
        print "three"
    }
}
</pre>
</pre>
Using if statements, we can also transform this code:
 
This will produce:
 
{{file|name=foobar|lang=python|desc=foobarosity|body=
import system
}}
 
The parameters {{c|name}} (filename), {{c|lang}} (language for syntax highlighting) and {{c|desc}} (Description, appearing as a caption) are optional. For a list of supported languages, see [http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi#Supported_languages this list].
 
 
{{important|If you need to display the pipe ("{{!}}") character within the body of a file template, replace each "{{!}}" with <nowiki>{{!}}</nowiki> -- otherwise your file contents will not display properly. This is necessary because <nowiki>{{file}}</nowiki> is a template and the "{{!}}" character is used as a delimiter for arguments to the template.}}
 
=== Displaying Text File Contents ===
 
For displaying the contents of non-programming language text files (like config files), you have two options. You can enclose your lines within <tt>&#60;pre&#62;</tt> tags, or use the new [[Template:File|file template]]. The file template is used like so:
 
<pre>
<pre>
! /matchme/ { print $1 $3 $4 }
{{file|name=/etc/foo.conf|desc=My foo.conf file|body=
# /etc/host.conf:
# $Header: /var/cvsroot/gentoo/src/patchsets/glibc/extra/etc/host.conf,v 1.1 2006/09/29
}}
</pre>
</pre>
to this:
 
This will produce:
 
{{file|name=/etc/foo.conf|desc=My foo.conf file|body=
# /etc/host.conf:
# $Header: /var/cvsroot/gentoo/src/patchsets/glibc/extra/etc/host.conf,v 1.1 2006/09/29
}}
 
=== Console ===
To display console output, use the <tt>&#60;console&#62;</tt> tag:
 
For a root console:
<pre>
<pre>
{
<console>
    if ( $0 !~ /matchme/ ) {
###i## run a command as root
        print $1 $3 $4
</console>
    }
}
</pre>
</pre>
Both scripts will output only those lines that don't contain a matchme character sequence. Again, you can choose the method that works best for your code. They both do the same thing.
Produces:
<console>
###i## run a command as root
</console>


Awk also allows the use of boolean operators "||" (for "logical or") and "&&"(for "logical and") to allow the creation of more complex boolean expressions:
For a non-root console:
<pre>
<pre>
( $1 == "foo" ) && ( $2 == "bar" ) { print }
<console>
$ ##i##run a command as user
</console>
</pre>
</pre>
This example will print only those lines where field one equals foo and field two equals bar.
Produces:
<console>
$ ##i##run a command as user
</console>
 
{{important|1=
Note that we use a <tt>#</tt> prompt for <tt>root</tt> and a <tt>$</tt> prompt to denote a non-root user.}}
 
{{important|The <tt>##i##</tt> text tags the rest of the line as being ''user input'' ("i" is for "input"). It is then highlighted in a noticeable color so it stands out from text that is not typed in by the user.}}
 
If you need to end highlighting of user input prior to the end of a line, use <code>##!i##</code> to mark the end of the highlighted area.
 
The following special character sequences are also available:
* <code>##g##</code> - Green
* <code>##y##</code> - Yellow
* <code>##bl##</code> - Blue
* <code>##r##</code> - Red
* <code>##b##</code> - Bold
 
Please use the above coloring options sparingly. It is sometimes nice to use them to get wiki console output to match the colors that are displayed on a Linux console. Also note that for every color above, there is a matching <code>##!(colorcode)##</code> option to turn color off prior to end of line.
 
Here is an example of its use:<console>
# ##i##bluetoothctl
[##g##NEW##!g##] Controller 00:02:72:C9:62:65 antec [default]
##bl##[bluetooth]##!bl###power on
Changing power on succeeded
##bl##[bluetooth]##!bl### ##i##agent on
Agent registered
##bl##[bluetooth]##!bl### ##i##scan on
Discovery started
##bl##[bluetooth]##!bl### ##i##devices
Device 00:1F:20:3D:1E:75 Logitech K760
##bl##[bluetooth]##!bl### ##i##pair 00:1F:20:3D:1E:75
Attempting to pair with 00:1F:20:3D:1E:75
[##y##CHG##!y##] Device 00:1F:20:3D:1E:75 Connected: yes
##r##[agent]##!r## Passkey: 454358
##r##[agent]##!r## Passkey: ##i##4##!i##54358
##r##[agent]##!r## Passkey: ##i##45##!i##4358
##r##[agent]##!r## Passkey: ##i##454##!i##358
##r##[agent]##!r## Passkey: ##i##4543##!i##58
##r##[agent]##!r## Passkey: ##i##45435##!i##8
##r##[agent]##!r## Passkey: ##i##454358##!i##
[##y##CHG##!y##] Device 00:1F:20:3D:1E:75 Paired: yes
Pairing successful
[##y##CHG##!y##] Device 00:1F:20:3D:1E:75 Connected: no
##bl##[bluetooth]##!bl### ##i##connect 00:1F:20:3D:1E:75
Attempting to connect to 00:1F:20:3D:1E:75
[##y##CHG##!y##] Device 00:1F:20:3D:1E:75 Connected: yes
Connection successful
##bl##[bluetooth]##!bl### ##i##quit
[##r##DEL##!r##] Controller 00:02:72:C9:62:65 antec [default]
#
</console>
 
=== Informational Messages ===
Notes, warnings, tips, and important templates can be used for informational messages that need to be offset from the regular text flow:
 
<pre>{{note|this is a note}}</pre>
{{note|this is a note}}
 
<pre>{{important|this is important}}</pre>
{{important|this is important}}
 
<pre>{{warning|this is a warning}}</pre>
{{warning|this is a warning}}
 
<pre>{{tip|this is a tip}}</pre>
{{tip|this is a tip}}


=== Numeric variables! ===
Note that these templates used to be called <code>fancynote</code>, <code>fancytip</code>, etc. The "fancy" names have been deprecated but will still be supported for the forseeable future.
So far, we've either printed strings, the entire line, or specific fields. However, awk also allows us to perform both integer and floating point math. Using mathematical expressions, it's very easy to write a script that counts the number of blank lines in a file. Here's one that does just that:
 
=== Kernelop ===
To display kernel configuration options, we encourage you to use the <tt>kernelop</tt> template. To use the <tt>kernelop</tt> template, create an entry similar to the following example:  
<pre>
<pre>
BEGIN { x=0 }
{{kernelop|title=foo,bar|desc=
/^$/  { x=x+1 }
kernel options pasted from "make menuconfig"
END  { print "I found " x " blank lines. :)" }  
}}  
</pre>
</pre>
In the BEGIN block, we initialize our integer variable x to zero. Then, each time awk encounters a blank line, awk will execute the x=x+1 statement, incrementing x. After all the lines have been processed, the END block will execute, and awk will print out a final summary, specifying the number of blank lines it found.


=== Stringy variables ===
{{note|Kernelop is colored blue to slightly resemble the blueish background from <tt>make menuconfig</tt>.}}
One of the neat things about awk variables is that they are "simple and stringy." I consider awk variables "stringy" because all awk variables are stored internally as strings. At the same time, awk variables are "simple" because you can perform mathematical operations on a variable, and as long as it contains a valid numeric string, awk automatically takes care of the string-to-number conversion steps. To see what I mean, check out this example:
 
Adding this entry will give you the following output:
{{kernelop|title=foo,bar|desc=
kernel options
}}
 
Here's a more concrete example:
{{kernelop|title=File systems|desc=
<M> Second extended fs support         
[ ]  Ext2 extended attributes         
[ ]  Ext2 execute in place support   
<M> Ext3 journalling file system support
}}
 
Examples of usage:
* [[Package:AMD Catalyst Video Drivers]]
* [[Package:ACPI Daemon]]
* [[Microcode]]
 
=== Discussion Pages ===
 
In MediaWiki, every "regular" wiki page has a corresponding "Talk" or "Discussion" page which has a page name prefixed by "Talk:" -- you can get to this page by going to the "Action" menu, and then choosing the "Discussion" menu item. These talk pages are typically used to discuss the edits that are going on in the "main" wiki page. The problem with talk pages is that they are kind of a pain to use. However, we have a way to fix that. If you want to enable a DISQUS-based mini-forum on a talk page, insert the following wikitext on the Talk page:
 
<pre>
<pre>
x="1.01"
{{DISQUS}}
# We just set x to contain the *string* "1.01"
x=x+1
# We just added one to a *string*
print x
# Incidentally, these are comments :)
</pre>
</pre>
Awk will output:
 
...and presto! You will now have DISQUS-powered mini-forums to discuss whatever you want about your wiki page.
 
== Marking Pages as Needing Updates ==
 
If you find outdated wiki content, but you don't have the time or ability to update it, add one of the following templates to the wikitext of the page. This will add the page to the [[:Category:Needs Updates|Needs Updates Category]] so we can identify pages that need updating:
 
<pre>
<pre>
2.01
{{PageNeedsUpdates}}
{{SectionNeedsUpdates}}
</pre>
</pre>
Interesting! Although we assigned the string value 1.01 to the variable x, we were still able to add one to it. We wouldn't be able to do this in bash or python. First of all, bash doesn't support floating point arithmetic. And, while bash has "stringy" variables, they aren't "simple"; to perform any mathematical operations, bash requires that we enclose our math in an ugly $( ) construct. If we were using python, we would have to explicitly convert our 1.01 string to a floating point value before performing any arithmetic on it. While this isn't difficult, it's still an additional step. With awk, it's all automatic, and that makes our code nice and clean. If we wanted to square and add one to the first field in each input line, we would use this script:
 
 
Examples of usage:
* [[UEFI Install Guide]]
* [[Package:MediaWiki]]
* [[Clang]]
 
=== Inline Code ===
 
To emphasize commands, and other technical jargon when they appear inline in a paragraph, use the <nowiki>{{c}}</nowiki> template. When referencing files, use the <nowiki>{{f}}</nowiki> template.
 
<pre>
<pre>
{ print ($1^2)+1 }
The {{f|/etc/fstab}} file is an important one. Another important file is {{f|/boot/grub/grub.cfg}}. The {{c|emerge}} command is really nifty.
</pre>
</pre>
If you do a little experimenting, you'll find that if a particular variable doesn't contain a valid number, awk will treat that variable as a numerical zero when it evaluates your mathematical expression.


=== Lots of operators ===
This example produces the following output:
Another nice thing about awk is its full complement of mathematical operators. In addition to standard addition, subtraction, multiplication, and division, awk allows us to use the previously demonstrated exponent operator "^", the modulo (remainder) operator "%", and a bunch of other handy assignment operators borrowed from C.
 
The {{f|/etc/fstab}} file is an important one. Another important file is {{f|/boot/grub/grub.cfg}}. The {{c|emerge}} command is really nifty.
 
{{important|1=
The &#60;tt&#62; tag has been deprecated for the purpose of tagging inline code, to conform with HTML5, and the previous use of the &#60;code&#62; tag is discouraged. It is more maintainable to use the <nowiki>{{c}}</nowiki> template. }}
 
=== Slideshow ===
 
Any page has the capability of displaying a slideshow. Adding a slideshow to a page involves three steps:
 
# Upload Images
# Define Slides
# Add Slideshow to page
 
==== Upload Images ====
 
To upload images, head to [[Special:Upload]] and upload a file. It is highly recommended to upload JPEG format images in high resolution -- MediaWiki will handle scaling JPEG automatically, saving bandwidth, but does not do this for PNG. Make sure that all images you upload have the same dimensions. When you upload, make note of the '''Destination Filename''' field -- this is the name that the upload will use when you reference it in your slide. It is recommended that you choose a simple descriptive name ending in ".jpg" for the '''Destination Filename'''.
 
==== Define Slides ====
 
Once images have been uploaded, you must define slides. To define slides on a page, you enter special semantic information about the slide on the page that it will be displayed, in the following format:


These include pre- and post-increment/decrement ( i++, --foo ), add/sub/mult/div assign operators ( a+=3, b*=2, c/=2.2, d-=6.2 ). But that's not all -- we also get handy modulo/exponent assign ops as well ( a^=2, b%=4 ).
<pre><nowiki>
{{#subobject:|slideIndex=0|slideCaption=
== Wikitext Here ==
This is a fantastic slide!
|slideImage=File:Fruit.jpg|slideLink=PageName}}
</nowiki></pre>


=== Field separators ===
Here are some important instructions regarding defining slides:
Awk has its own complement of special variables. Some of them allow you to fine-tune how awk functions, while others can be read to glean valuable information about the input. We've already touched on one of these special variables, FS. As mentioned earlier, this variable allows you to set the character sequence that awk expects to find between fields. When we were using /etc/passwd as input, FS was set to ":". While this did the trick, FS allows us even more flexibility.


The FS value is not limited to a single character; it can also be set to a regular expression, specifying a character pattern of any length. If you're processing fields separated by one or more tabs, you'll want to set FS like so:
* <code>slideIndex</code> must be 0 for the first slide, 1 for the second slide, etc. Numbers must be unique and incrementing from zero, and not doing this will result in slideshow display errors (but can be easily fixed by correcting the wikitext.)
<pre>
* <code>slideCaption=</code> can contain wikitext, such as headings and links. The best way to enter <code>slideCaption</code> is as above -- type a literal <code>slideCaption=</code>, followed by enter, then specify your wikitext, and terminate the caption by a single pipe character on the following line. Pipe characters are used to separate arguments from each other.
FS="\t+"
* Specify your image name in the <code>slideImage</code> field. Your slideImage will have a name of <code>File:myname.jpg</code>, where <code>myname.jpg</code> is the '''Destination Filename''' you used when uploading the image.
</pre>
* An optional parameter called <code>slideLink=</code> can be provided to allow the image to be clickable and link to another wiki page. If it is omitted, then the image will not be clickable.
Above, we use the special "+" regular expression character, which means "one or more of the previous character".
 
==== Add Slideshow to Page ====


If your fields are separated by whitespace (one or more spaces or tabs), you may be tempted to set FS to the following regular expression:
Once the slides have been added to the page, you can add the following text to your page at the point you'd like the slideshow to appear:
<pre>
<pre>
FS="[[:space:]]+"
{{Slideshow}}
</pre>
</pre>
While this assignment will do the trick, it's not necessary. Why? Because by default, FS is set to a single space character, which awk interprets to mean "one or more spaces or tabs." In this particular example, the default FS setting was exactly what you wanted in the first place!


Complex regular expressions are no problem. Even if your records are separated by the word "foo," followed by three digits, the following regular expression will allow your data to be parsed properly:
=== YouTube Videos (Screencasts, etc.) ===
<pre>
FS="foo[0-9][0-9][0-9]"
</pre>


=== Number of fields ===
Screencasting is an easy method to explain complex tasks. Take for instance <code>youtu.be/5KDei5mBfSg</code> and chop off the id and insert it into the following syntax to produce a video example.
The next two variables we're going to cover are not normally intended to be written to, but are normally read and used to gain useful information about the input. The first is the NF variable, also called the "number of fields" variable. Awk will automatically set this variable to the number of fields in the current record. You can use the NF variable to display only certain input lines:
<pre>
NF == 3 { print "this particular record has three fields: " $0 }
</pre>
Of course, you can also use the NF variable in conditional statements, as follows:
<pre>
{
    if ( NF > 2 ) {
        print $1 " " $2 ":" $3
    }
}
</pre>


=== Record number ===
<pre>{{#widget:YouTube16x9|id=5KDei5mBfSg}}</pre>
The record number (NR) is another handy variable. It will always contain the number of the current record (awk counts the first record as record number 1). Up until now, we've been dealing with input files that contain one record per line. For these situations, NR will also tell you the current line number. However, when we start to process multi-line records later in the series, this will no longer be the case, so be careful! NR can be used like the NF variable to print only certain lines of the input:
{{#widget:YouTube16x9|id=5KDei5mBfSg}}
<pre>
(NR < 10 ) || (NR > 100) { print "We are on record number 1-9 or 101+" }
</pre>
<pre>
{
    #skip header
    if ( NR > 10 ) {
        print "ok, now for the real information!"
    }
}
</pre>
Awk provides additional variables that can be used for a variety of purposes. We'll cover more of these variables in later articles.


We've come to the end of our initial exploration of awk. As the series continues, I'll demonstrate more advanced awk functionality, and we'll end the series with a real-world awk application.
{{tip|The sample video above explains how to create your own screencasts under Funtoo Linux.}}


== Resources ==
Most YouTube videos are in 16x9 format and should use the <code>YouTube16x9</code> widget. There is also a <code>YouTube4x3</code> widget for videos with a 4x3 aspect ratio.
{{note|These YouTube widgets have been updated to be mobile-friendly.}}


* Read Daniel's other awk articles on Funtoo: Awk By Example, [[Awk by example, Part2 |Part 2]] and [[Awk by example, Part3 |Part 3]].
[[Category:Wiki Development]]
* If you'd like a good old-fashioned book, [http://www.oreilly.com/catalog/sed2/ O'Reilly's sed & awk, 2nd Edition] is a wonderful choice.
* Be sure to check out the [http://www.faqs.org/faqs/computer-lang/awk/faq/ comp.lang.awk FAQ]. It also contains lots of additional awk links.
* Patrick Hartigan's [http://sparky.rice.edu/~hartigan/awk.html awk tutorial] is packed with handy awk scripts.
* [http://www.tasoft.com/tawk.html Thompson's TAWK Compiler] compiles awk scripts into fast binary executables. Versions are available for Windows, OS/2, DOS, and UNIX.
* [http://www.gnu.org/software/gawk/manual/gawk.html The GNU Awk User's Guide] is available for online reference.
* [http://www.folkstalk.com/2011/12/good-examples-of-awk-command-in-unix.html Awk Command] daily useful examples.
[[Category:Linux Core Concepts]]
[[Category:Articles]]
{{ArticleFooter}}

Revision as of 07:38, January 4, 2015

Thanks for your interest in contributing to the the Funtoo wiki!

Types of Edits

Before we get started, let's review what changes are okay to make, and what changes are not okay:

Type of ChangeOkay?
Grammar/spelling fixesYes
New wiki contentYes
New package informationYes
Adding to existing articleMaybe -- see below
Adding missing/incomplete informationYes
Making correctionsYes
Adding work-arounds to problems experiencedNo - open bug first on bug tracker.
   Important

Note that if you experience some problem with Funtoo Linux, during installation or otherwise, the proper course of action is to not add a work-around to our documentation, but to open a bug on our bug tracker. This is important because the problem you experienced may be a legitimate bug and the solution may be to fix the bug rather than add a work-around to our documentation. We may end up fixing a bug, making a documentation fix, or possibly both.

Basics

Here is a list of basic wiki information that you will need to know to get started:

  • First, to perform edits on the wiki, you must Create a Funtoo account and log in.
  • You can create a new page by navigating to http://www.funtoo.org/New_Page_Name. Underscores are the equivalent of spaces. Then select "Create" under the "Actions" menu.
  • Whether creating a new page or editing an existing page by clicking "Edit", you will be presented with Web-based text editor that allows you to modify the wikitext of the page. The wikitext is rendered to produce the document you see when you view the page normally.
  • Another fun thing you can do is click on your name under the "Account" menu once you have logged in. This will bring you to your "User" page. Then click "Create with Form" unde the "Actions" menu and enter your geographic and other information. This will allow you to be displayed on our Usermap and will also allow your full name to be displayed on Ebuild pages for which you are an author. It's generally a good idea to do this.
   Tip

The following sections document how to use wikitext and Funtoo templates on the Funtoo wiki.

Paragraphs

To create a new paragraph, insert a blank line between two lines of text. If a blank line doesn't exist between two lines of wikitext, they will be combined into a single flowing paragraph.

If you leave leading whitespace at the beginning of a line, MediaWiki will render it as pre-formatted text. Beware of this. Here's an example:

foobar

This can rear its ugly head when specifying template parameters, so you will get this:

   Note
ugh!

...instead of this:

   Note

This looks much better!

Page and Section Capitalization

In general, capitalize all words in page names and section heading except:

  • Articles: a, an, the
  • Coordinating Conjunctions: and, but, or, for, nor, etc.
  • Prepositions (fewer than five letters): on, at, to, from, by, etc.

Document Hierarchy

Use section headings to create a document hierarchy for your page. These will define the table of contents that appears at the top of the wiki page. Create chapters, sections and sub-sections as follows:

= Page Title =

== Chapter Title ==

=== Section Title ===

==== SubSection Title ====

   Note

By default, Table of Contents is disabled on the Funtoo wiki. If you would like to enable the TOC, you can place a __TOC__ on a blank line where you'd like the Table of Contents to appear, or place __FORCETOC__ on a blank line anywhere in the wikitext to force the TOC to appear at the top of the page.

In general, when creating new documents, it's best to use level-3 (three "="'s) Section Titles to break up content. Level-2 Section Titles are best used for major sections of larger documents. Use them infrequently. Level-1 Section Titles generally do not need to be used.

Links

Internal links to other wiki pages can be specified as [[pagename]]. To specify an alternate name for the link, use [[pagename|my link name]].

For external links, use [http://funtoo.org my link] to specify a URL. If you want the URL to appear in the wikitext, you can specify it without brackets: http://forums.funtoo.org.

Lists

MediaWiki supports a number of list formats:

  • Unordered List
  • Unordered Item 2
    • Unordered sub-item
  1. Ordered List
  2. Ordered Item 2
    1. Ordered sub-item
Term
This is called a "definition list". It is used when defining various terms.

If you need to quote a portion of text from another site, use <blockquote> as follows:

Wikipedia (ˌwɪkɨˈpiːdiə/ or wɪkiˈpiːdiə/ wik-i-pee-dee-ə) is a collaboratively edited, multilingual, free-access, free content Internet encyclopedia that is supported and hosted by the non-profit Wikimedia Foundation. Volunteers worldwide collaboratively write Wikipedia's 30 million articles in 287 languages, including over 4.5 million in the English Wikipedia. Anyone who can access the site can edit almost any of its articles, which on the Internet comprise[4] the largest and most popular general reference work.[5][6][7][8][9] In February 2014, The New York Times reported that Wikipedia is ranked fifth globally among all websites stating, "With 18 billion page views and nearly 500 million unique visitors a month..., Wikipedia trails just Yahoo, Facebook, Microsoft and Google, the largest with 1.2 billion unique visitors."[10]

Literal Text and HTML Symbols

Here is wikitext for the section above, which I am displaying by placing the literal wikitext between a <pre> and </pre> tag. If you want to disable wikitext processing for an inline span of text, use <nowiki> and </nowiki>. If you want to print out a tag literally, use &#60; and &#62; (In the wikitext, I used &amp;#60; and &amp;#62 to display these!)

* Unordered List
* Unordered Item 2
** Unordered sub-item

# Ordered List
# Ordered Item 2
## Ordered sub-item

;Term: This is called a "definition list". It is used when defining various terms.

If you need to quote a portion of text from another site, use <tt><blockquote></tt> as follows:

<blockquote>
Wikipedia (ˌwɪkɨˈpiːdiə/ or wɪkiˈpiːdiə/ wik-i-pee-dee-ə) is a collaboratively edited, multilingual, free-access, 
free content Internet encyclopedia that is supported and hosted by the non-profit Wikimedia Foundation. Volunteers
worldwide collaboratively write Wikipedia's 30 million articles in 287 languages, including over 4.5 million in the 
English Wikipedia. Anyone who can access the site can edit almost any of its articles, which on the Internet 
comprise[4] the largest and most popular general reference work.[5][6][7][8][9] In February 2014, The New York 
Times reported that Wikipedia is ranked fifth globally among all websites stating, "With 18 billion page views 
and nearly 500 million unique visitors a month..., Wikipedia trails just Yahoo, Facebook, Microsoft and Google, 
the largest with 1.2 billion unique visitors."[10]
</blockquote>

Linking to Packages

To link to a package page, use the Package template:

{{Package|sys-apps/portage}}

This template will create a link to the official wiki page for sys-apps/portage, and render using the official "English" page name, as follows:

sys-apps/portage

If you specify a yet-to-be-documented ebuild, it will render like this (which is okay -- it will encourage people to document it):

No results

Tables

Instead of using traditional MediaWiki table wikitext, use the following format:

{{TableStart}}
<tr class="info"><th>Header 1</th><th>Header 2</th></tr>
<tr><td>Value 1</td><td>Value 2</td></tr>
<tr><td>Value 3</td><td>Value 4</td></tr>
{{TableEnd}}

This wil render as follows:

Header 1Header 2
Value 1Value 2
Value 3Value 4
   Tip

This table syntax has an added benefit of creating a responsive table that renders properly on mobile devices.

It is possible to use the following CSS classes with tr (rows) and td/th elements to color them as desired:

Class Name
success
info
warning
active
danger

Displaying Source Code

To display source code, use can use the file template, specifying a lang= parameter:

{{file|name=foobar|lang=python|desc=foobarosity|body=
import system
}}

This will produce:

   foobar (python source code) - foobarosity
import system

The parameters name (filename), lang (language for syntax highlighting) and desc (Description, appearing as a caption) are optional. For a list of supported languages, see this list.


   Important

If you need to display the pipe ("|") character within the body of a file template, replace each "|" with {{!}} -- otherwise your file contents will not display properly. This is necessary because {{file}} is a template and the "|" character is used as a delimiter for arguments to the template.

Displaying Text File Contents

For displaying the contents of non-programming language text files (like config files), you have two options. You can enclose your lines within <pre> tags, or use the new file template. The file template is used like so:

{{file|name=/etc/foo.conf|desc=My foo.conf file|body=
# /etc/host.conf:
# $Header: /var/cvsroot/gentoo/src/patchsets/glibc/extra/etc/host.conf,v 1.1 2006/09/29
}}

This will produce:

   /etc/foo.conf - My foo.conf file
# /etc/host.conf:
# $Header: /var/cvsroot/gentoo/src/patchsets/glibc/extra/etc/host.conf,v 1.1 2006/09/29

Console

To display console output, use the <console> tag:

For a root console:

<console>
###i## run a command as root
</console>

Produces:

root # run a command as root

For a non-root console:

<console>
$ ##i##run a command as user
</console>

Produces:

user $ run a command as user
   Important

Note that we use a # prompt for root and a $ prompt to denote a non-root user.

   Important

The ##i## text tags the rest of the line as being user input ("i" is for "input"). It is then highlighted in a noticeable color so it stands out from text that is not typed in by the user.

If you need to end highlighting of user input prior to the end of a line, use ##!i## to mark the end of the highlighted area.

The following special character sequences are also available:

  • ##g## - Green
  • ##y## - Yellow
  • ##bl## - Blue
  • ##r## - Red
  • ##b## - Bold

Please use the above coloring options sparingly. It is sometimes nice to use them to get wiki console output to match the colors that are displayed on a Linux console. Also note that for every color above, there is a matching ##!(colorcode)## option to turn color off prior to end of line.

Here is an example of its use:

root # bluetoothctl 
[NEW] Controller 00:02:72:C9:62:65 antec [default]
root ##bl##[bluetooth]##!bl###power on
Changing power on succeeded
root ##bl##[bluetooth]##!bl### agent on
Agent registered
root ##bl##[bluetooth]##!bl### scan on
Discovery started
root ##bl##[bluetooth]##!bl### devices
Device 00:1F:20:3D:1E:75 Logitech K760
root ##bl##[bluetooth]##!bl### pair 00:1F:20:3D:1E:75
Attempting to pair with 00:1F:20:3D:1E:75
[CHG] Device 00:1F:20:3D:1E:75 Connected: yes
root ##r##[agent]##!r## Passkey: 454358
root ##r##[agent]##!r## Passkey: 454358
root ##r##[agent]##!r## Passkey: 454358
root ##r##[agent]##!r## Passkey: 454358
root ##r##[agent]##!r## Passkey: 454358
root ##r##[agent]##!r## Passkey: 454358
root ##r##[agent]##!r## Passkey: 454358
[CHG] Device 00:1F:20:3D:1E:75 Paired: yes
Pairing successful
[CHG] Device 00:1F:20:3D:1E:75 Connected: no
root ##bl##[bluetooth]##!bl### connect 00:1F:20:3D:1E:75
Attempting to connect to 00:1F:20:3D:1E:75
[CHG] Device 00:1F:20:3D:1E:75 Connected: yes
Connection successful
root ##bl##[bluetooth]##!bl### quit
[DEL] Controller 00:02:72:C9:62:65 antec [default]
root #

Informational Messages

Notes, warnings, tips, and important templates can be used for informational messages that need to be offset from the regular text flow:

{{note|this is a note}}
   Note

this is a note

{{important|this is important}}
   Important

this is important

{{warning|this is a warning}}
   Warning

this is a warning

{{tip|this is a tip}}
   Tip

this is a tip

Note that these templates used to be called fancynote, fancytip, etc. The "fancy" names have been deprecated but will still be supported for the forseeable future.

Kernelop

To display kernel configuration options, we encourage you to use the kernelop template. To use the kernelop template, create an entry similar to the following example:

{{kernelop|title=foo,bar|desc=
kernel options pasted from "make menuconfig"
}} 
   Note

Kernelop is colored blue to slightly resemble the blueish background from make menuconfig.

Adding this entry will give you the following output: Under foo-->bar:

kernel options

Here's a more concrete example: Under File systems:

<M> Second extended fs support          
[ ]   Ext2 extended attributes          
[ ]   Ext2 execute in place support     
<M> Ext3 journalling file system support

Examples of usage:

Discussion Pages

In MediaWiki, every "regular" wiki page has a corresponding "Talk" or "Discussion" page which has a page name prefixed by "Talk:" -- you can get to this page by going to the "Action" menu, and then choosing the "Discussion" menu item. These talk pages are typically used to discuss the edits that are going on in the "main" wiki page. The problem with talk pages is that they are kind of a pain to use. However, we have a way to fix that. If you want to enable a DISQUS-based mini-forum on a talk page, insert the following wikitext on the Talk page:

{{DISQUS}}

...and presto! You will now have DISQUS-powered mini-forums to discuss whatever you want about your wiki page.

Marking Pages as Needing Updates

If you find outdated wiki content, but you don't have the time or ability to update it, add one of the following templates to the wikitext of the page. This will add the page to the Needs Updates Category so we can identify pages that need updating:

{{PageNeedsUpdates}}
{{SectionNeedsUpdates}}


Examples of usage:

Inline Code

To emphasize commands, and other technical jargon when they appear inline in a paragraph, use the {{c}} template. When referencing files, use the {{f}} template.

The {{f|/etc/fstab}} file is an important one. Another important file is {{f|/boot/grub/grub.cfg}}. The {{c|emerge}} command is really nifty.

This example produces the following output:

The /etc/fstab file is an important one. Another important file is /boot/grub/grub.cfg. The emerge command is really nifty.

   Important

The <tt> tag has been deprecated for the purpose of tagging inline code, to conform with HTML5, and the previous use of the <code> tag is discouraged. It is more maintainable to use the {{c}} template.

Slideshow

Any page has the capability of displaying a slideshow. Adding a slideshow to a page involves three steps:

  1. Upload Images
  2. Define Slides
  3. Add Slideshow to page

Upload Images

To upload images, head to Special:Upload and upload a file. It is highly recommended to upload JPEG format images in high resolution -- MediaWiki will handle scaling JPEG automatically, saving bandwidth, but does not do this for PNG. Make sure that all images you upload have the same dimensions. When you upload, make note of the Destination Filename field -- this is the name that the upload will use when you reference it in your slide. It is recommended that you choose a simple descriptive name ending in ".jpg" for the Destination Filename.

Define Slides

Once images have been uploaded, you must define slides. To define slides on a page, you enter special semantic information about the slide on the page that it will be displayed, in the following format:

{{#subobject:|slideIndex=0|slideCaption=
== Wikitext Here ==
This is a fantastic slide!
|slideImage=File:Fruit.jpg|slideLink=PageName}}

Here are some important instructions regarding defining slides:

  • slideIndex must be 0 for the first slide, 1 for the second slide, etc. Numbers must be unique and incrementing from zero, and not doing this will result in slideshow display errors (but can be easily fixed by correcting the wikitext.)
  • slideCaption= can contain wikitext, such as headings and links. The best way to enter slideCaption is as above -- type a literal slideCaption=, followed by enter, then specify your wikitext, and terminate the caption by a single pipe character on the following line. Pipe characters are used to separate arguments from each other.
  • Specify your image name in the slideImage field. Your slideImage will have a name of File:myname.jpg, where myname.jpg is the Destination Filename you used when uploading the image.
  • An optional parameter called slideLink= can be provided to allow the image to be clickable and link to another wiki page. If it is omitted, then the image will not be clickable.

Add Slideshow to Page

Once the slides have been added to the page, you can add the following text to your page at the point you'd like the slideshow to appear:

{{Slideshow}}

YouTube Videos (Screencasts, etc.)

Screencasting is an easy method to explain complex tasks. Take for instance youtu.be/5KDei5mBfSg and chop off the id and insert it into the following syntax to produce a video example.

{{#widget:YouTube16x9|id=5KDei5mBfSg}}

   Tip

The sample video above explains how to create your own screencasts under Funtoo Linux.

Most YouTube videos are in 16x9 format and should use the YouTube16x9 widget. There is also a YouTube4x3 widget for videos with a 4x3 aspect ratio.

   Note

These YouTube widgets have been updated to be mobile-friendly.