ifConfig page added and corrected various imperfections in while for and if pages

git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@207 a672b425-5310-4d7a-af5c-997e18724b81
This commit is contained in:
omenem 2018-11-15 15:00:14 +00:00
parent 7a4c278c30
commit fcc1748074
4 changed files with 89 additions and 28 deletions

View File

@ -0,0 +1,61 @@
---
layout: page
category-page: intermediate
category-title: Intermediate commands
tags: command IfConfig
author: Matteo Omenetti
title: IfConfig
---
<!-- Introduction -->
<i> IfConfig </i> stands for "<b>I</b>nterface <b>C</b>onfiguration". It is used
to configure, control, and query network interface parameters of your system. <br>
If you try running this command with no arguments, it will simply display information
about all network interfaces currently active. <br>
{% highlight bash %}
ifConfig
{% endhighlight %}
The output sill resembles something like this, of course it changes from machine
to machine:
<pre>
en5: flags=8863 UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST mtu 1500
ether ac:de:48:00:11:22
inet6 fe80::aede:48ff:fe00:1122%en5 prefixlen 64 scopeid 0x8
nd6 options=201 PERFORMNUD,DAD
media: autoselect (100baseTX full-duplex)
status: active
ap1: flags=8802 BROADCAST,SIMPLEX,MULTICAST mtu 1500
ether f2:18:98:41:74:42
media: autoselect
status: inactive
...
</pre>
<!-- End of Introduction -->
If you want to view the configuration of all network interfaces, not just the ones currently active, you can use
flag <code>a</code>.
{% highlight bash %}
IiConfig -a
{% endhighlight %}
If you want to view the configuration of a specific interface, you can specify the name of the interface
you want to view after the command <i>IfConfig</i>:
{% highlight bash %}
ifConfig ap1
{% endhighlight %}
This command will show only the configuration of ap1.
To enable an interface, you can use the command ifConfig with the name of the interface
you want to enable, followed by the key word <code>up</code>.
However, enabling or disabling a device, is a privilege reserved for the super user, therefore you also
have to use the command <code>sudo</code>.
{% highlight bash %}
sudo ifConfig ap1 up
{% endhighlight %}
To disable an interface, you can follow the same procedure, this time using the key word <code>down</code>.
{% highlight bash %}
sudo ifConfig ap1 down
{% endhighlight %}

View File

@ -9,16 +9,16 @@ title: For Loop
<!-- Introduction -->
The second type of loops are for loops.
They follow this sintax:
They follow this syntax:
{% highlight bash %}
for [variable] in [list] do
[code]
done
{% endhighlight %}
Their purpose is to <i>iterate</i> over a list. Also while loops could do this, you might argue... <br>
Of course they could, but for loops are specifically meant to do this. Therefore, for instance,
you don't have to decleare your counter variable outside the loop. Most importantly,
Their purpose is to <i>iterate</i> over a list. Also, while loops could do this, you might argue... <br>
Of course, they could, but for loops are specifically meant to do this. Therefore, for instance,
you don't have to declare your counter variable outside the loop. Most importantly,
this variable can be accessed from inside the loop. <br>
For loops take this form:
@ -53,12 +53,12 @@ The output of this piece of code is:
</pre>
<!-- End of First Example -->
<!-- Explenation of Numerical Range -->
<!-- Explanation of Numerical Range -->
There are also other ways to specify the <i> numerical range </i>. For instance, if your numerical range
is too big, you can simply write: <code> {1..100} </code>. This piece of code means every natural number
between 1 and 100 (both included). <br>
Ranges can also count backward like this: <code>{10..1}</code>.
You can even icrement the numerical value by step of two: <code> {0..10..2} </code>.
You can even increment the numerical value by step of two: <code> {0..10..2} </code>.
This piece of code means every natural number between 0 and 10 with a step of two,
0 2 4 6... 10.
<!-- End of Explenation of Numerical Range -->
<!-- End of Explanation of Numerical Range -->

View File

@ -21,7 +21,7 @@ if [condition]; then
fi
{% endhighlight %}
Anything between <code>then</code> and <code>fi</code> will be executed only if the condtion
Anything between <code>then</code> and <code>fi</code> will be executed only if the condition
evaluates to true. <br>
Here is a simple example:
@ -33,9 +33,9 @@ if [$i -ge 200]; then
fi
{% endhighlight %}
In this first example we evaluate a varibale <code>i</code> to 105.
In this first example we evaluate a variable <code>i</code> to 105.
The <i> if statement </i> will print "You chose a big number"
only if the number contained in our varibale <code>i</code> is <b>G</b>reater or
only if the number contained in our variable <code>i</code> is <b>G</b>reater or
<b>E</b>qual to 200. <br>
This is our case, therefore the output of this piece of code will be:
<pre>
@ -47,7 +47,7 @@ This is our case, therefore the output of this piece of code will be:
<!-- If Else -->
<h3> If Else </h3>
Sometimes we want to perform a certain set of actions, if our condtion evaluates to
Sometimes we want to perform a certain set of actions, if our condition evaluates to
true and another set of actions if our condition evaluates to false. We can do this with
the <i> if else </i> statement.
<i> if else </i> sattements take this form:
@ -76,12 +76,12 @@ else
fi
{% endhighlight %}
In this example, that is just an extention of the previuous example, we
evealuate a variable <code>i</code> to 50. If <code>i</code> is gretaer or equal to
In this example, that is just an extension of the previous example, we
evaluate a variable <code>i</code> to 50. If <code>i</code> is greater or equal to
200, you print out "You chose a big number", otherwise,
(if <code>i</code> is not gretaer or equal to 200), just like in this case, you print out
(if <code>i</code> is not greater or equal to 200), just like in this case, you print out
"You chose a small number".
Therefore the output of this piece of code is:
Therefore, the output of this piece of code is:
<pre>
You chose a small number.
@ -91,8 +91,8 @@ Therefore the output of this piece of code is:
<!-- If Elif Else -->
<h3> If Elif Else </h3>
Sometimes, in programming, it is necessary to have a series of condtions that lead to different paths.
We can accomodate this need with the <i>if else elif</i> mechanism.
Sometimes, in programming, it is necessary to have a series of conditions that lead to different paths.
We can accommodate this need with the <i>if else elif</i> mechanism.
The <i>if else elif</i> mechanism takes this form:
{% highlight bash %}
@ -128,11 +128,11 @@ else
fi
{% endhighlight %}
In this example, that is just an extention of the previuous example, we evealuate a
variable <code>i</code> to 150. If <code>i</code> is gretaer or equal to 200,
In this example, that is just an extension of the previous example, we evaluate a
variable <code>i</code> to 150. If <code>i</code> is greater or equal to 200,
you print out "You chose a big number", if <code>i</code> is equal to 150 you print out
"You chose 150" otherwise you print out "You chose a small number".
Therefore the output of this piece of code is:
Therefore, the output of this piece of code is:
<pre>
You chose 150.

View File

@ -41,10 +41,10 @@ done
{% endhighlight %}
In this first example, you simply create a variable called i and evaluate it to 0.
Then you acces the while loop: the condition <code> [$i -lt 4] </code> means that this while
loop will run until the <code> i </code> varibale is less than 4.
Then you access the while loop: the condition <code> [$i -lt 4] </code> means that this while
loop will run until the <code> i </code> variable is less than 4.
Every cycle of this loop, you print out the value of variable i with <code> echo $i </code>
and finally you increase its value by 1 with <code> i=$((i + 1)) </code>.
and finally, you increase its value by 1 with <code> i=$((i + 1)) </code>.
Therefore in 4 cycles the value of i will be 4. This will make the condition of the while loop false.
The output of this piece of code is:
<pre>
@ -58,7 +58,7 @@ The output of this piece of code is:
<!-- Infinite Loop First Example -->
Sometimes it is required to decleare infinite loops for various programming purposes. <br>
Sometimes it is required to declare infinite loops for various programming purposes. <br>
Here is an example:
{% highlight bash %}
i=1;
@ -82,7 +82,7 @@ No termination condition is set for this loop in this example. This type of loop
is called infinite loop.<br>
The <code> exit </code> statement is used to quit the loop. This loop will
iterate for 9 times, then
as soon as <code> i </code> becomes equal to 0, the condtition of the last if
as soon as <code> i </code> becomes equal to 0, the condition of the last if
statement will evaluate to true and the loop will be terminated. <br>
The output of this piece of code is:
@ -115,7 +115,7 @@ done
<!-- Read -->
In scripting, while loops are often used to process files line by line. <br>
Here is an examaple:
Here is an example:
{% highlight bash %}
while read -r first_name last_name phone;
do
@ -125,12 +125,12 @@ done &lt; "$file"
The <code> read </code> command is used to read a file line by line.
The flag <code> -r </code> is used to tell the
command read to intepret backslashes (/) literally, instead as escape characters.
command read to interpret backslashes (/) literally, instead as escape characters.
This command, expect for some few
rare cases, should always be used with this flag.
In this example, <code> &lt; "$file" </code> redirects the loop's input from a file
whose name is stored in a variable.
This file has 3 colums, <code> first_name last_name phone </code>, separated by
This file has 3 columns, <code> first_name last_name phone </code>, separated by
blank space (or a tab).
This piece of code only prints out the second column.
<!-- End of Read -->