<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Augusto Zanella Bardini</title>
    <description>The latest articles on Forem by Augusto Zanella Bardini (@bardiniaz).</description>
    <link>https://forem.com/bardiniaz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F38366%2Fba22ebda-dd44-460b-9f66-89ac0e1f3f76.jpg</url>
      <title>Forem: Augusto Zanella Bardini</title>
      <link>https://forem.com/bardiniaz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bardiniaz"/>
    <language>en</language>
    <item>
      <title>Shell Scripting for Newbies 03</title>
      <dc:creator>Augusto Zanella Bardini</dc:creator>
      <pubDate>Fri, 20 Jul 2018 03:03:29 +0000</pubDate>
      <link>https://forem.com/bardiniaz/shell-scripting-for-newbies-03-3a1c</link>
      <guid>https://forem.com/bardiniaz/shell-scripting-for-newbies-03-3a1c</guid>
      <description>&lt;h3&gt;
  
  
  Conditionals
&lt;/h3&gt;

&lt;p&gt;In the last tutorial, you've given a look at how to interact with the user and how to return simple outputs accordingly to the user interaction.&lt;/p&gt;

&lt;p&gt;Ironically, your cat's been using the computer lately to ask for things. Of course it's not working, but you can solve this problem! Lets talk to your cat!&lt;/p&gt;

&lt;p&gt;First of all, we'll want to ask him what does he want. Let's do it this way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"What do you want, fella?&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;read &lt;/span&gt;answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;TIP: &lt;strong&gt;printf&lt;/strong&gt; is a better alternative to the command &lt;strong&gt;echo&lt;/strong&gt;. By now, it's just the same, except from you'll need to write &lt;strong&gt;\n&lt;/strong&gt; in the end of the sentences in order to go to the next line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that you've got his answer in the variable &lt;em&gt;answer&lt;/em&gt;, we'll see this NEW &lt;del&gt;hell no&lt;/del&gt; AWESOME logic: The &lt;strong&gt;if&lt;/strong&gt; command. It works almost as simple as it is written, but with some caveats. We already know that it's possible to test the truth of a statement with the command &lt;strong&gt;test&lt;/strong&gt;, so let's just tell the computer what to do &lt;strong&gt;if&lt;/strong&gt; it's true:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"What do you want, fella?&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;read &lt;/span&gt;answer

&lt;span class="c"&gt;#if the test is true, then it'll be printed the message for the cat&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nv"&gt;$answer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'food'&lt;/span&gt;
&lt;span class="k"&gt;then &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"There's meat in the fridge, dumbass!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we've literally responded to the cat to find his own food! To tell the computer where the &lt;strong&gt;if&lt;/strong&gt; conditional ends, just use &lt;del&gt;this is not a joke&lt;/del&gt; the command &lt;strong&gt;fi&lt;/strong&gt;.&lt;br&gt;
There's a simple trick to make the code even better readable. We can exchange the command &lt;strong&gt;test&lt;/strong&gt; to a pair of &lt;strong&gt;[ ]&lt;/strong&gt; around the statements, have a look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"What do you want, fella?&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;read &lt;/span&gt;answer

&lt;span class="c"&gt;#if the test is true, then it'll be printed the message for the cat&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$answer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'food'&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;then &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"There's meat in the fridge, dumbass!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cool, but your lil' kitty might not really know what he wants. So let's just add another literal command, say hello to the &lt;strong&gt;else&lt;/strong&gt; command! In case his answer is anything but food, let's just ignore it &lt;del&gt;poor cat&lt;/del&gt; and give him the cuddling option.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"What do you want, fella?&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;read &lt;/span&gt;answer

&lt;span class="c"&gt;#if the test is true, then it'll be printed the message for the cat&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$answer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"food"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;then 
        &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"There's meat in the fridge, dumbass!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="c"&gt;#now if his last answer was anything but food, you'll make this question &lt;/span&gt;
        &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"Want some cuddle, so? [yes/no]&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        &lt;span class="nb"&gt;read &lt;/span&gt;answer
        &lt;span class="c"&gt;#if his answer is yes again, you tell him you are busy,&lt;/span&gt;
        &lt;span class="c"&gt;#else, you tell him to top annoying!&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$answer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"yes"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"Sorry, I'm busy learning shell scripting.&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        &lt;span class="k"&gt;else
                &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"So stop annoying me!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

        &lt;span class="k"&gt;fi 
fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;TIP: Learning how to use the &lt;strong&gt;if&lt;/strong&gt; command is actually intuitive. The &lt;del&gt;boring&lt;/del&gt; funny part is understanding completely the &lt;strong&gt;test&lt;/strong&gt; command. You can have a deeper look at bash expressions and when you should use them clicking &lt;a href="https://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now this is getting bigger! Once the cat's answer is anything but food in the first question, we give him another question with &lt;del&gt;please stop&lt;/del&gt;&lt;br&gt;
 two more options! Notice that this question is only made if the first answer &lt;strong&gt;IS NOT&lt;/strong&gt; food. The possible outputs of our script are shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What do you want, fella?
food
There's meat in the fridge, dumbass!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What do you want, fella?
idk
Want some cuddle, so? [yes/no]
yes
Sorry, I'm busy learning shell scripting.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What do you want, fella?
communism
Want some cuddle, so? [yes/no]
no
So stop annoying me!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  About
&lt;/h2&gt;

&lt;p&gt;You can find all my scripts in &lt;a href="https://github.com/azbardini/shellscript"&gt;my github&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Follow me for more articles!&lt;/p&gt;

</description>
      <category>bash</category>
      <category>shell</category>
      <category>script</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Shell Scripting for Newbies 02</title>
      <dc:creator>Augusto Zanella Bardini</dc:creator>
      <pubDate>Wed, 18 Jul 2018 02:46:24 +0000</pubDate>
      <link>https://forem.com/bardiniaz/shell-scripting-for-newbies-02-inj</link>
      <guid>https://forem.com/bardiniaz/shell-scripting-for-newbies-02-inj</guid>
      <description>&lt;h3&gt;
  
  
  Variables
&lt;/h3&gt;

&lt;p&gt;With simple variables, you can...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;save values using &lt;strong&gt;=&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;find those values putting &lt;strong&gt;$&lt;/strong&gt; in your &lt;strong&gt;echo&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;"One Look Is Worth A Thousand Words"&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/bin/bash&lt;/span&gt;

&lt;span class="nv"&gt;var&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Yes, did it!"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Have you done it? &lt;/span&gt;&lt;span class="nv"&gt;$var&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of running this script is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Have you done it? Yes, did it!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Talking to the user
&lt;/h3&gt;

&lt;p&gt;But let's do something useful with this concepts. Imagine you can only show the date for the user if he knows &lt;strong&gt;the secret password&lt;/strong&gt;! You might want to ask him the password, so do it by using the command &lt;strong&gt;read&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Then, if the user type the &lt;del&gt;easiest ever&lt;/del&gt; right password "dog", the date is shown, otherwise, the program is closed. Let's have a look at the code before anything.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"What's THE SECRET PASSWORD?"&lt;/span&gt;

&lt;span class="c"&gt;#Puts the user's answer in the variable answer&lt;/span&gt;
&lt;span class="nb"&gt;read &lt;/span&gt;answer

&lt;span class="c"&gt;#If answer is dog dog, print date!&lt;/span&gt;
&lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$answer&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"dog"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, gotta understand it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The operator &lt;strong&gt;==&lt;/strong&gt; means &lt;strong&gt;equals to&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The operator &lt;strong&gt;&amp;amp;&amp;amp;&lt;/strong&gt; means &lt;strong&gt;and&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As we had already saved the user's answer in the variable &lt;strong&gt;$answer&lt;/strong&gt; with the command &lt;strong&gt;read&lt;/strong&gt;, when we compare the variable &lt;strong&gt;$answer&lt;/strong&gt; to &lt;strong&gt;"dog"&lt;/strong&gt;, if they are the same, it prints the date; else, it finishes the program (because there are no more commands to execute).&lt;/p&gt;

&lt;p&gt;Therefore, the result of the script must be both below:&lt;/p&gt;

&lt;p&gt;With the right password:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What's THE SECRET PASSWORD?
dog
Ter Jul 17 23:32:39 -03 2018
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the wrong password:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;What's THE SECRET PASSWORD?
cat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  I'm not convinced!
&lt;/h3&gt;

&lt;p&gt;So let's crack this code a bit more!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"What's THE SECRET PASSWORD?"&lt;/span&gt;

&lt;span class="c"&gt;#Puts the user's answer in the variable answer&lt;/span&gt;
&lt;span class="nb"&gt;read &lt;/span&gt;answer

&lt;span class="c"&gt;#REVERSE LOGIC!&lt;/span&gt;
&lt;span class="c"&gt;#If answer is not dog, exit; Else, print date!&lt;/span&gt;
&lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$answer&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;"dog"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;exit
date&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stuff is different here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The operator &lt;strong&gt;!=&lt;/strong&gt; means &lt;strong&gt;different&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we use the reverse logic to do the same thing. This time, the command &lt;strong&gt;exit&lt;/strong&gt; can &lt;strong&gt;only&lt;/strong&gt; happen if the user's answer is different from &lt;strong&gt;"dog"&lt;/strong&gt;. Otherwise, it will continue running the script and eventually reach the command &lt;strong&gt;date&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The result is &lt;strong&gt;exactly&lt;/strong&gt; the same as in the previous script!&lt;/p&gt;

&lt;h2&gt;
  
  
  About
&lt;/h2&gt;

&lt;p&gt;You can find all my scripts in &lt;a href="https://github.com/azbardini/shellscript"&gt;my github&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Follow me for more articles!&lt;/p&gt;

</description>
      <category>bash</category>
      <category>shell</category>
      <category>script</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Shell Scripting for Newbies 01</title>
      <dc:creator>Augusto Zanella Bardini</dc:creator>
      <pubDate>Wed, 18 Jul 2018 01:57:43 +0000</pubDate>
      <link>https://forem.com/bardiniaz/shell-scripting-for-newbies-4642</link>
      <guid>https://forem.com/bardiniaz/shell-scripting-for-newbies-4642</guid>
      <description>&lt;p&gt;Let's suppose you want to check your &lt;em&gt;any linux system&lt;/em&gt; stats, you might probably use commands such as &lt;strong&gt;w&lt;/strong&gt;, &lt;strong&gt;date&lt;/strong&gt;, or &lt;strong&gt;df&lt;/strong&gt;. That means you need to write three commands and check their results, one by one... Not the funniest hobby!&lt;/p&gt;

&lt;p&gt;That's where shell scripting arrives: lets automatize tasks, and a little more...&lt;/p&gt;

&lt;h3&gt;
  
  
  Hello Mars
&lt;/h3&gt;

&lt;p&gt;To start, let's just create an &lt;strong&gt;hellomars.sh&lt;/strong&gt; file. Do this by typing in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;hellomars.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, use &lt;del&gt;vim&lt;/del&gt; your finest editor to edit this file and have some &lt;del&gt;lack of&lt;/del&gt; fun creating your first Hello Mars script!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/bin/bash&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello Mars!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once created, give this file permission to be executed and execute the file itself by typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x hellomars.sh
./hellomars.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you may have noticed, &lt;strong&gt;echo&lt;/strong&gt; is the command to write something as output. The &lt;em&gt;#/bin/bash&lt;/em&gt; is used to tell linux which interpreter it must use (there are plenty of them, &lt;em&gt;sh&lt;/em&gt;, &lt;em&gt;bash&lt;/em&gt;, &lt;em&gt;dash&lt;/em&gt;...). The output of the script might be as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello Mars!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  One after the other
&lt;/h3&gt;

&lt;p&gt;Now that you know how to write something in the screen, lets write something relevant. Putting all those first commands together, you can make another file such, let's call it &lt;em&gt;mysystem.sh&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/bin/bash&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Aliens using this computer:"&lt;/span&gt;
w
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"What year am I?"&lt;/span&gt;
&lt;span class="nb"&gt;date
echo&lt;/span&gt; &lt;span class="s2"&gt;"Is there any computer left?"&lt;/span&gt;
&lt;span class="nb"&gt;df&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;tip: -h flag turns &lt;em&gt;df&lt;/em&gt; a little more &lt;em&gt;human readable&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By running this script, the output must be something as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Aliens using this computer:
 22:13:13 up  1:54,  1 user,  load average: 0,55, 0,56, 0,60
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
bardini  tty7     :0               20:22    1:54m  2:28   0.60s /sbin/upstart --user
What year am I?
Ter Jul 17 22:13:13 -03 2018
Is there any computer left?
Filesystem      Size  Used Avail Use% Mounted on
udev            2,9G     0  2,9G   0% /dev
tmpfs           586M   17M  570M   3% /run
/dev/sda1       105G   33G   67G  33% /
tmpfs           2,9G   31M  2,9G   2% /dev/shm
tmpfs           5,0M  4,0K  5,0M   1% /run/lock
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;People might not understand the functions you are using in your script, so comment it using hashtags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;#This shows users in this computer&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Aliens using this computer:"&lt;/span&gt;
w

&lt;span class="c"&gt;#This shows the date and time of this computer&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"What year am I?"&lt;/span&gt;
&lt;span class="nb"&gt;date&lt;/span&gt;

&lt;span class="c"&gt;#This shows the disk usage of the computer&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Is there any computer left?"&lt;/span&gt;
&lt;span class="nb"&gt;df&lt;/span&gt; &lt;span class="nt"&gt;-h&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  About
&lt;/h2&gt;

&lt;p&gt;You can find all my scripts in &lt;a href="https://github.com/azbardini/shellscript"&gt;my github&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Follow me for more articles!&lt;/p&gt;

</description>
      <category>bash</category>
      <category>shell</category>
      <category>script</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
