{"id":13185,"date":"2019-04-01T06:54:04","date_gmt":"2019-04-01T06:54:04","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13185"},"modified":"2019-04-01T06:54:04","modified_gmt":"2019-04-01T06:54:04","slug":"bash-shell","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/bash-shell\/","title":{"rendered":"BASH SHELL"},"content":{"rendered":"<h1 class=\"post-title\">Understand Linux Shell and Basic Shell Scripting Language Tips \u2013 Part I<\/h1>\n<p>Picture speak more than words and the below picture says all about the working of\u00a0<strong>Linux<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n<div id=\"attachment_3439\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/understand-linux-shell-and-basic-shell-scripting-language-tips\/understanding-linux-shell\/\" rel=\"attachment wp-att-3439\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3439\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/07\/Understanding-Linux-Shell.png\" alt=\"Understanding Linux Shell\" width=\"382\" height=\"387\" aria-describedby=\"caption-attachment-3439\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-3439\" class=\"wp-caption-text\">Understanding Linux Shell<\/p>\n<\/div>\n<p><strong>Read Also<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/basic-shell-programming-part-ii\/\" target=\"_blank\" rel=\"noopener\">5 Shell Scripts to Learn Shell Programming \u2013 Part II<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/sailing-through-the-world-of-linux-bash-scripting-part-iii\/\" target=\"_blank\" rel=\"noopener\">Sailing Through The World of Linux BASH Scripting \u2013 Part III<\/a><\/li>\n<\/ol>\n<h3>Understanding Linux Shell<\/h3>\n<ol>\n<li><strong>Shell<\/strong>: A Command-Line Interpretor that connects a user to\u00a0<strong>Operating System<\/strong>\u00a0and allows to execute the commands or by creating text script.<\/li>\n<li><strong>Process<\/strong>: Any task that a user run in the system is called a process. A process is little more complex than just a task.<\/li>\n<li><strong>File<\/strong>: It resides on hard disk (<strong>hdd<\/strong>) and contains data owned by a\u00a0<strong>user<\/strong>.<\/li>\n<li><strong>X-windows aka windows<\/strong>: A mode of Linux where screen (<strong>monitor<\/strong>) can be split in small \u201c<strong>parts<\/strong>\u201d called\u00a0<strong>windows<\/strong>, that allow a\u00a0<strong>user<\/strong>\u00a0to do several things at the same time and\/or switch from one task to another easily and view graphics in a nice way.<\/li>\n<li><strong>Text terminal<\/strong>: A monitor that has only the capability of displaying text stuff, no graphics or a very basic graphics display.<\/li>\n<li><strong>Session<\/strong>: Time between\u00a0<strong>logging<\/strong>\u00a0<strong>on<\/strong>\u00a0and\u00a0<strong>logging out<\/strong>\u00a0of the system.<\/li>\n<\/ol>\n<h3>Types of Shell on a Standard Linux Distribution<\/h3>\n<p><strong>Bourne shell<\/strong>\u00a0: The Bourne shell was one of the major shells used in early versions and became a de facto standard. It was written by\u00a0<strong>Stephen Bourne<\/strong>\u00a0at\u00a0<strong>Bell Labs<\/strong>. Every Unix-like system has at least one shell compatible with the Bourne shell. The Bourne shell program name is \u201c<strong>sh<\/strong>\u201d and it is typically located in the file system hierarchy at\u00a0<strong>\/bin\/sh<\/strong>.<\/p>\n<p><strong>C shell<\/strong>: The\u00a0<strong>C shell<\/strong>\u00a0was developed by\u00a0<strong>Bill Joy<\/strong>\u00a0for the\u00a0<strong>Berkeley Software Distribution<\/strong>. Its syntax is modelled after the\u00a0<strong>C<\/strong>\u00a0programming language. It is used primarily for interactive terminal use, but less frequently for scripting and operating system control.\u00a0<strong>C<\/strong>\u00a0shell has many interactive commands.<\/p>\n<h3>Beginning the Fun! (Linux Shell)<\/h3>\n<p>There exist thousands of commands for command-line user, how about remembering all of them? Hmmm! Simply you can not. The real power of computer is to ease the ease your work, you need to automate the process and hence you need scripts.<\/p>\n<p>Scripts are collections of commands, stored in a file. The shell can read this file and act on the commands as if they were typed at the keyboard. The shell also provides a variety of useful programming features to make scripts truly powerful.<\/p>\n<h3>Basics of Shell Programming<\/h3>\n<ol>\n<li>To get a Linux shell, you need to start a terminal.<\/li>\n<li>To see what shell you have,<strong>\u00a0run: echo $SHELL<\/strong>.<\/li>\n<li>In Linux, the dollar sign (<strong>$<\/strong>) stands for a shell variable.<\/li>\n<li>The \u2018<strong>echo<\/strong>\u2018 command just returns whatever you type in.<\/li>\n<li>The pipeline instruction (<strong>|<\/strong>) comes to rescue, when chaining several commands.<\/li>\n<li>Linux commands have their own syntax, Linux won\u2019t forgive you whatsoever is the mistakes. If you get a command wrong, you won\u2019t flunk or damage anything, but it won\u2019t work.<\/li>\n<li><strong>#!\/bin\/sh<\/strong>\u00a0\u2013 It is called shebang. It is written at the top of a shell script and it passes the instruction to the program\u00a0<strong>\/bin\/sh<\/strong>.<\/li>\n<\/ol>\n<h3>About shell Script<\/h3>\n<p>Shell script is just a simple text file with \u201c<strong>.sh<\/strong>\u201d extension, having executable permission.<\/p>\n<h4>Process of writing and executing a script<\/h4>\n<ol>\n<li>Open terminal.<\/li>\n<li>Navigate to the place where you want to create script using \u2018<strong>cd<\/strong>\u2018 command.<\/li>\n<li><strong>Cd<\/strong>\u00a0(enter) [This will bring the prompt at\u00a0<strong>Your home Directory<\/strong>].<\/li>\n<li>touch\u00a0<strong>hello.sh<\/strong>\u00a0(Here we named the script as\u00a0<strong>hello<\/strong>, remember the \u2018<strong>.sh<\/strong>\u2018 extension is compulsory).<\/li>\n<li>vi\u00a0<strong>hello.sh<\/strong>\u00a0(nano\u00a0<strong>hello.sh<\/strong>) [You can use your favourite editor, to edit the script].<\/li>\n<li><strong>chmod 744 hello.sh<\/strong>\u00a0(making the script executable).<\/li>\n<li><strong>sh hello.sh<\/strong>\u00a0or\u00a0<strong>.\/hello.sh<\/strong>\u00a0(running the script)<\/li>\n<\/ol>\n<h5>Writing your First Script<\/h5>\n<pre>#!\/bin\/bash\r\n# My first script\r\n\r\necho \"Hello World!\"<\/pre>\n<p>Save the above lines on a text file, make it executable and run it, as described above.<\/p>\n<h4>Sample Output<\/h4>\n<pre>Hello World!<\/pre>\n<p>In the above code.<\/p>\n<pre>#!\/bin\/bash (is the shebang.)\r\n# My first script (is comment, anything following '#' is a comment)\r\necho \u201cHello World!\u201d (is the main part of this script)<\/pre>\n<h5>Writing your Second Script<\/h5>\n<p>OK time to move to the next script. This script will tell you, your\u2019s \u201c<strong>username<\/strong>\u201d and list the running\u00a0<strong>processes<\/strong>.<\/p>\n<pre>#! \/bin\/bash\r\necho \"Hello $USER\"\r\necho \"Hey i am\" $USER \"and will be telling you about the current processes\"\r\necho \"Running processes List\"\r\nps<\/pre>\n<p>Create a file with above codes, save it to anything you want, but with extension \u201c<strong>.sh<\/strong>\u201c, make it executable and run it, from you terminal.<\/p>\n<h4>Sample Output<\/h4>\n<pre>Hello tecmint\r\nHey i am tecmint and will be telling you about the current processes\r\nRunning processes List\r\n  PID TTY          TIME CMD\r\n 1111 pts\/0    00:00:00 bash\r\n 1287 pts\/0    00:00:00 sh\r\n 1288 pts\/0    00:00:00 ps<\/pre>\n<p><strong>Was this cool<\/strong>? Writing script is as simple as getting an idea and writing pipelined commands. There are some restrictions, too. Shell scripts are excellent for concise filesystem operations and scripting the combination of existing functionality in filters and command line tools via pipes.<\/p>\n<p>When your needs are greater \u2013 whether in\u00a0<strong>functionality<\/strong>,\u00a0<strong>robustness<\/strong>,\u00a0<strong>performance<\/strong>,\u00a0<strong>efficiency<\/strong>\u00a0etc \u2013 then you can move to a more full-featured language.<\/p>\n<p>If you already know\u00a0<strong>C<\/strong>\/<strong>Perl<\/strong>\/<strong>Python<\/strong>\u00a0programming language or any other programming language, learning the scripting language won\u2019t be much difficult.<\/p>\n<h5>Writing your Third Script<\/h5>\n<p>Moving to, write our third and last script for this article. This script acts as an interactive script. Why don\u2019t you, yourself execute this simple yet interactive script and tell us how you felt.<\/p>\n<pre>#! \/bin\/bash\r\necho \"Hey what's Your First Name?\";\r\nread a;\r\necho \"welcome Mr.\/Mrs. $a, would you like to tell us, Your Last Name\";\r\nread b;\r\necho \"Thanks Mr.\/Mrs. $a $b for telling us your name\";\r\necho \"*******************\"\r\necho \"Mr.\/Mrs. $b, it's time to say you good bye\"<\/pre>\n<h4>Sample Output<\/h4>\n<pre>Hey what's Your First Name?\r\nAvishek\r\nwelcome Mr.\/Mrs. Avishek, would you like to tell us, Your Last Name\r\nKumar\r\nThanks Mr.\/Mrs. Avishek Kumar for telling us your name\r\n******************************************************\r\nMr.\/Mrs. Kumar, it's time to say you good bye<\/pre>\n<p>Well this is not an end. We tried to bring a taste of scripting to you. In our future article we will elaborate this scripting language topic, rather a never ending scripting language topic, to be more perfect. Your\u00a0<strong>valuable thoughts<\/strong>\u00a0in comments is highly appreciated,\u00a0<strong>Like and share<\/strong>\u00a0us and help us to spread. Till then just chill, keep connected, stay tuned.<\/p>\n<p><strong>Read Also<\/strong>\u00a0:\u00a0<a title=\"learn shell programming\" href=\"https:\/\/www.tecmint.com\/basic-shell-programming-part-ii\/\">5 Shell Scripts to Learn Shell Programming \u2013 Part II<\/a><\/p>\n<h1 class=\"post-title\">5 Shell Scripts for Linux Newbies to Learn Shell Programming \u2013 Part II<\/h1>\n<p>To Learn something you need to do it, without the fear of being unsuccessful. I believe in practicality and hence will be accompanying you to the practical world of Scripting Language.<\/p>\n<div id=\"attachment_3502\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/basic-shell-programming-part-ii\/shell-scripting-2\/\" rel=\"attachment wp-att-3502\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3502\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/07\/Shell-Scripting-2.png\" alt=\"Learn Basic Shell Scripting\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-3502\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-3502\" class=\"wp-caption-text\">Learn Basic Shell Scripting<\/p>\n<\/div>\n<p>This article is an extension of our First article\u00a0<a href=\"https:\/\/www.tecmint.com\/understand-linux-shell-and-basic-shell-scripting-language-tips\/\" target=\"_blank\" rel=\"noopener\">Understand Linux Shell and Basic Shell Scripting \u2013 Part I<\/a>, where we gave you a taste of Scripting, continuing that we won\u2019t disappoint you in this article.<\/p>\n<h3>Script 1: Drawing a Special Pattern<\/h3>\n<pre>#!\/bin\/bash\r\nMAX_NO=0\r\necho -n \"Enter Number between (5 to 9) : \"\r\nread MAX_NO\r\nif ! [ $MAX_NO -ge 5 -a $MAX_NO -le 9 ] ; then\r\n   echo \"WTF... I ask to enter number between 5 and 9, Try Again\"\r\n   exit 1\r\nfi\r\nclear\r\nfor (( i=1; i&lt;=MAX_NO; i++ )) do     for (( s=MAX_NO; s&gt;=i; s-- ))\r\n    do\r\n       echo -n \" \"\r\n    done\r\n    for (( j=1; j&lt;=i;  j++ ))     do      echo -n \" .\"      done     echo \"\" done ###### Second stage ###################### for (( i=MAX_NO; i&gt;=1; i-- ))\r\ndo\r\n    for (( s=i; s&lt;=MAX_NO; s++ ))\r\n    do\r\n       echo -n \" \"\r\n    done\r\n    for (( j=1; j&lt;=i;  j++ ))\r\n    do\r\n     echo -n \" .\"\r\n    done\r\n    echo \"\"\r\ndone\r\necho -e \"\\n\\n\\t\\t\\t Whenever you need help, Tecmint.com is always there\"<\/pre>\n<p>Most of the above \u2018<strong>key words<\/strong>\u2018 would be known to you and most of them are self explanatory. e.g.,\u00a0<strong>MAX<\/strong>\u00a0sets the maximum value of the variable, for is a loop and anything within the loop gets on executing again and again till the loop is valid for given value of input.<\/p>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# chmod 755 Special_Pattern.sh\r\n[root@tecmint ~]# .\/Special_Pattern.sh\r\nEnter Number between (5 to 9) : 6\r\n       .\r\n      . .\r\n     . . .\r\n    . . . .\r\n   . . . . .\r\n  . . . . . .\r\n  . . . . . .\r\n   . . . . .\r\n    . . . .\r\n     . . .\r\n      . .\r\n       .\r\n\r\n                         Whenever you need help, Tecmint.com is always there<\/pre>\n<p>If you are a little aware of any programming language, learning the above script is not difficult, even if you are new to computation, programming and Linux it is not going to be much difficult.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Special_Pattern.sh\">Download Special_Pattern.sh<\/a><\/p>\n<h3>Script 2: Creating Colorful Script<\/h3>\n<p>&nbsp;<\/p>\n<p>Who says,\u00a0<strong>Linux is colorless<\/strong>\u00a0and boring, save the codes below to anything [<strong>dot<\/strong>]\u00a0<strong>sh<\/strong>, make it executable and Run it, don\u2019t forget to tell me how it was, Think what you can achieve, implementing it somewhere.<\/p>\n<pre>#!\/bin\/bash\r\nclear \r\necho -e \"33[1m Hello World\"\r\n# bold effect\r\necho -e \"33[5m Blink\"\r\n# blink effect\r\necho -e \"33[0m Hello World\"\r\n# back to normal\r\necho -e \"33[31m Hello World\"\r\n# Red color\r\necho -e \"33[32m Hello World\"\r\n# Green color\r\necho -e \"33[33m Hello World\"\r\n# See remaining on screen\r\necho -e \"33[34m Hello World\"\r\necho -e \"33[35m Hello World\"\r\necho -e \"33[36m Hello World\"\r\necho -e -n \"33[0m\"\r\n# back to normal\r\necho -e \"33[41m Hello World\"\r\necho -e \"33[42m Hello World\"\r\necho -e \"33[43m Hello World\"\r\necho -e \"33[44m Hello World\"\r\necho -e \"33[45m Hello World\"\r\necho -e \"33[46m Hello World\"\r\necho -e \"33[0m Hello World\"<\/pre>\n<p><strong>Note<\/strong>: Don\u2019t bother about the color code now, Those important to you will be at your tongue, gradually.<\/p>\n<p><strong>Warning<\/strong>: Your terminal might not have the facility of blinking.<\/p>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# chmod 755 Colorfull.sh\r\n[root@tecmint ~]# .\/Colorfull.sh\r\n\r\nHello World\r\nBlink\r\nHello World\r\nHello World\r\nHello World\r\nHello World\r\nHello World\r\nHello World\r\nHello World\r\nHello World\r\nHello World\r\nHello World\r\nHello World\r\nHello World\r\nHello World\r\nHello World<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Colorfull.sh\">Download Colorfull.sh<\/a><\/p>\n<h3>Script 3: Encrypt a File\/Directory<\/h3>\n<p>This script will encrypt a\u00a0<strong>file<\/strong>\u00a0(remember?\u00a0<strong>directory<\/strong>\/<strong>driver<\/strong>\/\u2026. everything is treated as file, in\u00a0<strong>Linux<\/strong>). The current limitation of the above script is that it don\u2019t support auto completion of name using\u00a0<strong>TAB<\/strong>. Moreover, you need to place the script and file to be encrypted in the same folder. You may need to install \u201c<strong>pinentry-gui<\/strong>\u201d, using\u00a0<strong>yum<\/strong>\u00a0or\u00a0<strong>apt<\/strong>\u00a0the package, if required.<\/p>\n<pre>[root@midstage ~]# yum install pinentry-gui\r\n[root@midstage ~]# apt-get install pinentry-gui<\/pre>\n<p>Crete a file called \u201c<strong>Encrypt.sh<\/strong>\u201d and place the following script, make it executable and run it as shown.<\/p>\n<pre>#!\/bin\/bash\r\necho \"Welcome, I am ready to encrypt a file\/folder for you\"\r\necho \"currently I have a limitation, Place me to thh same folder, where a file to be \r\nencrypted is present\"\r\necho \"Enter the Exact File Name with extension\"\r\nread file;\r\ngpg -c $file\r\necho \"I have encrypted the file successfully...\"\r\necho \"Now I will be removing the original file\"\r\nrm -rf $file<\/pre>\n<h3>Sample Output<\/h3>\n<pre>[root@tecmint ~]# chmod 755 Encrypt.sh\r\n[root@tecmint ~]# .\/Encrypt.sh\r\n\r\nWelcome, I am ready to encrypt a file\/folder for you\r\ncurrently I have a limitation, Place me to the same folder, where a file to be\r\n\r\nencrypted is present\r\nEnter the Exact File Name with extension\r\n\r\npackage.xml\r\n\r\n                                                   \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\r\n                                                   \u2502 Enter passphrase                                    \u2502\r\n                                                   \u2502                                                     \u2502\r\n                                                   \u2502                                                     \u2502\r\n                                                   \u2502 Passphrase *******_________________________________ \u2502\r\n                                                   \u2502                                                     \u2502\r\n                                                   \u2502       &lt;OK&gt;                             &lt;Cancel&gt;     \u2502\r\n                                                   \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\r\n\r\nPlease re-enter this passphrase\r\n\r\n                                                   \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\r\n                                                   \u2502 Please re-enter this passphrase                     \u2502\r\n                                                   \u2502                                                     \u2502\r\n                                                   \u2502 Passphrase ********________________________________ \u2502\r\n                                                   \u2502                                                     \u2502\r\n                                                   \u2502       &lt;OK&gt;                             &lt;Cancel&gt;     \u2502\r\n                                                   \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\r\n\r\nI have encrypted the file successfully...\r\nNow I will be removing the original file\r\n&lt;\/pre&gt;<\/pre>\n<p><strong>gpg -c<\/strong>\u00a0: This will encrypt your file, using a passkey aka\u00a0<strong>password<\/strong>. In this process of learning you would have never thought that the actual process of learning could be that much easy. So after encrypting a file what you need? Obviously! decrypting the file. And I want you \u2013 the learner, the reader to write the decryption script yourself, don\u2019t worry I am not leaving you in the middle, I just want you to gain something out of this article.<\/p>\n<p><strong>Note<\/strong>:\u00a0<strong>gpg -d filename.gpg<\/strong>\u00a0&gt;\u00a0<strong>filename<\/strong>\u00a0is what you need to implement in your decryption script. You may post you script in comment if successful, if not you may ask me to write it for you.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Encrypt.sh\">Download Encrypt.sh<\/a><\/p>\n<h3>Script 4: Checking Server Utilization<\/h3>\n<p>Checking the server utilization is one of the important task of an administrator, and a good administrator is one who knows how to automate his day to day task. Below is the script that will give many such information about your server. Check it yourself.<\/p>\n<pre>#!\/bin\/bash\r\n    date;\r\n    echo \"uptime:\"\r\n    uptime\r\n    echo \"Currently connected:\"\r\n    w\r\n    echo \"--------------------\"\r\n    echo \"Last logins:\"\r\n    last -a |head -3\r\n    echo \"--------------------\"\r\n    echo \"Disk and memory usage:\"\r\n    df -h | xargs | awk '{print \"Free\/total disk: \" $11 \" \/ \" $9}'\r\n    free -m | xargs | awk '{print \"Free\/total memory: \" $17 \" \/ \" $8 \" MB\"}'\r\n    echo \"--------------------\"\r\n    start_log=`head -1 \/var\/log\/messages |cut -c 1-12`\r\n    oom=`grep -ci kill \/var\/log\/messages`\r\n    echo -n \"OOM errors since $start_log :\" $oom\r\n    echo \"\"\r\n    echo \"--------------------\"\r\n    echo \"Utilization and most expensive processes:\"\r\n    top -b |head -3\r\n    echo\r\n\ttop -b |head -10 |tail -4\r\n    echo \"--------------------\"\r\n    echo \"Open TCP ports:\"\r\n    nmap -p- -T4 127.0.0.1\r\n    echo \"--------------------\"\r\n    echo \"Current connections:\"\r\n    ss -s\r\n    echo \"--------------------\"\r\n    echo \"processes:\"\r\n    ps auxf --width=200\r\n    echo \"--------------------\"\r\n    echo \"vmstat:\"\r\n    vmstat 1 5<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# chmod 755 Server-Health.sh\r\n[root@tecmint ~]# .\/Server-Health.sh\r\n\r\nTue Jul 16 22:01:06 IST 2013\r\nuptime:\r\n 22:01:06 up 174 days,  4:42,  1 user,  load average: 0.36, 0.25, 0.18\r\nCurrently connected:\r\n 22:01:06 up 174 days,  4:42,  1 user,  load average: 0.36, 0.25, 0.18\r\nUSER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT\r\ntecmint   pts\/0    116.72.134.162   21:48    0.00s  0.03s  0.03s sshd: tecmint [priv]\r\n--------------------\r\nLast logins:\r\ntecmint   pts\/0        Tue Jul 16 21:48   still logged in    116.72.134.162\r\ntecmint   pts\/0        Tue Jul 16 21:24 - 21:43  (00:19)     116.72.134.162\r\n--------------------\r\nDisk and memory usage:\r\nFree\/total disk: 292G \/ 457G\r\nFree\/total memory: 3510 \/ 3838 MB\r\n--------------------\r\nOOM errors since Jul 14 03:37 : 0\r\n--------------------\r\nUtilization and most expensive processes:\r\ntop - 22:01:07 up 174 days,  4:42,  1 user,  load average: 0.36, 0.25, 0.18\r\nTasks: 149 total,   1 running, 148 sleeping,   0 stopped,   0 zombie\r\nCpu(s):  0.1%us,  0.0%sy,  0.0%ni, 99.3%id,  0.6%wa,  0.0%hi,  0.0%si,  0.0%st\r\n\r\n  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND\r\n    1 root      20   0  3788 1128  932 S  0.0  0.0   0:32.94 init\r\n    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd\r\n    3 root      RT   0     0    0    0 S  0.0  0.0   0:14.07 migration\/0<\/pre>\n<p><strong>Note<\/strong>: I have given you the script that gives the output in the terminal itself, how about getting the output in a file for future reference. Implement it using redirect operator.<\/p>\n<ol>\n<li>\u2018<strong>&gt;<\/strong>\u2018 : the redirection operator causes a file creation, and if it does exist, the contents are overwritten.<\/li>\n<li>\u2018<strong>&gt;&gt;<\/strong>\u2018 : when you use &gt;&gt;, you are adding information, rather than replacing it.<\/li>\n<li>\u2018<strong>&gt;&gt;<\/strong>\u2018 is safe, as compared to \u2018<strong>&gt;<\/strong>\u2018<\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Server-Health.sh\">Download Server-Health.sh<\/a><\/p>\n<h3>Script 5: Check Disk Space and Sends an Email Alert<\/h3>\n<p>How about getting an email when disk use in partition\u00a0<strong>PART<\/strong>\u00a0is bigger than Maximum allowed, it is a life saver script for web administrators with little modification.<\/p>\n<pre>MAX=95\r\nEMAIL=USER@domain.com\r\nPART=sda1\r\nUSE=`df -h |grep $PART | awk '{ print $5 }' | cut -d'%' -f1`\r\nif [ $USE -gt $MAX ]; then\r\n  echo \"Percent used: $USE\" | mail -s \"Running out of disk space\" $EMAIL\r\nfi<\/pre>\n<p><strong>Note<\/strong>: Remove \u201c<strong>USER<\/strong>\u201d with your user name. You can check mail using using \u2018<strong>mail<\/strong>\u2018 command.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Check-Disk-Space.sh\">Download Check-Disk-Space.sh<\/a><\/p>\n<p>Script writing and programming is beyond boundaries, anything and everything could be implemented as required. That\u2019s all for now, In my very next article I will be giving your some different flavors of scripting. Till then stay cool and tuned, enjoy.<\/p>\n<h1 class=\"post-title\">Sailing Through The World of Linux BASH Scripting \u2013 Part III<\/h1>\n<p>The Previous following articles of \u2018<strong>Shell Scripting<\/strong>\u2018 series were highly appreciated and hence I am writing this article to extend the never ending process of learning.<\/p>\n<div id=\"attachment_3557\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/sailing-through-the-world-of-linux-bash-scripting-part-iii\/shell-scripting-part-3\/\" rel=\"attachment wp-att-3557\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3557\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/07\/Shell-Scripting-Part-3.png\" alt=\"Basic Shell Scripting Part-3\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-3557\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-3557\" class=\"wp-caption-text\">Basic Shell Scripting Part-3<\/p>\n<\/div>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/understand-linux-shell-and-basic-shell-scripting-language-tips\/\" target=\"_blank\" rel=\"noopener\">Understand Basic Linux Shell Scripting Language Tips \u2013 Part I<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/basic-shell-programming-part-ii\/\" target=\"_blank\" rel=\"noopener\">5 Shell Scripts for Linux Newbies to Learn Shell Programming \u2013 Part II<\/a><\/li>\n<\/ol>\n<h5>Bash Keywords<\/h5>\n<p>A\u00a0<strong>keyword<\/strong>\u00a0is a word or symbol that has a special meaning to a computer language. The following symbols and words have special meanings to\u00a0<strong>Bash<\/strong>\u00a0when they are unquoted and the first word of a command.<\/p>\n<pre>! \t\t\tesac \t\t\tselect \t\t} \r\ncase \t\t\tfi \t\t\tthen \t\t[[ \r\ndo \t\t\tfor \t\t\tuntil \t\t]] \r\ndone \t\t\tfunction \t\twhile \t\telif\r\nif \t\t\ttime \t\t\telse \t\tin \t\t{<\/pre>\n<p>Unlike most computer languages,\u00a0<strong>Bash<\/strong>\u00a0allows keywords to be used as\u00a0<strong>variable names<\/strong>\u00a0even though this can make scripts difficult to read. To keep scripts understandable, key-words should not be used for variable names.<\/p>\n<p>A command is implemented in shell as\u00a0<strong>$<\/strong>(command). You might have to include the full path of command. e.g.,\u00a0<strong>$(\/bin\/date)<\/strong>, for correct execution.<\/p>\n<p>&nbsp;<\/p>\n<p>You may know the path of specific program using \u2018<strong>whereis<\/strong>\u2018 command. e.g.,\u00a0<strong>whereis date<\/strong><\/p>\n<pre>[root@tecmint \/]# whereis date\r\ndate: \/bin\/date \/usr\/share\/man\/man1\/date.1.gz<\/pre>\n<p>That\u2019s enough for now. We won\u2019t be talking much about these theory now. Coming to Scripts.<\/p>\n<h3>Move Current Working Directory<\/h3>\n<p>Move from current working directory to any level up by just providing the numerical value at the end of script while executing.<\/p>\n<pre>#! \/bin\/bash \r\nLEVEL=$1 \r\nfor ((i = 1; i &lt;= LEVEL; i++)) \r\ndo \r\nCDIR=..\/$CDIR \r\ndone \r\ncd $CDIR \r\necho \"You are in: \"$PWD \r\nexec \/bin\/bash<\/pre>\n<p>Save the above codes as \u201c<strong>up.sh<\/strong>\u201c, on your desktop. Make it executable (<strong>chmod 755 up.sh<\/strong>). Run:<\/p>\n<p><strong>.\/up.sh 2<\/strong>\u00a0(will Move the current working directory to two level up).<br \/>\n<strong>.\/up.sh 4<\/strong>\u00a0(will Move the current working directory to four level up).<\/p>\n<h5>Use and Area of Application<\/h5>\n<p>In larger scripts which contains folder inside folder inside\u2026 containing\u00a0<strong>libraries<\/strong>,\u00a0<strong>binaries<\/strong>,\u00a0<strong>icons<\/strong>,\u00a0<strong>executables<\/strong>, etc at different location, You as a developer can implement this script to move to the desired location in a very automated fashion.<\/p>\n<p><strong>Note<\/strong>: For is a loop in the above script and it will continue to execute till the values are true for the loop.<\/p>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint \/]# chmod 755 up\r\n[root@tecmint \/]# .\/up.sh 2\r\nYou are in: \/\r\n\r\n[root@tecmint \/]# .\/up.sh 4 \r\nYou are in: \/ \r\n\r\n[root@tecmint \/]#<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/up.sh\" target=\"_blank\" rel=\"noopener\">Download up.sh<\/a><\/p>\n<h3>Create a Random File or Folder<\/h3>\n<p>Create a random file (folder) with no chance of duplication.<\/p>\n<pre>#! \/bin\/bash\r\n\r\necho \"Hello $USER\";\r\necho \"$(uptime)\" &gt;&gt; \"$(date)\".txt\r\necho \"Your File is being saved to $(pwd)\"<\/pre>\n<p>This is a Simple script but it\u2019s working is not that much simple.<\/p>\n<ol>\n<li>\u2018<strong>echo<\/strong>\u2018 : Prints everything written within the quotes.<\/li>\n<li>\u2018<strong>$<\/strong>\u2018 : Is a shell variable.<\/li>\n<li>\u2018<strong>&gt;&gt;<\/strong>\u2018 : The output is redirected to the output of\u00a0<strong>date<\/strong>\u00a0command followed by\u00a0<strong>txt<\/strong>\u00a0extension.<\/li>\n<\/ol>\n<p>We know the output of\u00a0<strong>date<\/strong>\u00a0command is\u00a0<strong>date<\/strong>, and\u00a0<strong>time<\/strong>\u00a0in\u00a0<strong>hour<\/strong>,\u00a0<strong>minute,<\/strong>\u00a0<strong>second<\/strong>\u00a0along with\u00a0<strong>year<\/strong>. Hence we could get output on an organised file name without the chance of filename duplication. It could be very much useful when user needs the file created with\u00a0<strong>time stamp<\/strong>\u00a0for future reference.<\/p>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint \/]# .\/randomfile.sh  \r\nHello server \r\nYour File is being saved to \/home\/server\/Desktop<\/pre>\n<p>You can view the file which is created on desktop with Today\u2019s Date and current time.<\/p>\n<pre>[root@tecmint \/]# nano Sat\\ Jul\\ 20\\ 13\\:51\\:52\\ IST\\ 2013.txt \r\n13:51:52 up  3:54,  1 user,  load average: 0.09, 0.12, 0.08<\/pre>\n<p>A more detailed implementation of the above script is given below, which works on the above principle and is very useful in gathering the network information of a\u00a0<strong>Linux<\/strong>\u00a0server.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/randomfile.sh\" target=\"_blank\" rel=\"noopener\">Download randomfile.sh<\/a><\/p>\n<h3>Script to Collect Network Information<\/h3>\n<p>Gathers network information on a\u00a0<strong>Linux<\/strong>\u00a0server. The script is too large and it\u2019s not possible to post the whole code and output of the script here. So, it\u2019s better you can download the script using below download link and test it yourself.<\/p>\n<p><strong>Note<\/strong>: You might need to install\u00a0<strong>lsb-core<\/strong>\u00a0package and other required packages and dependency.\u00a0<strong>Apt<\/strong>\u00a0or\u00a0<strong>Yum<\/strong>\u00a0the required packages. Obviously you need to be\u00a0<strong>root<\/strong>\u00a0to run the script because most of the commands used here are configured to be run as\u00a0<strong>root<\/strong>.<\/p>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint \/]# .\/collectnetworkinfo.sh  \r\n\r\nThe Network Configuration Info Written To <strong>network.20-07-13.info.txt<\/strong>. Please email this file to <strong>your_name@service_provider.com<\/strong>. ktop<\/pre>\n<p>You can change the above email address in your script to get it being mailed to you. The Automatically generated file can be viewed.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/collectnetworkinfo.sh\" target=\"_blank\" rel=\"noopener\">Download collectnetworkinfo.sh<\/a><\/p>\n<h3>Script to Converts UPPERCASE to lowercase<\/h3>\n<p>A script that converts\u00a0<strong>UPPERCASE<\/strong>\u00a0to\u00a0<strong>lowercase<\/strong>\u00a0and redirects the output to a text file \u201c<strong>small.txt<\/strong>\u201d which can be modified as required.<\/p>\n<pre>#!\/bin\/bash \r\n\r\necho -n \"Enter File Name : \" \r\nread fileName \r\n\r\nif [ ! -f $fileName ]; then \r\n  echo \"Filename $fileName does not exists\" \r\n  exit 1 \r\nfi \r\n\r\ntr '[A-Z]' '[a-z]' &lt; $fileName &gt;&gt; small.txt<\/pre>\n<p>This above script can convert the case of a file of any length with a single click from\u00a0<strong>uppercase<\/strong>\u00a0to\u00a0<strong>lowercase<\/strong>and vice-versa if required, with little modification.<\/p>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint \/]# .\/convertlowercase.sh  \r\nEnter File Name : a.txt \r\n\r\nInitial File: \r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\n...<\/pre>\n<p>New File (<strong>small.txt<\/strong>) output:<\/p>\n<pre>a\r\nb\r\nc\r\nd\r\ne\r\nf\r\ng\r\nh\r\ni\r\nj\r\nk\r\n...<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/convertlowercase.sh\" target=\"_blank\" rel=\"noopener\">Download convertlowercase.sh<\/a><\/p>\n<h3>Simple Calculator Program<\/h3>\n<pre>#! \/bin\/bash \r\nclear \r\nsum=0 \r\ni=\"y\" \r\n\r\necho \" Enter one no.\" \r\nread n1 \r\necho \"Enter second no.\" \r\nread n2 \r\nwhile [ $i = \"y\" ] \r\ndo \r\necho \"1.Addition\" \r\necho \"2.Subtraction\" \r\necho \"3.Multiplication\" \r\necho \"4.Division\" \r\necho \"Enter your choice\" \r\nread ch \r\ncase $ch in \r\n    1)sum=`expr $n1 + $n2` \r\n     echo \"Sum =\"$sum;; \r\n        2)sum=`expr $n1 - $n2` \r\n     echo \"Sub = \"$sum;; \r\n    3)sum=`expr $n1 \\* $n2` \r\n     echo \"Mul = \"$sum;; \r\n    4)sum=`expr $n1 \/ $n2` \r\n     echo \"Div = \"$sum;; \r\n    *)echo \"Invalid choice\";; \r\nesac \r\necho \"Do u want to continue (y\/n)) ?\" \r\nread i \r\nif [ $i != \"y\" ] \r\nthen \r\n    exit \r\nfi \r\ndone<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint \/]# .\/simplecalc.sh \r\n\r\nEnter one no. \r\n12 \r\nEnter second no. \r\n14 \r\n1.Addition \r\n2.Subtraction \r\n3.Multiplication \r\n4.Division \r\nEnter your choice \r\n1 \r\nSum =26 \r\nDo u want to continue (y\/n)) ? \r\ny\r\n1.Addition \r\n2.Subtraction \r\n3.Multiplication \r\n4.Division \r\nEnter your choice \r\n3 \r\nmul = 14812\r\nDo u want to continue (y\/n)) ? \r\nn<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/simplecalc.sh\" target=\"_blank\" rel=\"noopener\">Download simplecalc.sh<\/a><\/p>\n<p>So did you saw how easy it was to create a powerful program as calculations such a simple way. Its\u2019 not the end. We will be comping up with at least one more article of this series, covering broad perspective from administration view.<\/p>\n<p>That\u2019s all for now. Being the reader and the best critic don\u2019t forget to tell us how much and what you enjoyed in this article and what you want to see in the future article. Any question is highly welcome in comment. Till then stay\u00a0<strong>healthy<\/strong>,\u00a0<strong>safe<\/strong>\u00a0and\u00a0<strong>tuned<\/strong>.\u00a0<strong>Like<\/strong>\u00a0and\u00a0<strong>Share<\/strong>\u00a0us and help us spread.<\/p>\n<h1 class=\"post-title\">Mathematical Aspect of Linux Shell Programming \u2013 Part IV<\/h1>\n<p>In this post I will be discussing the S<strong>cripts<\/strong>\u00a0from the\u00a0<strong>Mathematical<\/strong>\u00a0and\u00a0<strong>Number<\/strong>\u00a0point of view. Although I have posted a more complex script (<strong>Simple Calculator<\/strong>) in the previous post, but on a user part it was difficult to understand and hence I thought to make you people learn the other useful side of learning in small packets.<\/p>\n<div id=\"attachment_3880\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/mathematical-aspect-of-linux-shell-programming-part-iv\/shell-scripting-part-4-2\/\" rel=\"attachment wp-att-3880\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3880\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/08\/Shell-Scripting-Part-41.png\" alt=\"Learn Shell Scripting Part 4\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-3880\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-3880\" class=\"wp-caption-text\">Shell Scripting Part 4<\/p>\n<\/div>\n<p>Prior to this article, three article of\u00a0<strong>Shell Scripting Series<\/strong>\u00a0are published and they are:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/understand-linux-shell-and-basic-shell-scripting-language-tips\/\">Understand Linux Shell and Basic Shell Scripting \u2013 Part I<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/basic-shell-programming-part-ii\/\">5 Shell Scripts to Learn Shell Programming \u2013 Part II<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/sailing-through-the-world-of-linux-bash-scripting-part-iii\/\">Sailing Through The World of Linux BASH Scripting \u2013 Part III<\/a><\/li>\n<\/ol>\n<p>Let\u2019s start the further learning process with some new exciting scripts, start with\u00a0<strong>Mathematics<\/strong>\u00a0scripts:<\/p>\n<h3>Script 1: Additions<\/h3>\n<p>Create a file \u201c<strong>Addition.sh<\/strong>\u201d and\u00a0<strong>chmod 755<\/strong>\u00a0to the script as described in previous post and run it.<\/p>\n<pre>#!\/bin\/bash\r\necho \u201cEnter the First Number: \u201d \r\nread a \r\necho \u201cEnter the Second Number: \u201d \r\nread b \r\nx=$(expr \"$a\" + \"$b\") \r\necho $a + $b = $x<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# vi Additions.sh\r\n[root@tecmint ~]# chmod 755 Additions.sh\r\n[root@tecmint ~]# .\/Additions.sh\r\n\r\n\u201cEnter the First Number: \u201d \r\n12 \r\n\u201cEnter the Second Number: \u201d \r\n13 \r\n12 + 13 = 25<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Additions.sh\">Download Additions.sh<\/a><\/p>\n<h3>Script 2: Substraction<\/h3>\n<pre>#!\/bin\/bash\r\necho \u201cEnter the First Number: \u201d \r\nread a \r\necho \u201cEnter the Second Number: \u201d \r\nread b \r\nx=$(($a - $b)) \r\necho $a - $b = $x<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Note<\/strong>: Here we replaced the\u00a0<strong>expr<\/strong>\u00a0and let the mathematical calculation be performed in shell.<\/p>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# vi Substraction.sh\r\n[root@tecmint ~]# chmod 755 Substraction.sh\r\n[root@tecmint ~]# .\/Substraction.sh\r\n\r\n\u201cEnter the First Number: \u201d \r\n13 \r\n\u201cEnter the Second Number: \u201d \r\n20 \r\n13 - 20 = -7<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Substraction.sh\">Download Substraction.sh<\/a><\/p>\n<h3>Script 3: Multiplication<\/h3>\n<p>So far you would be enjoying a lot, learning scripts in such an easy way, so the next in chronological order is\u00a0<strong>Multiplication<\/strong>.<\/p>\n<pre>#!\/bin\/bash\r\necho \u201cEnter the First Number: \u201d \r\nread a \r\necho \u201cEnter the Second Number: \u201d \r\nread b \r\necho \"$a * $b = $(expr $a \\* $b)\"<\/pre>\n<p><strong>Note<\/strong>: Yup! Here we didn\u2019t put the value of multiplication in a variable but performed it directly in output statement.<\/p>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# vi Multiplication.sh\r\n[root@tecmint ~]# chmod 755 Multiplication.sh\r\n[root@tecmint ~]# .\/Multiplication.sh\r\n\r\n\u201cEnter the First Number: \u201d \r\n11 \r\n\u201cEnter the Second Number: \u201d \r\n11 \r\n11 * 11 = 121<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Multiplication.sh\">Download Multiplication.sh<\/a><\/p>\n<h3>Script 4: Division<\/h3>\n<p>Right! Next is\u00a0<strong>Division<\/strong>, and again it is a very simple script. Check it Yourself.<\/p>\n<pre>#!\/bin\/bash\r\necho \u201cEnter the First Number: \u201d \r\nread a \r\necho \u201cEnter the Second Number: \u201d \r\nread b \r\necho \"$a \/ $b = $(expr $a \/ $b)\"<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# vi Division.sh\r\n[root@tecmint ~]# chmod 755 Division.sh\r\n[root@tecmint ~]# .\/Division.sh\r\n\r\n\u201cEnter the First Number: \u201d \r\n12 \r\n\u201cEnter the Second Number: \u201d \r\n3 \r\n12 \/ 3 = 4<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Division.sh\">Download Division.sh<\/a><\/p>\n<h3>Script 5: Table<\/h3>\n<p>Fine! What after these basic mathematical operation. Lets write a script that prints table of any number.<\/p>\n<pre>#!\/bin\/bash\r\necho \u201cEnter The Number upto which you want to Print Table: \u201d \r\nread n \r\ni=1 \r\nwhile [ $i -ne 10 ] \r\ndo \r\ni=$(expr $i + 1) \r\ntable=$(expr $i \\* $n) \r\necho $table \r\ndone<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# vi Table.sh\r\n[root@tecmint ~]# chmod 755 Table.sh\r\n[root@tecmint ~]# .\/Table.sh\r\n\r\n\u201cEnter The Number upto which you want to Print Table: \u201d \r\n29 \r\n58 \r\n87 \r\n116 \r\n145 \r\n174 \r\n203 \r\n232 \r\n261 \r\n290<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Table.sh\">Download Table.sh<\/a><\/p>\n<h3>Script 6: EvenOdd<\/h3>\n<p>We as a child always have carried out calculation to find if the number is odd or even. Won\u2019t it be a good idea to implement it in script.<\/p>\n<pre>#!\/bin\/bash\r\necho \"Enter The Number\" \r\nread n \r\nnum=$(expr $n % 2) \r\nif [ $num -eq 0 ] \r\nthen \r\necho \"is a Even Number\" \r\nelse \r\necho \"is a Odd Number\" \r\nfi<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# vi EvenOdd.sh\r\n[root@tecmint ~]# chmod 755 EvenOdd.sh\r\n[root@tecmint ~]# .\/EvenOdd.sh\r\n\r\nEnter The Number \r\n12 \r\nis a Even Number<\/pre>\n<pre>[root@tecmint ~]# .\/EvenOdd.sh\r\n\r\nEnter The Number \r\n11 \r\nis a Odd Number<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/EvenOdd.sh\">Download EvenOdd.sh<\/a><\/p>\n<h3>Script 7: Factorial<\/h3>\n<p>Next is to find the Factorial.<\/p>\n<pre>#!\/bin\/bash \r\necho \"Enter The Number\" \r\nread a \r\nfact=1 \r\nwhile [ $a -ne 0 ] \r\ndo \r\nfact=$(expr $fact \\* $a) \r\na=$(expr $a - 1) \r\ndone \r\necho $fact<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# vi Factorial.sh\r\n[root@tecmint ~]# chmod 755 Factorial.sh\r\n[root@tecmint ~]# .\/Factorial.sh\r\n\r\nEnter The Number \r\n12 \r\n479001600<\/pre>\n<p>You may now relax with a feeling that calculating\u00a0<strong>12*11*10*9*7*7*6*5*4*3*2*1<\/strong>\u00a0would be more difficult than a simple script as produced above. Think of the situation where you require to find\u00a0<strong>99!<\/strong>\u00a0or something like that. Sure! This script will be very much handy in that situation.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Factorial.sh\">Download Factorial.sh<\/a><\/p>\n<h3>Script 8: Armstrong<\/h3>\n<p><strong>Armstrong Number<\/strong>! Ohhh You forget what an\u00a0<strong>Armstrong Number<\/strong>\u00a0is. Well an Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example,\u00a0<strong>371<\/strong>\u00a0is an Armstrong number since\u00a0<strong>3**3 + 7**3 + 1**3 = 371<\/strong>.<\/p>\n<pre>#!\/bin\/bash \r\necho \"Enter A Number\" \r\nread n \r\narm=0 \r\ntemp=$n \r\nwhile [ $n -ne 0 ] \r\ndo \r\nr=$(expr $n % 10) \r\narm=$(expr $arm + $r \\* $r \\* $r) \r\nn=$(expr $n \/ 10) \r\ndone \r\necho $arm \r\nif [ $arm -eq $temp ] \r\nthen \r\necho \"Armstrong\" \r\nelse \r\necho \"Not Armstrong\" \r\nfi<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# vi Armstrong.sh\r\n[root@tecmint ~]# chmod 755 Armstrong.sh\r\n[root@tecmint ~]# .\/Armstrong.sh\r\n\r\nEnter A Number \r\n371 \r\n371 \r\nArmstrong<\/pre>\n<pre>[root@tecmint ~]# .\/Armstrong.sh\r\n\r\nEnter A Number \r\n123 \r\n36 \r\nNot Armstrong<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Armstrong.sh\">Download Armstrong.sh<\/a><\/p>\n<h3>Script 9: Prime<\/h3>\n<p>The last script is to distinguish whether a number is prime or not.<\/p>\n<pre>#!\/bin\/bash \r\necho \u201cEnter Any Number\u201d\r\nread n\r\ni=1\r\nc=1\r\nwhile [ $i -le $n ]\r\ndo\r\ni=$(expr $i + 1)\r\nr=$(expr $n % $i)\r\nif [ $r -eq 0 ]\r\nthen\r\nc=$(expr $c + 1)\r\nfi\r\ndone\r\nif [ $c -eq 2 ]\r\nthen\r\necho \u201cPrime\u201d\r\nelse\r\necho \u201cNot Prime\u201d\r\nfi<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# vi Prime.sh\r\n[root@tecmint ~]# chmod 755 Prime.sh\r\n[root@tecmint ~]# .\/Prime.sh\r\n\r\n\u201cEnter Any Number\u201d \r\n12 \r\n\r\n\u201cNot Prime\u201d<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Prime.sh\">Download Prime.sh<\/a><\/p>\n<p>That\u2019s all for now. In our very next article we will be covering other mathematical programs in the shell Scripting programming language. Don\u2019t forget to mention your views regarding article in the Comment section. Like and share us and help us spread. Come Visiting\u00a0<strong>tecmint.com<\/strong>\u00a0for\u00a0<strong>News<\/strong>\u00a0and articles relating to\u00a0<strong>FOSS<\/strong>. Till then Stay tuned.<\/p>\n<h1 class=\"post-title\">Calculating Mathematical Expressions in Shell Scripting Language \u2013 Part V<\/h1>\n<p>You People would be feeling comfortable, understanding\u00a0<strong>Shell Scripts<\/strong>\u00a0and writing them fluently, as per your need. This is the last post of this tutorial series, where we will be carrying out a bit complex\u00a0<strong>Mathematical Operations<\/strong>\u00a0using scripting language. The last four articles of\u00a0<strong>Shell Scripting<\/strong>\u00a0series which are chronologically.<\/p>\n<div id=\"attachment_4247\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/calculating-mathematical-expressions-in-shell-scripting-part-v\/shell-scripting-4\/\" rel=\"attachment wp-att-4247\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4247\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/09\/Shell-Scripting-4.png\" alt=\"Learn Shell Scripting\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-4247\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-4247\" class=\"wp-caption-text\">Learn Shell Scripting Part \u2013 V<\/p>\n<\/div>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/understand-linux-shell-and-basic-shell-scripting-language-tips\/\" target=\"_blank\" rel=\"noopener\">Understand Basic Linux Shell Scripting Language Tips \u2013 Part I<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/basic-shell-programming-part-ii\/\" target=\"_blank\" rel=\"noopener\">5 Shell Scripts for Linux Newbies to Learn Shell Programming \u2013 Part II<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/sailing-through-the-world-of-linux-bash-scripting-part-iii\/\" target=\"_blank\" rel=\"noopener\">Sailing Through The World of Linux BASH Scripting \u2013 Part III<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/mathematical-aspect-of-linux-shell-programming-part-iv\/\" target=\"_blank\" rel=\"noopener\">Mathematical Aspect of Linux Shell Programming \u2013 Part IV<\/a><\/li>\n<\/ol>\n<h3>Lets start with Fibonacci Series<\/h3>\n<p>A pattern of numbers where each number is the sum of two preceding numbers. The series is\u00a0<strong>0<\/strong>,<strong>\u00a01<\/strong>,\u00a0<strong>1<\/strong>,\u00a0<strong>2<\/strong>,\u00a0<strong>3<\/strong>,\u00a0<strong>5<\/strong>,\u00a0<strong>8<\/strong>\u2026\u2026 By definition, the first two numbers in the\u00a0<strong>Fibonccai<\/strong>\u00a0sequence are 0 and 1.<\/p>\n<h5>Script 1: Fibonacci.sh<\/h5>\n<pre>#!\/bin\/bash\r\necho \"How many numbers do you want of Fibonacci series ?\" \r\n  read total \r\n  x=0 \r\n  y=1 \r\n  i=2 \r\n  echo \"Fibonacci Series up to $total terms :: \" \r\n  echo \"$x\" \r\n  echo \"$y\" \r\n  while [ $i -lt $total ] \r\n  do \r\n      i=`expr $i + 1 ` \r\n      z=`expr $x + $y ` \r\n      echo \"$z\" \r\n      x=$y \r\n      y=$z \r\n  done<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# chmod 755 Fibonacci.sh\r\n[root@tecmint ~]# .\/Fibonacci.sh\r\n\r\nHow many numbers do you want of Fibonacci series ? \r\n10 \r\nFibonacci Series up to 10 terms :: \r\n0 \r\n1 \r\n1 \r\n2 \r\n3 \r\n5 \r\n8 \r\n13 \r\n21 \r\n34<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Fibonacci.sh\">Download Fibonacci.sh<\/a><\/p>\n<p>You are Familiar with the fact that computer understand only in the Binary Format, i.e., \u2018<strong>0<\/strong>\u2018 and \u2018<strong>1<\/strong>\u2018 and most of us have enjoyed learning the conversion of\u00a0<strong>Decimal<\/strong>\u00a0to\u00a0<strong>Binary<\/strong>. How about writing a simple script for this complex operation.<\/p>\n<h5>Script 2: Decimal2Binary.sh<\/h5>\n<pre>#!\/bin\/bash \r\n\r\nfor ((i=32;i&gt;=0;i--)); do \r\n        r=$(( 2**$i)) \r\n        Probablity+=( $r  ) \r\ndone \r\n\r\n[[ $# -eq 0 ]] &amp;echo -en \"Decimal\\t\\tBinary\\n\" \r\nfor input_int in $@; do \r\ns=0 \r\ntest ${#input_int} -gt 11 &amp;printf \"%-10s\\t\" \"$input_int\" \r\n\r\n        for n in ${Probablity[@]}; do \r\n\r\n                if [[ $input_int -lt ${n} ]]; then \r\n                        [[ $s = 1 ]] &amp;&amp; printf \"%d\" 0 \r\n                else \r\n                        printf \"%d\" 1 ; s=1 \r\n                        input_int=$(( $input_int - ${n} )) \r\n                fi \r\n        done \r\necho -e \r\ndone<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# chmod 755 Decimal2Binary.sh\r\n[root@tecmint ~]# .\/Decimal2Binary.sh 1121\r\n\r\nDecimal\t\tBinary \r\n1121      \t10001100001<\/pre>\n<p><strong>Note<\/strong>: The above script accept Input at run time, which obviously is an aid.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Decimal2Binary.sh\">Download Decimal2Binary.sh<\/a><\/p>\n<p>Well the inbuilt \u2018<strong>bc<\/strong>\u2018 command can convert a\u00a0<strong>decimal<\/strong>\u00a0to\u00a0<strong>binary<\/strong>\u00a0in a script of single line. Run, at your terminal.<\/p>\n<pre>[root@tecmint ~]# echo \"obase=2; NUM\" | bc<\/pre>\n<p>Replace \u2018<strong>NUM<\/strong>\u2018 with the number, which you want to convert from\u00a0<strong>Decimal<\/strong>\u00a0to\u00a0<strong>Binary<\/strong>. For example,<\/p>\n<pre>[root@tecmint ~]# echo \"obase=2; 121\" | bc \r\n\r\n1111001<\/pre>\n<p>Next we will be writing a script which function just opposite of the above script,\u00a0<strong>Converting Binary Values<\/strong>\u00a0to\u00a0<strong>Decimal<\/strong>.<\/p>\n<h5>Script 3: Binary2Decimal.sh<\/h5>\n<pre>#!\/bin\/bash \r\necho \"Enter a number :\" \r\nread Binary \r\nif [ $Binary -eq 0 ] \r\nthen \r\necho \"Enter a valid number \" \r\nelse \r\nwhile [ $Binary -ne 0 ] \r\ndo \r\nBnumber=$Binary \r\nDecimal=0 \r\npower=1 \r\nwhile [ $Binary -ne 0 ] \r\ndo \r\nrem=$(expr $Binary % 10 ) \r\nDecimal=$((Decimal+(rem*power))) \r\npower=$((power*2)) \r\nBinary=$(expr $Binary \/ 10) \r\ndone \r\necho  \" $Decimal\" \r\ndone \r\nfi<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# chmod 755 Binary2Decimal.sh\r\n[root@tecmint ~]# .\/Binary2Decimal.sh\r\n\r\nEnter a number : \r\n11 \r\n3<\/pre>\n<p><strong>Note<\/strong>: The above function can be performed in terminal using \u2018<strong>bc<\/strong>\u2018 command as.<\/p>\n<pre>[root@tecmint ~]# echo \"ibase=2; BINARY\" | bc<\/pre>\n<p>Replace \u2018<strong>BINARY<\/strong>\u2018 with the Binary number, viz.,<\/p>\n<pre>[root@tecmint ~]# echo \"ibase=2; 11010101\" | bc \r\n\r\n213<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/scripts\/Binary2Decimal.sh\">Download Binary2Decimal.sh<\/a><\/p>\n<p>Similarly you can write conversion from\u00a0<strong>octal<\/strong>,\u00a0<strong>hexadecimal<\/strong>\u00a0to\u00a0<strong>decimal<\/strong>\u00a0and vice-versa yourself. Accomplishing the above result in terminal using \u2018<strong>bc<\/strong>\u2018 command is.<\/p>\n<h5>Decimal to Octal<\/h5>\n<pre>[root@tecmint ~]# echo \"obase=8; Decimal\" | bc<\/pre>\n<h5>Decimal to Hexadecimal<\/h5>\n<pre>[root@tecmint ~]# echo \"obase=16; Decimal\" | bc<\/pre>\n<h5>Octal to Decimal<\/h5>\n<pre>[root@tecmint ~]# echo \"ibase=8; Octal\" | bc<\/pre>\n<h5>Hexadecimal to Decimal<\/h5>\n<pre>[root@tecmint ~]# echo \"ibase=16; Hexadecimal\" | bc<\/pre>\n<h5>Binary to Octal<\/h5>\n<pre>[root@tecmint ~]# echo \"ibase=2;obase=8 Binary\" | bc<\/pre>\n<p>Some of the\u00a0<strong>Common Numeric<\/strong>\u00a0tests used in shell scripting language with description is.<\/p>\n<pre>Test : INTEGER1 -eq INTEGER2\r\nMeaning: INTEGER1 is equal to INTEGER2<\/pre>\n<pre>Test : INTEGER1 -ge INTEGER2\r\nMeaning: INTEGER1 is greater than or equal to INTEGER2<\/pre>\n<pre>Test: INTEGER1 -gt INTEGER2\r\nMeaning: INTEGER1 is greater than INTEGER2<\/pre>\n<pre>Test:INTEGER1 -le INTEGER2\r\nMeaning: INTEGER1 is less than or equal to INTEGER2<\/pre>\n<pre>Test: INTEGER1 -lt INTEGER2\r\nMeaning: INTEGER1 is less than INTEGER2<\/pre>\n<pre>Test: INTEGER1 -ne INTEGER2\r\nMeaning: INTEGER1 is not equal to INTEGER2<\/pre>\n<p>That\u2019s all for this article, and the article series. This is the last article of\u00a0<strong>Shell Script Series<\/strong>\u00a0and it does not means that no article on Scripting language will be here again, it only means the shell scripting tutorial is over and whenever we find an interesting topic worth knowing or a query from you people, we will be happy to continue the series from here.<\/p>\n<p>Stay healthy, tuned and connected to\u00a0<strong>Tecmint<\/strong>. Very soon I will be coming with another interesting topic, you people will love to read. Share your valuable thoughts in\u00a0<strong>Comment Section<\/strong>.<\/p>\n<h1 class=\"post-title\">Learning Shell Scripting Language: A Guide from Newbies to System Administrator<\/h1>\n<p><strong>Linux<\/strong>\u00a0is built with certain powerful tools, which are unavailable in\u00a0<strong>Windows<\/strong>. One of such important tool is\u00a0<strong>Shell Scripting<\/strong>.\u00a0<strong>Windows<\/strong>\u00a0however comes with such a tool but as usual it is much weak as compared to it\u2019s\u00a0<strong>Linux Counterpart<\/strong>. Shell scripting\/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages. In-fact automating these day-to-day task on server is an important task, system administrator has to perform and most of the admins achieve this by writing scripts to be executed as and when required.<\/p>\n<div id=\"attachment_4328\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/learning-shell-scripting-language-a-guide-from-newbies-to-system-administrator\/shell-script-guide\/\" rel=\"attachment wp-att-4328\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4328\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/10\/Shell-Script-Guide.png\" alt=\"Linux Shell Script Guide\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-4328\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-4328\" class=\"wp-caption-text\">Linux Shell Script Guide<\/p>\n<\/div>\n<p>The most commonly used shell in\u00a0<strong>Linux<\/strong>\u00a0is\u00a0<strong>BASH<\/strong>\u00a0which stands for\u00a0<strong>Bourne Again Shell<\/strong>. Other Shell commonly found in Linux are:<\/p>\n<ol>\n<li>Almquist shell (<strong>ash<\/strong>)<\/li>\n<li>Bourne shell (<strong>sh<\/strong>)<\/li>\n<li>Debian Almquist shell (<strong>dash<\/strong>)<\/li>\n<li>korn shell (<strong>ksh<\/strong>)<\/li>\n<li>Public domain korn shell (<strong>pdksh<\/strong>)<\/li>\n<li>MirBSD korn shell (<strong>mksh<\/strong>)<\/li>\n<li>Z shell (<strong>zsh<\/strong>)<\/li>\n<li>Busybox, etc.<\/li>\n<\/ol>\n<p>We have tried to cover a large variety of shell programming on a number of aspect in\u00a0<strong>5 different posts<\/strong>.<\/p>\n<h3>Understand Linux Shell and Basic Shell Scripting \u2013 Part I<\/h3>\n<p>I was a bit hesitating to write on scripting Language, as I was not sure if the users were going to accept it or not, but the response received is a history, in itself. We tried to provide you with the basic knowledge of scripting Language and how to use it, writing basic commands, Need of comment lines and how to write it, talking shebang, making a script executable and its\u2019 execution.<\/p>\n<h5>Hello.sh<\/h5>\n<p>&nbsp;<\/p>\n<p>The first and the introductory script was aimed to get a simple output, thus making you comfortable with the world of shell scripting.<\/p>\n<h5>Process.sh<\/h5>\n<p>The second script was there, to tell you how you can execute more than one command in a script, however not piped, at this stage.<\/p>\n<h5>Interactive.sh<\/h5>\n<p>The third and last script of this post was a simple but very much interactive script which ask for you first name, store it, again ask for your last name, store it and address you with your full name, and last name in different lines of output.<\/p>\n<p>At the end of this post you were supposed to know how to execute Linux commands independently from a shell script, storing and manipulating data, as required and store data at the run-time.<\/p>\n<p><strong>Shell Script Part I<\/strong>\u00a0:\u00a0<a href=\"https:\/\/www.tecmint.com\/understand-linux-shell-and-basic-shell-scripting-language-tips\/\" target=\"_blank\" rel=\"noopener\">Understand Linux Shell and Basic Shell Scripting Language<\/a><\/p>\n<p>Feeling proud with the response received on first article, writing next article of the series was the first thought, that hit my mind and hence the second article of the series was:<\/p>\n<h3>5 Shell Scripts for Linux Newbies to Learn Scripting \u2013 Part II<\/h3>\n<p>Very much clear from the caption, here 5-Shell Scripts were listed. But to list which kind of script here, was a cumbersome job for us. We thought to dedicate this post to design and colours in shell. Our principal thinking behind this was to tell you that Linux terminal is not boring and colourless and you can perform your task in a very much colourful manner.<\/p>\n<h5>Special_patter.sh<\/h5>\n<p>The first script of this post draws a special pattern, say a diamond pattern with dots(.), the implementation of for loop here was what you learned from this specific script.<\/p>\n<h5>Colourfull.sh<\/h5>\n<p>The second script of this post, provided you with the output of several colours. You learned certain colour codes (not necessary to memorise) changing the text and background colour individually and the learning process was very much colourful<\/p>\n<h5>Encrypt.sh<\/h5>\n<p>The third article of this post was a script of less than 10 lines, but was a very useful script which encrypts a file\/folder with password. Security implementation was never so easy ever. We didn\u2019t write a decryption script here, but provided you with the command you need to decrypt a file\/folder and ask you to write the decryption script yourself.<\/p>\n<h5>Server-Health.sh<\/h5>\n<p>The fourth script of this post was a bit long script (long, at this point of learning) which reports server related information and can be redirected to a file for future reference. We utilised Linux commands in a pipelined fashion to get desired result and thus pipeline an important tool in scripting language, was in your knowledge.<\/p>\n<h5>Disk_space.sh<\/h5>\n<p>The fifth and the last script of this post was a very useful script specially for web administrator, where automatic email will be send to user if the disk space crosses the limit. Let a user registered for 5 GB of web space and as soon as his web upload limit counts reaches 4.75 GB, an automatic email will be send to user for web space increment.<\/p>\n<p><strong>Shell Script Part II<\/strong>\u00a0:\u00a0<a href=\"https:\/\/www.tecmint.com\/basic-shell-programming-part-ii\/\" target=\"_blank\" rel=\"noopener\">5 Shell Scripts to Learn Shell Programming<\/a><\/p>\n<h3>Sailing Through The World of Linux BASH Scripting \u2013 Part III<\/h3>\n<p>It was time to tell you about certain key words used and reserved in Scripting Language, so that we could refine our scripts in a very much professional manner. We discussed here, the implementation of Linux commands in shell script.<\/p>\n<h5>up.sh<\/h5>\n<p>The first script of this post aimed to tell you how to move up a directory in shell script. Well during Linux package installation you would have seen that the file gets stored at several location, automatically and this script comes handy if you need any such task.<\/p>\n<h5>Randomfile.sh<\/h5>\n<p>The second script of this post is a very useful script, and useful to Administrators. It can create unique file\/folder automatically with date and time stamp, so as to remove any chance of overwriting data.<\/p>\n<h5>Collectnetworkinfo.sh<\/h5>\n<p>The third article of this post gathers information related to server and stores it into a text file, so that it could be sent\/stored for future references.<\/p>\n<h5>Convertlowercase.sh<\/h5>\n<p>The fourth article of this post converts data either from the file or standard input to lowercase in a one go.<\/p>\n<h5>Simplecacl.sh<\/h5>\n<p>The last article of this post is a simple calculator which is capable of doing four basic Mathematical operation interactively.<\/p>\n<p><strong>Shell Script Part III<\/strong>\u00a0:\u00a0<a href=\"https:\/\/www.tecmint.com\/sailing-through-the-world-of-linux-bash-scripting-part-iii\/\" target=\"_blank\" rel=\"noopener\">Sailing Through The World of Linux BASH Scripting<\/a><\/p>\n<h3>Mathematical Aspect of Linux Shell Programming \u2013 Part IV<\/h3>\n<p>The mathematical theme based article is the result of an email I received, where a Linux Enthusiastic didn\u2019t understood the last script of the third post, yup! The calculator script. Well to simplify the mathematical operations, we created independent scripts for individual mathematical operation.<\/p>\n<h5>Addition.sh<\/h5>\n<p>Very much clear from the name this script performs addition of two numbers. We have used \u2018expr\u2019 to perform the operation.<\/p>\n<p><strong>Subtraction.sh<\/strong>,\u00a0<strong>Multiplication.sh<\/strong>,\u00a0<strong>Division.sh<\/strong>\u00a0are second, third and fourth script of the post respectively which performs mathematical operations according to their name.<\/p>\n<h5>Table.sh<\/h5>\n<p>The fifth script of this post generates table of a number, which can be provided at run-time.<\/p>\n<h5>EvenOdd.sh<\/h5>\n<p>The next script of the post checks if a number input from standard input is odd or even and prints the result on standard output.<\/p>\n<h5>Factorial.sh<\/h5>\n<p>The seventh script of this post generates the factorial of a number. Calculating factorial on black and white (paper) is a painful task, but here it is a fun.<\/p>\n<h5>Armstrong.sh<\/h5>\n<p>The script checks if a provided number is Armstrong or not.<\/p>\n<h5>Prime.sh<\/h5>\n<p>The last script of this post check if a number is prime or not and generates the corresponding output.<\/p>\n<p><strong>Shell Script Part IV<\/strong>\u00a0:\u00a0<a href=\"https:\/\/www.tecmint.com\/mathematical-aspect-of-linux-shell-programming-part-iv\/\" target=\"_blank\" rel=\"noopener\">Mathematical Aspect of Linux Shell Programming<\/a><\/p>\n<h3>Calculating Mathematical Expressions in Scripting \u2013 Part V<\/h3>\n<h5>Fibonacci.sh<\/h5>\n<p>The first script of this post test if a number being entered is a Fibonacci or not.<\/p>\n<h5>Decimal2Binary.sh<\/h5>\n<p>The second script of this post converts Decimal Number to Binary. This is one of the most common project you would have had in your summer vacation assignments.<\/p>\n<h5>Binry2Decimal.sh<\/h5>\n<p>The third script of this post converts Binary Number back to decimal, just vice-versa of above process.<\/p>\n<p>However, we didn\u2019t wrote proper script for the below mathematical conversions but provided one liner command, so that you yourself can implement it in your own script.<\/p>\n<ol>\n<li>Decimal to octal<\/li>\n<li>Decimal to Hexadecimal<\/li>\n<li>Octal to Decimal<\/li>\n<li>Hexadecimal to Decimal<\/li>\n<li>Binary to Octal , falls into the above category.<\/li>\n<\/ol>\n<p><strong>Shell Script Part V<\/strong>\u00a0:\u00a0<a href=\"https:\/\/www.tecmint.com\/calculating-mathematical-expressions-in-shell-scripting-part-v\/\" target=\"_blank\" rel=\"noopener\">Calculating Mathematical Expressions in Shell Scripting Language<\/a><\/p>\n<p>We have tested all the scripts, ourselves to ensure, every script you get runs 100% perfectly in your terminal. Moreover, we have included sample output in most of the scripts, so that you don\u2019t gets confused.<\/p>\n<p>Well that\u2019s all for now, from me. I will be here again with an interesting article, you people will love to read. Till then keep connected to\u00a0<strong>Tecmint<\/strong>. Stay Fit, Healthy and Tuned. Don\u2019t forget to provide us with your valuable thoughts in comment, which is highly appreciated.<\/p>\n<h1 class=\"post-title\">10 Useful Chaining Operators in Linux with Practical Examples<\/h1>\n<p>Chaining of Linux commands means, combining several commands and make them execute based upon the behaviour of operator used in between them. Chaining of commands in Linux, is something like you are writing\u00a0<a title=\"Write linux shell scripts\" href=\"https:\/\/www.tecmint.com\/category\/bash-shell\/\" target=\"_blank\" rel=\"noopener\">short shell scripts<\/a>\u00a0at the shell itself, and executing them from the terminal directly. Chaining makes it possible to automate the process. Moreover, an unattended machine can function in a much systematic way with the help of chaining operators.<\/p>\n<div id=\"attachment_5080\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/12\/Chaining-Operators-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-5080\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/12\/Chaining-Operators-in-Linux.png\" alt=\"Chaining Operators in Linux\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-5080\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-5080\" class=\"wp-caption-text\">10 Chaining Operators in Linux<\/p>\n<\/div>\n<p><b>Read Also:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/use-linux-awk-command-to-filter-text-string-in-files\/\" target=\"_blank\" rel=\"noopener\">How to Use Awk and Regular Expressions to Filter Text in Files<\/a><\/p>\n<p>This Article aims at throwing light on frequently used\u00a0<strong>command\u00ad-chaining operators<\/strong>, with short descriptions and corresponding examples which surely will increase your productivity and lets you write short and meaningful codes beside reducing system load, at times.<\/p>\n<h3>1. Ampersand Operator (&amp;)<\/h3>\n<p>The function of \u2018<strong>&amp;<\/strong>\u2018 is to make the command run in background. Just type the command followed with a white space and \u2018<strong>&amp;<\/strong>\u2018. You can execute more than one command in the background, in a single go.<\/p>\n<p>Run one command in the background:<\/p>\n<pre>tecmint@localhost:~$ ping \u00adc5 www.tecmint.com &amp;<\/pre>\n<p>&nbsp;<\/p>\n<p>Run two command in background, simultaneously:<\/p>\n<pre>root@localhost:\/home\/tecmint# apt-get update &amp; apt-get upgrade &amp;<\/pre>\n<h3>2. semi-colon Operator (;)<\/h3>\n<p>The semi-colon operator makes it possible to run, several commands in a single go and the execution of command occurs sequentially.<\/p>\n<pre>root@localhost:\/home\/tecmint# apt-get update ; apt-get upgrade ; mkdir test<\/pre>\n<p>The above command combination will first execute\u00a0<strong>update<\/strong>\u00a0instruction, then\u00a0<strong>upgrade<\/strong>\u00a0instruction and finally will create a \u2018<strong>test<\/strong>\u2018 directory under the current working directory.<\/p>\n<h3>3. AND Operator (&amp;&amp;)<\/h3>\n<p>The\u00a0<strong>AND Operator<\/strong>\u00a0(<strong>&amp;&amp;<\/strong>) would execute the second command only, if the execution of first command\u00a0<strong>SUCCEEDS<\/strong>, i.e., the exit status of the first command is\u00a0<strong>0<\/strong>. This command is very useful in checking the execution status of last command.<\/p>\n<p>For example, I want to visit website\u00a0<strong>tecmint.com<\/strong>\u00a0using\u00a0<a href=\"https:\/\/www.tecmint.com\/command-line-web-browsers\/\" target=\"_blank\" rel=\"noopener\">links command<\/a>, in terminal but before that I need to check if the host is\u00a0<strong>live<\/strong>\u00a0or\u00a0<strong>not<\/strong>.<\/p>\n<pre>root@localhost:\/home\/tecmint# ping -c3 www.tecmint.com &amp;&amp; links www.tecmint.com<\/pre>\n<h3>4. OR Operator (||)<\/h3>\n<p>The\u00a0<strong>OR Operator<\/strong>\u00a0(<strong>||<\/strong>) is much like an \u2018<strong>else<\/strong>\u2018 statement in programming. The above operator allow you to execute second command only if the execution of first command fails, i.e., the exit status of first command is \u2018<strong>1<\/strong>\u2018.<\/p>\n<p>For example, I want to execute \u2018<strong>apt-get update<\/strong>\u2018 from non-root account and if the first command fails, then the second\u00a0<strong>\u2018links www.tecmint.com<\/strong>\u2018 command will execute.<\/p>\n<pre>tecmint@localhost:~$ apt-get update || links tecmint.com<\/pre>\n<p>In the above command, since the\u00a0<strong>user<\/strong>\u00a0was not allowed to\u00a0<strong>update<\/strong>\u00a0system, it means that the exit status of first command is\u00a0<strong>\u20181\u2019<\/strong>\u00a0and hence the last command \u2018<strong>links tecmint.com<\/strong>\u2018 gets executed.<\/p>\n<p>What if the first command is executed successfully, with an exit status \u2018<strong>0<\/strong>\u2018? Obviously! Second command won\u2019t execute.<\/p>\n<pre>tecmint@localhost:~$ mkdir test || links tecmint.com<\/pre>\n<p>Here, the user creates a folder \u2018<strong>test<\/strong>\u2018 in his home directory, for which user is permitted. The command executed successfully giving an exit status \u2018<strong>0<\/strong>\u2018 and hence the last part of the command is not executed.<\/p>\n<h3>5. NOT Operator (!)<\/h3>\n<p>The\u00a0<strong>NOT Operator<\/strong>\u00a0(<strong>!<\/strong>) is much like an \u2018<strong>except<\/strong>\u2018 statement. This command will execute all except the condition provided. To understand this, create a directory \u2018<strong>tecmint<\/strong>\u2018 in your home directory and \u2018<strong>cd<\/strong>\u2018 to it.<\/p>\n<pre>tecmint@localhost:~$ mkdir tecmint \r\ntecmint@localhost:~$ cd tecmint<\/pre>\n<p>Next, create several types of files in the folder \u2018<strong>tecmint<\/strong>\u2018.<\/p>\n<pre>tecmint@localhost:~\/tecmint$ touch a.doc b.doc a.pdf b.pdf a.xml b.xml a.html b.html<\/pre>\n<p>See we\u2019ve created all the new files within the folder \u2018<strong>tecmint<\/strong>\u2018.<\/p>\n<pre>tecmint@localhost:~\/tecmint$ ls \r\n\r\na.doc  a.html  a.pdf  a.xml  b.doc  b.html  b.pdf  b.xml<\/pre>\n<p>Now delete all the files except \u2018<strong>html<\/strong>\u2018 file all at once, in a smart way.<\/p>\n<pre>tecmint@localhost:~\/tecmint$ rm -r !(*.html)<\/pre>\n<p>Just to verify, last execution. List all of the available files using\u00a0<a href=\"https:\/\/www.tecmint.com\/15-basic-ls-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">ls command<\/a>.<\/p>\n<pre>tecmint@localhost:~\/tecmint$ ls \r\n\r\na.html  b.html<\/pre>\n<h3>6. AND \u2013 OR operator (&amp;&amp; \u2013 ||)<\/h3>\n<p>The above operator is actually a combination of \u2018<strong>AND<\/strong>\u2018 and \u2018<strong>OR<\/strong>\u2018 Operator. It is much like an \u2018<strong>if-else<\/strong>\u2018 statement.<\/p>\n<p>For example, let\u2019s do ping to\u00a0<strong>tecmint.com<\/strong>, if success echo \u2018<strong>Verified<\/strong>\u2018 else echo \u2018<strong>Host Down<\/strong>\u2018.<\/p>\n<pre>tecmint@localhost:~\/tecmint$ ping -c3 www.tecmint.com &amp;&amp; echo \"Verified\" || echo \"Host Down\"<\/pre>\n<h5>Sample Output<\/h5>\n<pre>PING www.tecmint.com (212.71.234.61) 56(84) bytes of data. \r\n64 bytes from www.tecmint.com (212.71.234.61): icmp_req=1 ttl=55 time=216 ms \r\n64 bytes from www.tecmint.com (212.71.234.61): icmp_req=2 ttl=55 time=224 ms \r\n64 bytes from www.tecmint.com (212.71.234.61): icmp_req=3 ttl=55 time=226 ms \r\n\r\n--- www.tecmint.com ping statistics --- \r\n3 packets transmitted, 3 received, 0% packet loss, time 2001ms \r\nrtt min\/avg\/max\/mdev = 216.960\/222.789\/226.423\/4.199 ms \r\n<strong>Verified<\/strong><\/pre>\n<p>Now, disconnect your internet connection, and try same command again.<\/p>\n<pre>tecmint@localhost:~\/tecmint$ ping -c3 www.tecmint.com &amp;&amp; echo \"verified\" || echo \"Host Down\"<\/pre>\n<h5>Sample Output<\/h5>\n<pre>ping: unknown host www.tecmint.com \r\n<strong>Host Down<\/strong><\/pre>\n<h3>7. PIPE Operator (|)<\/h3>\n<p>This\u00a0<strong>PIPE<\/strong>\u00a0operator is very useful where the output of first command acts as an input to the second command. For example, pipeline the output of \u2018<strong>ls -l<\/strong>\u2018 to \u2018<strong>less<\/strong>\u2018 and see the output of the command.<\/p>\n<pre>tecmint@localhost:~$ ls -l | less<\/pre>\n<h3>8. Command Combination Operator {}<\/h3>\n<p>Combine two or more commands, the second command depends upon the execution of the first command.<\/p>\n<p>For example, check if a directory \u2018<strong>bin<\/strong>\u2018 is available or not, and output corresponding output.<\/p>\n<pre>tecmint@localhost:~$ [ -d bin ] || { echo Directory does not exist, creating directory now.; mkdir bin; } &amp;&amp; echo Directory exists.\r\n<\/pre>\n<h3>9. Precedence Operator ()<\/h3>\n<p>The Operator makes it possible to execute command in precedence order.<\/p>\n<pre>Command_x1 &amp;&amp;Command_x2 || Command_x3 &amp;&amp; Command_x4.<\/pre>\n<p>In the above pseudo command, what if the\u00a0<strong>Command_x1<\/strong>\u00a0fails? Neither of the\u00a0<strong>Command_x2<\/strong>,\u00a0<strong>Command_x3<\/strong>,\u00a0<strong>Command_x4<\/strong>\u00a0would executed, for this we use\u00a0<strong>Precedence Operator<\/strong>, as:<\/p>\n<pre>(Command_x1 &amp;&amp;Command_x2) || (Command_x3 &amp;&amp; Command_x4)<\/pre>\n<p>In the above pseudo command, if\u00a0<strong>Command_x1<\/strong>\u00a0fails,\u00a0<strong>Command_x2<\/strong>\u00a0also fails but Still\u00a0<strong>Command_x3<\/strong>\u00a0and\u00a0<strong>Command_x4<\/strong>\u00a0executes depends upon exit status of\u00a0<strong>Command_x3<\/strong>.<\/p>\n<h3>10. Concatenation Operator (\\)<\/h3>\n<p>The\u00a0<strong>Concatenation Operator<\/strong>\u00a0(<strong>\\<\/strong>) as the name specifies, is used to concatenate large commands over several lines in the shell. For example, The below command will open text file\u00a0<strong>test(1).txt<\/strong>.<\/p>\n<pre>tecmint@localhost:~\/Downloads$ nano test\\(1\\).txt<\/pre>\n<p>That\u2019s all for now. I am coming up with another interesting article very soon.<\/p>\n<h1 class=\"post-title\">rbash \u2013 A Restricted Bash Shell Explained with Practical Examples<\/h1>\n<p><strong>Linux Shell<\/strong>\u00a0is one of the most fascinating and powerful\u00a0<strong>GNU<\/strong>\/<strong>Linux<\/strong>\u00a0powered tool. All the application, including\u00a0<strong>X<\/strong>, is built over shell and Linux shell is so powerful that the whole Linux system can be controlled precisely, using it. The other aspect of Linux shell is that, it can be potentially harmful, when you executed a system command, without knowing its consequence or unknowingly.<\/p>\n<div id=\"attachment_5410\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/01\/Restricted-Bash-Shell1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-5410\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/01\/Restricted-Bash-Shell1-620x401.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/01\/Restricted-Bash-Shell1-620x401.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/01\/Restricted-Bash-Shell1.png 719w\" alt=\"Restrict Linux Commands\" width=\"620\" height=\"401\" aria-describedby=\"caption-attachment-5410\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-5410\" class=\"wp-caption-text\">Restricted Bash Shell<\/p>\n<\/div>\n<p>Being an ignorant user. For this purpose we are introducing restricted shell. We will be discussing restricted shell in details, the restrictions implemented, and a lot more.<\/p>\n<h3>What is rbash?<\/h3>\n<p>The\u00a0<strong>Restricted Shell<\/strong>\u00a0is a Linux Shell that restrict some of the features of bash shell, and is very clear from the name. The restriction is well implemented for the command as well as script running in restricted shell. It provides an additional layer for security to bash shell in Linux.<\/p>\n<h3>Restrictions Implemented in rbash<\/h3>\n<ol>\n<li>cd command (Change Directory)<\/li>\n<li>PATH (setting\/ unsetting)<\/li>\n<li>ENV aka BASH_ENV (Environment Setting\/ unsetting)<\/li>\n<li>Importing Function<\/li>\n<li>Specifying file name containing argument \u2018\/\u2019<\/li>\n<li>Specifying file name containing argument \u2018-\u2018<\/li>\n<li>Redirecting output using \u2018<strong>&gt;<\/strong>\u2018, \u2018<strong>&gt;&gt;<\/strong>\u2018, \u2018<strong>&gt;|<\/strong>\u2018, \u2018<strong>&lt;&gt;<\/strong>\u2018, \u2018<strong>&gt;&amp;<\/strong>\u2018, \u2018<strong>&amp;&gt;<\/strong>\u2018<\/li>\n<li>turning off restriction using \u2018<strong>set +r<\/strong>\u2018 or \u2018<strong>set +o<\/strong>\u2018<\/li>\n<\/ol>\n<p><strong>Note<\/strong>: Restrictions of rbash is enforced after any startup files are read.<\/p>\n<h3>Enabling Restricted Shell<\/h3>\n<p>&nbsp;<\/p>\n<p>In some version of\u00a0<strong>GNU<\/strong>\/<strong>Linux<\/strong>\u00a0viz.,\u00a0<strong>Red Hat<\/strong>\/<strong>CentOS<\/strong>, rbash may not be implemented directly and needs symbolic links to be created.<\/p>\n<pre># cd \/bin\r\n\r\n# ln -s bash rbash<\/pre>\n<p>In most of the today\u2019s\u00a0<strong>GNU<\/strong>\/<strong>Linux<\/strong>\u00a0standard distributions, rbash is available by default. If not, you can\u00a0<a href=\"ftp:\/\/ftp.cwru.edu\/pub\/bash\/bash-4.2.tar.gz\" target=\"_blank\" rel=\"nofollow noopener\">download source tarball<\/a>\u00a0and install it from source in your system.<\/p>\n<h4>Starting rbash<\/h4>\n<p>To start rbash restricted shell in Linux, execute the following command.<\/p>\n<pre># bash -r\r\n\r\nOR\r\n\r\n# rbash<\/pre>\n<p><strong>Note<\/strong>: If rbash is started successfully, it returns 0.<\/p>\n<h4>Testing a Few Restrictions<\/h4>\n<p>Here, we executing few commands on the rbash shell to check restrictions.<\/p>\n<pre># cd\r\n\r\n<strong>rbash: cd: restricted<\/strong><\/pre>\n<pre># pwd &gt; a.txt\r\n\r\n<strong>bash: a.txt: restricted: cannot redirect outpu<\/strong>t<\/pre>\n<h5>Pros of Restricted Shell<\/h5>\n<ol>\n<li>Restricted shell is used in conjunction with a chroot jail, in a further attempt to limit access to the system as a whole.<\/li>\n<\/ol>\n<h5>Cons of Restricted Shell<\/h5>\n<ol>\n<li>Insufficient to allow execution of entirely untrusted software.<\/li>\n<li>When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script.<\/li>\n<li>When users run bash or dash from rbash then they got unrestricted shells.<\/li>\n<li>rbash should only be used within a chroot unless you know what you are doing.<\/li>\n<li>There are many ways to break out a restricted bash shell that are not easy to predict in advance.<\/li>\n<\/ol>\n<h3>Conclusion<\/h3>\n<p>rbash is a fantastic tool to work on, within restricted environment and works brilliant. You must give it a try and you wont be disappointed.<\/p>\n<p>That\u2019s all for now. I\u2019ll soon be here again here with another interesting and knowledgeable topic you people would love to read. Don\u2019t forget to provide us with your valuable feedback in our comment section.<\/p>\n<h1 class=\"post-title\">Accessing Clipboard Contents Across Multiple Instances of Vim from Terminal<\/h1>\n<p><strong>Vim<\/strong>\u00a0(<strong>Vi IMproved<\/strong>) is one of the most favourite text editors among programmers. It has its own specialities in performing different operations with short hand commands.<\/p>\n<div id=\"attachment_5646\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/02\/vim-clipboard-content.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-5646\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/02\/vim-clipboard-content-620x402.jpeg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/02\/vim-clipboard-content-620x402.jpeg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/02\/vim-clipboard-content.jpeg 732w\" alt=\"Accessing Clipboard Contents from Vim\" width=\"620\" height=\"402\" aria-describedby=\"caption-attachment-5646\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-5646\" class=\"wp-caption-text\">Accessing Clipboard Contents from Vim<\/p>\n<\/div>\n<p>For example, to copy the highlighted text we use the \u2018<strong>y<\/strong>\u2018 command and \u2018<strong>x<\/strong>\u2018 to cut the same. But, by default\u00a0<strong>vim<\/strong>(and not<strong>\u00a0gVim<\/strong>) clipboard contents cannot be accessed after closing vim instances.<\/p>\n<p>Vim uses the \u2018<strong>+<\/strong>\u2018 register to refer to the system clipboard. You can run \u2018<strong>vim \u00ad\u00ad\u2013version<\/strong>\u2018 and if you cannot see something like \u201c<strong>+xterm_clipboard<\/strong>\u201d and instead \u201c\u00ad<strong>xterm_clipboard<\/strong>\u201c, then internal clipboard contents will not be available outside\u00a0<strong>vim<\/strong>.<\/p>\n<h4>Install gvim and parcellite<\/h4>\n<p>In order to access the vim clipboard contents, you need to install\u00a0<strong>gvim<\/strong>\u00a0package. The\u00a0<strong>gVim<\/strong>\u00a0is a GUI mode for vim editor where clipboard option is enabled by default.<\/p>\n<pre># yum install -y gvim<\/pre>\n<p>&nbsp;<\/p>\n<p>Next, enable\u00a0<a title=\"enable rpmforge in linux\" href=\"https:\/\/www.tecmint.com\/install-and-enable-rpmforge-repository-in-rhel-centos-6-5-4\/\" target=\"_blank\" rel=\"noopener\">RPMForge Repository<\/a>\u00a0to install\u00a0<strong>parcellite<\/strong>\u00a0package. The Parcellite is a lightweight, tiny and free clipboard manager for Linux.<\/p>\n<pre># yum install -y parcellite<\/pre>\n<p>Once installed, run the following command. Where argument \u2018<strong>&amp;<\/strong>\u2019 is used to send parcellite for running as a background process.<\/p>\n<pre># parcellite &amp;<\/pre>\n<p>Check whether the option is enabled in gvim.<\/p>\n<pre># gvim --version<\/pre>\n<p>Make sure you have the \u201c<strong>+xterm_clipboard<\/strong>\u201d option displayed in the output as shown below.<\/p>\n<pre>VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Apr  5 2012 10:12:08)\r\nIncluded patches: 1-411\r\nModified by &lt;bugzilla@redhat.com&gt;\r\nCompiled by &lt;bugzilla@redhat.com&gt;\r\nHuge version with GTK2 GUI.  Features included (+) or not (-):\r\n+arabic +autocmd +balloon_eval +browse ++builtin_terms +byte_offset +cindent \r\n+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments \r\n+cryptv +cscope +cursorshape +dialog_con_gui +diff +digraphs +dnd -ebcdic \r\n+emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path \r\n+float +folding -footer +fork() +gettext -hangul_input +iconv +insert_expand \r\n+jumplist +keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap \r\n+menu +mksession +modify_fname +mouse +mouseshape +mouse_dec +mouse_gpm \r\n-mouse_jsbterm +mouse_netterm -mouse_sysmouse +mouse_xterm +multi_byte \r\n+multi_lang -mzscheme +netbeans_intg -osfiletype +path_extra +perl +postscript \r\n+printer +profile +python +quickfix +reltime +rightleft -ruby +scrollbind \r\n+signs +smartindent -sniff +startuptime +statusline -sun_workshop +syntax \r\n+tag_binary +tag_old_static -tag_any_white -tcl +terminfo +termresponse \r\n+textobjects +title +toolbar +user_commands +vertsplit +virtualedit +visual \r\n+visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writebackup \r\n+X11 -xfontset +xim +xsmp_interact <strong>+xterm_clipboard<\/strong> -xterm_save<\/pre>\n<p>Open up user\u2019s .bashrc file.<\/p>\n<pre># vim ~\/.bashrc<\/pre>\n<p>And add the alias and save the file (press \u2018<strong>i<\/strong>\u2019 to insert line and press\u00a0<strong>ESC<\/strong>, then run\u00a0<strong>:wq<\/strong>\u00a0to save and exit).<\/p>\n<pre># .bashrc\r\n\r\n# User specific aliases and functions\r\n\r\nalias rm='rm -i'\r\nalias cp='cp -i'\r\nalias mv='mv -i'\r\n<strong>alias vim='gvim -v'<\/strong>\r\n# Source global definitions\r\nif [ -f \/etc\/bashrc ]; then\r\n        . \/etc\/bashrc\r\nfi<\/pre>\n<p>This alias is a built-in used to bypass some command to another. Thus every time when vim command is issued, the corresponding alias goes to gvim with clipboard enabled by default.<\/p>\n<p>Now edit your \u2018<strong>.vimrc<\/strong>\u2018 file in a similar way (In case if you don\u2019t have a\u00a0<strong>.vimrc<\/strong>\u00a0file, generate one such file through and then get back here.<\/p>\n<pre># vim ~\/.vimrc<\/pre>\n<p>Append the following line and save the file.<\/p>\n<pre>autocmd VimLeave * call system(\"echo -n $'\" . escape(getreg(), \"'\") . \"' | xsel -ib\")<\/pre>\n<p>Now open any file in vim and highlight the portion of text (using \u2018v\u2018 command) and press \u201c+y. Try to paste anywhere outside vim (after closing or without closing vim) and you are done.<\/p>\n<h4>Generating .vimrc File<\/h4>\n<p>Run the following command to generate\u00a0<strong>.vimrc<\/strong>\u00a0file (skip this part if you already have one).<\/p>\n<pre># cd   [This will put you in home directory]       \r\n# vim .vimrc<\/pre>\n<p>In vim run the following after pressing the ESC key (In vim every command is run after pressing ESC key which puts you in command mode).<\/p>\n<pre>:r $VIMRUNTIME\/vimrc_example.vim \r\n:w<\/pre>\n<h1 class=\"post-title\">Understanding and Writing functions in Shell Scripts \u2013 Part VI<\/h1>\n<p>Functions play an important role in any programming language. Like many real programming languages, bash has functions which are used with limited implementation.<\/p>\n<div id=\"attachment_5726\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/03\/Shell-Scripting-6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-5726\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/03\/Shell-Scripting-6.png\" alt=\"Shell Scripting Functions\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-5726\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-5726\" class=\"wp-caption-text\">Understanding Linux Shell Script Functions<\/p>\n<\/div>\n<h3>What are functions?<\/h3>\n<p>In programming, functions are named sections of a program that performs a specific task. In this sense, a function is a type of procedure or routine. When a function is called the program leaves the current section of code and begins to execute the first line inside the function. Whenever there is repetitive code or when a task repeats, consider using a function instead.<\/p>\n<p>For example, consider the case where we need to\u00a0find the factorial of a number at several stages of a particular program. Instead of writing the whole code (for calculating the factorial) each and every time, we can write that part of code which calculates the factorial once inside a block and reuse the same at multiple occasions.<\/p>\n<h4>Why do we write functions?<\/h4>\n<ol>\n<li>It helps us to reuse the code.<\/li>\n<li>Improve the readability of program.<\/li>\n<li>Efficient use of variables inside the program.<\/li>\n<li>Allows us to test the program part by part.<\/li>\n<li>Displays program\u00a0as a bunch of sub-steps.<\/li>\n<\/ol>\n<h5>Functions in shell scripts<\/h5>\n<p>The general syntax for writing functions in shell script includes the following ways.<\/p>\n<pre>function func_name {\r\n\t. . .\r\n\tcommands\r\n\t. . .\r\n}\r\n\r\nor\r\n\r\nfunc_name ( ) {\r\n\t. . .\r\n\tcommands\r\n\t. . .\r\n}\r\n\r\nOpening curly braces can also be used in the second line as well.\r\n\r\nfunc_name ( )\r\n{\r\n\t. . .\r\n\tcommands\r\n\t. . .\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>You are always free to write valid commands inside these function blocks as we do normally in shell scripts. Now let\u2019s try to write one simple script with a small function inside it.<\/p>\n<pre>#!\/bin\/bash\r\n\r\ncall_echo ( ) {\r\n\techo \u2018This is inside function\u2019\r\n}\r\n\r\nop=$1\r\n\r\nif [ $# -ne 1 ]; then\r\n\techo \"Usage: $0 &lt;1\/0&gt;\"\r\nelse\r\n\tif [ $1 = 0 ] ; then\r\n\t\techo \u2018This is outside function\u2019\r\n\telif [ $1 = 1 ] ; then\r\n\t\tcall_echo\r\n\telse\r\n\t\techo \u2018Invalid argument\u2019\r\n\tfi\r\nfi\r\n\r\nexit 0<\/pre>\n<p>The function definition must precede the first call to it. There is nothing like \u2018declaring the function\u2019 before calling it. And we can always nest functions inside functions.<\/p>\n<p><strong>Note<\/strong>:- Writing empty functions always results in syntax errors.<\/p>\n<p>When same function is defined multiple times, the final version is what is invoked. Let\u2019s take an example.<\/p>\n<pre>#!\/bin\/bash\r\n\r\nfunc_same ( ) {\r\n\techo \u2018First definition\u2019\r\n}\r\n\r\nfunc_same ( ) {\r\n\techo \u2018Second definition\u2019\r\n}\r\n\r\nfunc_same\r\n\r\nexit 0<\/pre>\n<h5>Functions taking parameters and returning values<\/h5>\n<p>Let\u2019s get deeper by considering functions taking parameters and returning values. To return a value from a function we use the \u2018return\u2019 shell built-in. Syntax is as follows.<\/p>\n<pre>func_name ( ) {\r\n\t. . .\r\n\tcommands\r\n\t. . .\r\n\treturn $ret_val\r\n}<\/pre>\n<p>Similarly we can pass arguments to the functions separated with spaces as given below.<\/p>\n<pre>func_name $arg_1 $arg_2 $arg_3<\/pre>\n<p>Inside the function we can access the arguments in order as $1, $2, $3 and so on. Look at the following example script to find the maximum of two integers using function to add more clarity.<\/p>\n<pre>#!\/bin\/bash\r\n\r\nUSG_ERR=7\r\n\r\nmax_two ( ) {\r\n\tif [ \"$1\" -eq \"$2\" ] ; then\r\n\t\techo 'Equal'\r\n\t\texit 0\r\n\telif [ \"$1\" -gt \"$2\" ] ; then\r\n\t\techo $1\r\n\telse\r\n\t\techo $2\r\n\tfi\r\n}\r\n\r\nerr_str ( ) {\r\n\techo \"Usage: $0 &lt;number1&gt;  &lt;number2&gt;\"\r\n\texit $USG_ERR\r\n}\r\n\r\nNUM_1=$1\r\nNUM_2=$2\r\nx\r\nif [ $# -ne 2 ] ; then\r\n\terr_str\r\nelif [ `expr $NUM_1 : '[0-9]*'` -eq ${#NUM_1} ] ; then\r\n\tif [ `expr $NUM_2 : '[0-9]*'` -eq ${#NUM_2} ] ; then  \r\n\t\tmax_two $NUM_1 $NUM_2\r\n\telse\r\n\t\terr_str\r\n\tfi\r\nelse\r\n\terr_str\r\nfi\r\n\r\nexit 0<\/pre>\n<p>The above looks like a bit complex, but it\u2019s simple if we read through the lines. First nested if-else if lines for validation purposes i.e., to check number and type of arguments with the help of regular expressions. After that we call the function with two command line arguments and displays the result there itself. This is because we cannot return large integers from a function. Another way to work around this problem is to use global variables to store the result inside function. The script below explains this method.<\/p>\n<pre>#!\/bin\/bash\r\n\r\nUSG_ERR=7\r\nret_val=\r\n\r\nmax_two ( ) {\r\n\tif [ \"$1\" -eq \"$2\" ] ; then\r\n\t\techo 'Equal'\r\n\t\texit 0\r\n\telif [ \"$1\" -gt \"$2\" ] ; then\r\n\t\tret_val=$1\r\n\telse\r\n\t\tret_val=$2\r\n\tfi\r\n}\r\n\r\nerr_str ( ) {\r\n\techo \"Usage: $0 &lt;number1&gt;  &lt;number2&gt;\"\r\n\texit $USG_ERR\r\n}\r\n\r\nNUM_1=$1\r\nNUM_2=$2\r\n\r\nif [ $# -ne 2 ] ; then\r\n\terr_str\r\nelif [ `expr $NUM_1 : '[0-9]*'` -eq ${#NUM_1} ] ; then\r\n\tif [ `expr $NUM_2 : '[0-9]*'` -eq ${#NUM_2} ] ; then  \r\n\t\tmax_two $NUM_1 $NUM_2\r\n\t\techo $ret_val\r\n\telse\r\n\t\terr_str\r\n\tfi\r\nelse\r\n\terr_str\r\nfi\r\n\r\nexit 0<\/pre>\n<p>Now try out some exciting problems that were explained in the previous shell scripting series using functions as follows.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/understand-linux-shell-and-basic-shell-scripting-language-tips\/\" target=\"_blank\" rel=\"noopener\">Understand Basic Linux Shell Scripting Language Tips \u2013 Part I<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/basic-shell-programming-part-ii\/\" target=\"_blank\" rel=\"noopener\">5 Shell Scripts for Linux Newbies to Learn Shell Programming \u2013 Part II<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/sailing-through-the-world-of-linux-bash-scripting-part-iii\/\" target=\"_blank\" rel=\"noopener\">Sailing Through The World of Linux BASH Scripting \u2013 Part III<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/mathematical-aspect-of-linux-shell-programming-part-iv\/\" target=\"_blank\" rel=\"noopener\">Mathematical Aspect of Linux Shell Programming \u2013 Part IV<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/calculating-mathematical-expressions-in-shell-scripting-part-v\/\" target=\"_blank\" rel=\"noopener\">Calculating Mathematical Expressions in Shell Scripting Language \u2013 Part V<\/a><\/li>\n<\/ol>\n<p>I will get back with more insight to functional features like using local variables, recursion etc in the next part. Stay updated with comments.<\/p>\n<h1 class=\"post-title\">Deeper into Function Complexities with Shell Scripting \u2013 Part VII<\/h1>\n<p>My previous article on \u201c<a href=\"https:\/\/www.tecmint.com\/understanding-and-writing-functions-in-shell-scripts-part-vi\/\" target=\"_blank\" rel=\"noopener\">Understanding and Writing functions in Shell Scripts<\/a>\u201d might have given you a basic idea on how to write functions under shell scripts. Now it is time to get deeper into functional features like the usage of local variables and recursion.<\/p>\n<div id=\"attachment_5889\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/03\/Shell-Scripting-7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-5889\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/03\/Shell-Scripting-7.png\" alt=\"Learn Linux Shell Scripting\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-5889\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-5889\" class=\"wp-caption-text\">Function Complexities with Shell Scripting<\/p>\n<\/div>\n<h4>Local Variables<\/h4>\n<p>What makes a variable local? It depends on that particular block where the variable is declared. A variable declared as\u00a0<em>local<\/em>\u00a0will be accessible from that block of code where it appears i.e. its scope is local. In order to explain this thing let\u2019s look into one example below.<\/p>\n<pre>#!\/bin\/bash \r\n\r\nfunc( ) { \r\n\tlocal i=10 \r\n\tj=20 \r\n\techo \"i from func = $i\" \r\n\techo \"j from func = $j\" \r\n} \r\n\r\necho \"i outside func = $i\" \r\necho \"j outside func = $j\" \r\n\r\nfunc \r\n\r\necho \"i outside func = $i\" \r\necho \"j outside func = $j\" \r\n\r\nexit 0<\/pre>\n<p>On executing the above script the output will be.<\/p>\n<pre>i outside func = \r\nj outside func = \r\ni from func = 10 \r\nj from func = 20 \r\ni outside func = \r\nj outside func = 20<\/pre>\n<p>This is because the function\u00a0<em>func<\/em>\u00a0has not yet called while the\u00a0<strong>first 2<\/strong>\u00a0echo statements were executed. After calling the function\u00a0<em>func<\/em>\u00a0the same\u00a0<strong>2 echo statements<\/strong>\u00a0produce a different result. Now the variable\u00a0<em>j<\/em>, which was declared inside\u00a0<em>func<\/em>\u00a0and not local, could be accessed afterwards.<\/p>\n<p>&nbsp;<\/p>\n<p>Thus value for\u00a0<em>j<\/em>\u00a0becomes\u00a0<strong>20<\/strong>. What about the local variable\u00a0<em>i<\/em>? Since its scope was inside the function\u00a0<em>func<\/em>, value\u00a0<strong>10<\/strong>\u00a0could not be accessed from outside. Note that the variable\u00a0<em>j<\/em>\u00a0normally declared inside\u00a0<em>func<\/em>\u00a0is global by default.<\/p>\n<p>Now you are familiar with local variables and how to use them inside function blocks. Let us move on to the most interesting section under functions, the recursion.<\/p>\n<h4>What is Recursion?<\/h4>\n<p>A function calling itself is generally termed as the recursion procedure. Or it can be defined as expressing an algorithm by using a simpler version of that same algorithm. Consider the example of finding factorial of a number. We know that\u00a0<strong>n! = 1 x 2 x 3 x \u2026 x (n-1) x n<\/strong>. Thus we can write a recurrence relation as:<\/p>\n<pre>n! = (n-1)! x n<\/pre>\n<p>So its easy for us to recursively call the same function and use the return value from each call to multiply with the previous result, i.e.<\/p>\n<pre>5! = 4! x 5\r\n4! = 3! x 4\r\n3! = 2! x 3\r\n2! = 1! x 2\r\n1! = 0! x 1<\/pre>\n<h4>Recursion using Local Variables<\/h4>\n<p>Here we try to write a script for finding factorial of a number using local variables and recursion.<\/p>\n<pre>#!\/bin\/bash \r\n\r\nfact( ) { \r\n\tlocal num=$1 \r\n\tif [ $num -eq 0 ]; then \r\n\t\tret=1 \r\n\telse \r\n\t\ttemp=$((num-1)) \r\n\t\tfact $temp \r\n\t\tret=$((num*$?)) \r\n\tfi \r\n\treturn $ret \r\n} \r\n\r\nfact 5 \r\n\r\necho \"Factorial of 5 = $?\" \r\n\r\nexit 0<\/pre>\n<p><em>num<\/em>\u00a0is a local variable used to store each\u00a0<strong>n-1<\/strong>\u00a0value on each call. Here the base condition checks whether the number is equal to zero or not (since 0! = 1 and factorial is not defined for negative numbers). On arriving this base condition it returns the value\u00a0<strong>1<\/strong>\u00a0to its caller. Now\u00a0<em>num = 1<\/em>\u00a0and\u00a0<em>ret = 1 x 1<\/em>.<\/p>\n<p>At this instant it returns\u00a0<strong>1<\/strong>\u00a0to its caller. Now\u00a0<em>num = 2<\/em>\u00a0and\u00a0<em>ret = 2 x 1<\/em>\u00a0and so on. Finally when\u00a0<em>num = 5<\/em>\u00a0return value will be\u00a0<strong>24<\/strong>\u00a0and final result is\u00a0<em>ret = 5 x 24<\/em>. The final result\u00a0<strong>120<\/strong>\u00a0is passed down to the initial caller statement and is displayed.<\/p>\n<p>There is one problem in the above script. As I explained in the previous article, functions cannot return large integers. So its left to users to find a solution for the above issue.<\/p>\n<p><strong>Q.<\/strong>\u00a0Can we perform recursion without using local variables? Answer is<strong>\u00a0Yes<\/strong>.<\/p>\n<h4>Recursion without Local Variables<\/h4>\n<p>Look at the following example for displaying the\u00a0<strong>Fibonacci series<\/strong>\u00a0using recursion. The basic recurrence relation is:<\/p>\n<pre>fib(0) = 0 \r\nfib(1) = 1 \r\nelse \r\n\tfib(n) = fib(n-1) + fib(n-2)\r\n\r\nFibonacci series using recursion\r\n\r\n#!\/bin\/bash \r\n\r\nfib( ) { \r\n\ta=$1 \r\n\tif [ $a -lt 2 ]; then \r\n\t\techo $a \r\n\telse \r\n\t\t((--a)) \r\n\t\tb=$(fib $a) \r\n\r\n\t\t((--a)) \r\n\t\tc=$(fib $a) \r\n\r\n\t\techo $((b+c)) \r\n\tfi \r\n} \r\n\r\nfor i in $(seq 0 15) \r\ndo \r\n\tout=$(fib $i) \r\n\techo $out \r\ndone \r\n\r\nexit 0<\/pre>\n<p>No local variables are used in the above script. I hope you can understand the flow of script during execution.<\/p>\n<p>Here the value\u00a0<strong>15<\/strong>\u00a0represents the number of terms in the\u00a0<strong>Fibonacci series<\/strong>\u00a0to be displayed. Did you notice anything special regarding the execution of above script. It takes a while, doesn\u2019t it? Recursion in a script is slower than a recursion in programming languages like\u00a0<strong>C<\/strong>.<\/p>\n<p>With this article, I plan to conclude the functions part in shell scripting. Stay updated with\u00a0the upcoming articles on\u00a0<strong>arrays<\/strong>\u00a0and much more\u2026<\/p>\n<h1 class=\"post-title\">Working with Arrays in Linux Shell Scripting \u2013 Part 8<\/h1>\n<p>We cannot imagine a programming language without the concept of arrays. It doesn\u2019t matter how they are implemented among various languages. Instead arrays help us in consolidating data, similar or different, under one symbolic name.<\/p>\n<div id=\"attachment_6539\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/04\/Working-With-Arrays-in-Shell-Scripting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-6539\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/04\/Working-With-Arrays-in-Shell-Scripting.png\" alt=\"Working With Arrays in Shell Scripting\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-6539\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-6539\" class=\"wp-caption-text\">Working With Arrays in Shell Scripting<\/p>\n<\/div>\n<p>Here as we are concerned about shell scripting, this article will help you in playing around with some shell scripts which make use of this concept of arrays.<\/p>\n<h3>Array Initialization and Usage<\/h3>\n<p>With newer versions of bash, it supports one-dimensional arrays. An array can be explicitly declared by the\u00a0<em>declare<\/em>\u00a0shell-builtin.<\/p>\n<pre>declare -a var  \r\n<\/pre>\n<p>But it is not necessary to declare array variables as above. We can insert individual elements to array directly as follows.<\/p>\n<pre>var[XX]=&lt;value&gt;\r\n<\/pre>\n<p>where \u2018XX\u2019 denotes the array index. To dereference array elements use the curly bracket syntax, i.e.<\/p>\n<pre>${var[XX]}\r\n<\/pre>\n<p><strong>Note<\/strong>: Array indexing always start with 0.<\/p>\n<p>Another convenient way of initializing an entire array is by using the pair of parenthesis as shown below.<\/p>\n<pre>var=( element1 element2 element3 . . . elementN )\r\n<\/pre>\n<p>There is yet another way of assigning values to arrays. This way of initialization is a sub-category of the previously explained method.<\/p>\n<pre>array=( [XX]=&lt;value&gt; [XX]=&lt;value&gt; . . . )\r\n<\/pre>\n<p>We can also read\/assign values to array during the execution time using the\u00a0<em>read<\/em>\u00a0shell-builtin.<\/p>\n<pre>read -a array\r\n<\/pre>\n<p>Now upon executing the above statement inside a script, it waits for some input. We need to provide the array elements separated by space (and not carriage return). After entering the values press enter to terminate.<\/p>\n<p>To traverse through the array elements we can also use for loop.<\/p>\n<pre>for i in \u201c${array[@]}\u201d\r\ndo\r\n\t#access each element as $i. . .\r\ndone \r\n<\/pre>\n<p>The following script summarizes the contents of this particular section.<\/p>\n<pre>#!\/bin\/bash \r\n\r\narray1[0]=one \r\narray1[1]=1 \r\necho ${array1[0]} \r\necho ${array1[1]} \r\n\r\narray2=( one two three ) \r\necho ${array2[0]} \r\necho ${array2[2]} \r\n\r\narray3=( [9]=nine [11]=11 ) \r\necho ${array3[9]} \r\necho ${array3[11]} \r\n\r\nread -a array4 \r\nfor i in \"${array4[@]}\" \r\ndo \r\n\techo $i \r\ndone \r\n\r\nexit 0\r\n<\/pre>\n<h4>Various Operations on Arrays<\/h4>\n<p>Many of the standard string operations work on arrays . Look at the following sample script which implements some operations on arrays (including string operations).<\/p>\n<pre>#!\/bin\/bash \r\n\r\narray=( apple bat cat dog elephant frog ) \r\n\r\n#print first element \r\necho ${array[0]} \r\necho ${array:0} \r\n\r\n#display all elements \r\necho ${array[@]} \r\necho ${array[@]:0} \r\n\r\n#display all elements except first one \r\necho ${array[@]:1} \r\n\r\n#display elements in a range \r\necho ${array[@]:1:4} \r\n\r\n#length of first element \r\necho ${#array[0]} \r\necho ${#array} \r\n\r\n#number of elements \r\necho ${#array[*]} \r\necho ${#array[@]} \r\n\r\n#replacing substring \r\necho ${array[@]\/\/a\/A} \r\n\r\nexit 0\r\n<\/pre>\n<p>Following is the output produced on executing the above script.<\/p>\n<pre>apple \r\napple \r\napple bat cat dog elephant frog \r\napple bat cat dog elephant frog \r\nbat cat dog elephant frog \r\nbat cat dog elephant \r\n5 \r\n5 \r\n6 \r\n6 \r\nApple bAt cAt dog elephAnt frog\r\n<\/pre>\n<p>I think there is no significance in explaining the above script in detail as it is self-explanatory. If necessary I will dedicate one part in this series exclusively on string manipulations.<\/p>\n<h4>Command Substitution with Arrays<\/h4>\n<p>Command substitution assigns the output of a command or multiple commands into another context. Here in this context of arrays we can insert the output of commands as individual elements of arrays. Syntax is as follows.<\/p>\n<pre>array=( $(command) )\r\n<\/pre>\n<p>By default the contents in the output of command separated by white spaces are plugged into array as individual elements. The following script list the contents of a directory, which are files with 755 permissions.<\/p>\n<pre>#!\/bin\/bash \r\n\r\nERR=27 \r\nEXT=0 \r\n\r\nif [ $# -ne 1 ]; then \r\n\techo \"Usage: $0 &lt;path&gt;\" \r\n\texit $ERR \r\nfi \r\n\r\nif [ ! -d $1 ]; then \r\n\techo \"Directory $1 doesn't exists\" \r\n\texit $ERR \r\nfi \r\n\r\ntemp=( $(find $1 -maxdepth 1 -type f) ) \r\n\r\nfor i in \"${temp[@]}\" \r\ndo \r\n\tperm=$(ls -l $i) \r\n\tif [ `expr ${perm:0:10} : \"-rwxr-xr-x\"` -eq 10 ]; then \r\n\t\techo ${i##*\/} \r\n\tfi \r\ndone \r\n\r\nexit $EXT\r\n<\/pre>\n<h4>Simulating Two-dimensional Arrays<\/h4>\n<p>We can easily represent a 2-dimensional matrix using a 1-dimensional array. In\u00a0<em>row major order<\/em>\u00a0representation elements in each row of a matrix are progressively stored in array indexes in a sequential manner. For an mXn matrix, formula for the same can be written as.<\/p>\n<pre>matrix[i][j]=array[n*i+j]\r\n<\/pre>\n<p>Look at another sample script for adding 2 matrices and printing the resultant matrix.<\/p>\n<pre>#!\/bin\/bash \r\n\r\nread -p \"Enter the matrix order [mxn] : \" t \r\nm=${t:0:1} \r\nn=${t:2:1} \r\n\r\necho \"Enter the elements for first matrix\" \r\nfor i in `seq 0 $(($m-1))` \r\ndo \r\n\tfor j in `seq 0 $(($n-1))` \r\n\tdo \r\n\t\tread x[$(($n*$i+$j))] \r\n\tdone \r\ndone \r\n\r\necho \"Enter the elements for second matrix\" \r\nfor i in `seq 0 $(($m-1))` \r\ndo \r\n\tfor j in `seq 0 $(($n-1))` \r\n\tdo \r\n\t\tread y[$(($n*$i+$j))] \r\n\t\tz[$(($n*$i+$j))]=$((${x[$(($n*$i+$j))]}+${y[$(($n*$i+$j))]})) \r\n\tdone \r\ndone \r\n\r\necho \"Matrix after addition is\" \r\nfor i in `seq 0 $(($m-1))` \r\ndo \r\n\tfor j in `seq 0 $(($n-1))` \r\n\tdo \r\n\t\techo -ne \"${z[$(($n*$i+$j))]}\\t\" \r\n\tdone \r\n\techo -e \"\\n\" \r\ndone \r\n\r\nexit 0 \r\n<\/pre>\n<p>Even though there are limitations for implementing arrays inside shell scripting, it becomes useful in a handful of situations, especially when we handle with command substitution. Looking from an administrative point of view, the concept of arrays paved the way for development of many background scripts in GNU\/Linux systems.<\/p>\n<h1 class=\"post-title\">An Insight of Linux \u201cVariables\u201d in Shell Scripting Language \u2013 Part 9<\/h1>\n<p>We already have written a series of articles on\u00a0<strong>Linux Shell Scripting<\/strong>\u00a0which was warm welcomed that time and it was much relevant even now. Here is the link to the collection of articles on shell scripting.<\/p>\n<ol>\n<li><a target=\"_blank\">Learn Linux Shell Scripting<\/a><\/li>\n<\/ol>\n<p>Here in this article we will see the\u00a0<strong>variables<\/strong>, its execution and its implementation in shell script.<\/p>\n<div id=\"attachment_6996\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/05\/Linux-Variables-Shell-Scripting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-6996\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/05\/Linux-Variables-Shell-Scripting.png\" alt=\"Linux Variables Shell Scripting\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-6996\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-6996\" class=\"wp-caption-text\">Linux Variables Shell Scripting<\/p>\n<\/div>\n<h4>Saving an Output<\/h4>\n<p>The output of a command can be redirected to standard output or a file and can be stored in a variable, as well. If the output of a command is large enough such that it does not fit the screen we are left only with the option of saving output to a file to in a variable. One advantage of saving output to variable is faster examination speed. Variables are saved into memory and hence it tends to be fast as compared to retrieval from file.<\/p>\n<h4>Variables in scripting Language<\/h4>\n<p>Variables are an important component used in Shell scripting and are declared using bash command \u201c<strong>Declare<\/strong>\u201d. To declare a variable say \u2018<strong>level<\/strong>\u2018, we need to execute the below command.<\/p>\n<pre>$ declare LEVEL<\/pre>\n<p><strong>Note<\/strong>: We need to use \u201c<strong>typecast<\/strong>\u201d, a built in statement for korn shell compatibility. The \u2018declare\u2019 is more advanced and contains all the features, hence is recommended when using BASH.<\/p>\n<h5>Rules<\/h5>\n<ol>\n<li>A variable name must justify, the use of variable in the script.<\/li>\n<li>Using the same variable name throughout the program is strongly advised.<\/li>\n<li>Variables name can be uppercase as well as lowercase but by convention shell commands are in lowercase and hence we should use variables name in uppercase, so as to remove any confusion. e.g., TOTAL_BILLED_AMOUNT, SELL_REPORT, ORDER_RECEIPT, etc.<\/li>\n<\/ol>\n<h4>Implementation<\/h4>\n<p>A variable can be assigned a value using an equal sign (<strong>=<\/strong>). To assign an empty string to a variable we must not supply any value after equal sign.<\/p>\n<pre>$ LEVEL =<\/pre>\n<p>Check the value stored in variable \u2018LEVEL\u2019 as.<\/p>\n<pre>$ printf \"%i\" $LEVEL<\/pre>\n<p><strong>printf<\/strong>, the command most of \u2018<strong>C<\/strong>\u2018 programmers are aware of, prints data.<strong>\u00a0%i<\/strong>\u00a0\u2013 Represents Integer. We can replace it with\u00a0<strong>%c<\/strong>\u00a0for Character or\u00a0<strong>%c<\/strong>\u00a0for string, as and when required.<\/p>\n<p>$LEVEL: Note the \u2018<strong>$<\/strong>\u2018 which works as value substituter for the variable \u2018<strong>LEVEL\u2019<\/strong>.<\/p>\n<h5>Sample Output<\/h5>\n<pre>$ printf \"%i\" $LEVEL\r\n0<\/pre>\n<p>Assign a value to the variable.<\/p>\n<pre>$ LEVEL=0<\/pre>\n<p>Check the stored data in variable.<\/p>\n<pre>$ printf \"%i\" $LEVEL\r\n0<\/pre>\n<p><strong>NOTE<\/strong>: It is interesting to note that in both the cases, when we didn\u2019t assigned the value to variable and when we assigned the value \u2018<strong>0<\/strong>\u2018 to the variable \u2018<strong>LEVEL<\/strong>\u2018 outputs\u00a0<strong>0<\/strong>. Although the output are same in both the cases but shell script handles both the variable declaration differently.<\/p>\n<p>Assign a new value to the variable.<\/p>\n<pre>$ LEVEL=121<\/pre>\n<p>Check the stored data in variable.<\/p>\n<pre>$ printf \"%i\" $LEVEL\r\n121<\/pre>\n<h4>Unset a Variable<\/h4>\n<p><strong>Declare<\/strong>\u00a0is a BASH command and it creates variable only when executed. The variable so created remains in memory till the script stops or the variable is destroyed.<\/p>\n<pre>$ unset LEVEL<\/pre>\n<h4>Predefined Variables in BASH<\/h4>\n<p>BASH has over\u00a0<strong>50<\/strong>\u00a0variables predefined. Some of these variables has a special meaning attached to BASH e.g., a variable\u00a0<strong>RANDOM<\/strong>\u00a0outputs a random number. If it is unset and then defined again, the original variable value is lost forever. Hence it is advised not to use any system defined variable.<\/p>\n<p>Here is a list of some useful BASH variables.<\/p>\n<ol>\n<li>BASH\u2014The full pathname of Bash.<\/li>\n<li>BASH_ENV\u2014In a shell script, the name of the profile file executed before the script was started.<\/li>\n<li>BASH_VERSION\u2014The version of Bash (for example, 2.04.0(1)-release).<\/li>\n<li>COLUMNS\u2014The number of characters per line on your display (for example, 80).<\/li>\n<li>HOSTNAME\u2014The name of the computer. Under some versions of Linux, this can be the machine name. On others, it can be a fully qualified domain name.<\/li>\n<li>HOSTTYPE\u2014Type of computer.<\/li>\n<li>HOME\u2014The name of your home directory.<\/li>\n<li>OSTYPE\u2014The name of the operating system.<\/li>\n<li>PATH\u2014Colon-separated list of search paths to find a command to execute.<\/li>\n<li>PPID\u2014The process ID of the shell\u2019s parent process.<\/li>\n<li>PROMPT_COMMAND\u2014Command to execute before the setting of the PS1 primary prompt string.<\/li>\n<li>PWD\u2014The current working directory (as set by the cd command).<\/li>\n<li>RANDOM\u2014Returns a random number between 0 and 32767 each time it is referenced.<\/li>\n<li>SHELL\u2014The preferred shell to use; for programs that start a shell for you.<\/li>\n<li>TERM\u2014The terminal emulation type (for example, console).<\/li>\n<\/ol>\n<p>The Rule of Word Splitting.<\/p>\n<pre>$ LEVEL=0\r\n$ printf \"%i\" $LEVEL\r\n0\r\n\r\nAND\r\n\r\n$ LEVEL=\u201d0\u201d\r\n$ printf \"%i\" $LEVEL\r\n0<\/pre>\n<p>In both the cases output remains same. So what\u2019s the difference in result while using quotation?<\/p>\n<p>Lets check the same with different variable data.<\/p>\n<pre>$ LEVEL=0 ; 1 ; 2 ; 3 ; 4 ; 5\r\nbash: 1: command not found \r\nbash: 2: command not found \r\nbash: 3: command not found \r\nbash: 4: command not found \r\nbash: 5: command not found<\/pre>\n<pre>$ printf \"%i\" $LEVEL\r\n0<\/pre>\n<p>Not to mention, the output is not correct. BASH is taking the space after \u2018<strong>0<\/strong>\u2018 as termination and hence the value of variable is set as \u2018<strong>0<\/strong>\u2018. Now we try to use quotation for variables as below.<\/p>\n<pre>$ LEVEL=\u201d0 ; 1 ; 2 ; 3 ; 4 ; 5\u201d\r\n$ printf \"%s\" $LEVEL \r\n0;1;2;3;4;5<\/pre>\n<p>Still the result is not correct. BASH took the variable values and removed all the spaces in between them. Hence\u00a0<strong>printf<\/strong>\u00a0didn\u2019t interpreted 0,1,2,3,4,5 as distinct values. So what\u2019s the solution?<\/p>\n<pre>printf \"%s\" \"$LEVEL\" \r\n0 ; 1 ; 2 ; 3 ; 4 ; 5<\/pre>\n<p>Yeah! Putting the Variable substitution under quotes is the solution. Quotations groups characters in shell and interpret the special characters in a meaningful way.<\/p>\n<p>Quotations can be used back-to-back and it is a good idea to enclose variable substitutions with quotes. Moreover it can be used to separate overall text from quotations. Here is an example.<\/p>\n<pre>$ LEVEL=5 \r\n$ FLAG_MESSAGE=\"I HAVE CLEARED LEVEL\"\"$LEVEL\"\". I Deserve appreciation.\" \r\n$ printf \u201c%s\u201d \u201c$FLAG_MESSAGE\u201d<\/pre>\n<pre>\u201cI HAVE CLEARED LEVEL5. I Deserve appreciation.\u201d<\/pre>\n<p>Separating chunks of quoted text with space will result into the same problem as discussed above. The bash will treat white space as termination. Another way of variable substitution is.<\/p>\n<pre>$ LEVEL=5\r\n\r\n$ FLAG_MESSAGE=\"I HAVE CLEARED LEVEL ${LEVEL}. I Deserve appreciation.\" \r\n\r\n$ printf \u201c%s\u201d \"$FLAG_MESSAGE\" \r\n\u201cI HAVE CLEARED LEVEL 5. I Deserve appreciation.\u201d<\/pre>\n<p>Single quotes restricts BASH from printing Special characters.<\/p>\n<pre>$ printf \u201c%s\u201d '$FLAG_MESSAGE'\r\n\u201c$FLAG_MESSAGE\u201d<\/pre>\n<h4>The Backslash (\/)<\/h4>\n<p>Backslash works like single quote for one character. Have you thought how will you print (<strong>\u201c<\/strong>)?<\/p>\n<pre>$ printf \"%c\" \"\\\"\"<\/pre>\n<p>When\u00a0<strong>%q<\/strong>\u00a0grouped with\u00a0<strong>printf<\/strong>, provides backslash after every word to ensure word spacing.<\/p>\n<pre>$ LEVEL=5\r\n\r\n$ FLAG_MESSAGE=\"I HAVE CLEARED LEVEL ${LEVEL}. I Deserve appreciation.\" \r\n\r\n$ printf \u201c%q\u201d \"$FLAG_MESSAGE\" \r\n\u201cI\\ HAVE\\ CLEARED\\ LEVEL\\ 5.\\ I\\ Deserve\\ appreciation.\u201d<\/pre>\n<p>That\u2019s all for now. We always try to provide our readers with articles that are useful for them every now and then. The above covered article is vast hence rest of the topics with examples will be produced in the next article which will include \u2018Attributes of variable\u2019, \u2018Variable exporting\u2019 etc.<\/p>\n<h1 class=\"post-title\">Understanding and Writing \u2018Linux Variables\u2019 in Shell Scripting \u2013 Part 10<\/h1>\n<p>The Linux shell scripting language has always been a hot topic and will always be in the future. The Shell Scripting Language is magical and its so easy to do a program in scripting language as in any other Language. However, it needs an in-depth knowledge of what we are doing and what the result is expected.<\/p>\n<div id=\"attachment_7364\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/06\/Understanding-Variables-in-Shell-Scripting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7364\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/06\/Understanding-Variables-in-Shell-Scripting.png\" alt=\"Understanding Variables in Shell Scripting\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-7364\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-7364\" class=\"wp-caption-text\">Understanding Variables in Shell Scripting<\/p>\n<\/div>\n<p>All the shell scripting articles we have written for our readers are highly appreciated including the last one \u201c<a href=\"https:\/\/www.tecmint.com\/an-insight-of-linux-variables-in-shell-scripting\/\" target=\"_blank\" rel=\"noopener\">An Insight of Linux Variables<\/a>\u201d. We are extending the last article to a new Level.<\/p>\n<h3>Variable Attributes<\/h3>\n<p>Each Variable in Linux Environment has certain options, and those are called \u2018attributes\u2019. These options or attributes can be turned\u00a0<b>On<\/b>\u00a0and\u00a0<b>Off<\/b>, when required according to the situation using a command \u201cdeclare\u201d.<\/p>\n<p>An Example of variable attribute is using a switch say \u2018<b>-i<\/b>\u2018 which will turn on the integer attribute for the corresponding variable. Even if a non-numeric value is passed to switch \u2018<b>-i<\/b>\u2018 it won\u2019t throw an error message and output \u2018<b>0<\/b>\u2018 as integer interpretation. Here it becomes more clear from the example below.<\/p>\n<p>Declare a variable Integer, bill = 121<\/p>\n<pre>avi@localhost:~$ declare -i bill=121<\/pre>\n<p>Printf the value of variable bill.<\/p>\n<pre>avi@localhost:~$ printf \"%d\\n\" \"$bill\" \r\n\r\n121<\/pre>\n<p>Let the variable value be a string. The variable bill is already declared, no need to declare it second time. Just change the value of variable as.<\/p>\n<pre>avi@localhost:~$ bill=tecmint<\/pre>\n<p>Now, again printf the value of variable bill.<\/p>\n<pre>avi@localhost:~$ printf \"%d\\n\" \"$bill\" \r\n\r\n0<\/pre>\n<p>Notice \u2018<b>0<\/b>\u2018 in the place of error message.<\/p>\n<h6>Now, the question is, how to know the attributes of already declared variables?<\/h6>\n<pre>avi@localhost:~$ declare -p bill \r\n\r\ndeclare -i bill=\"121\"<\/pre>\n<p>Here, a\u00a0<b>-p<\/b>\u00a0(stands for print) switch comes to rescue.<\/p>\n<h6>Again, what should I do to switch off the attributes of a variable?<\/h6>\n<p>In order to switch\u00a0<b>Off<\/b>\u00a0the attributes of a variable what we need all is to put a\u00a0<b>+<\/b>\u00a0(<b>plus<\/b>) sign just before the switch. Here it is more clear from the example below.<\/p>\n<p>Switch\u00a0<b>Off<\/b>\u00a0the integer attribute for the above variable.<\/p>\n<pre>avi@localhost:~$ declare +i bill<\/pre>\n<p>Check the value of the variable.<\/p>\n<pre>avi@localhost:~$ printf \"%d\\n\" \"$bill\" \r\n\r\nbash: printf: bill: invalid number\r\n0<\/pre>\n<p>Now print the value of variable using switch string.<\/p>\n<pre>avi@localhost:~$ printf \"%s\\n\" \"$bill\" \r\n\r\ntecmint<\/pre>\n<p>Here in the above example, bash could not judge non-numeric value as error, however\u00a0<b>printf<\/b>\u00a0is interpreting, what could be a number and what could not be.<\/p>\n<h3>Read-only Variables<\/h3>\n<p>You might have heard Read Only Memory (<b>ROM<\/b>), but what is Read-only Variable? Has it any similarity with ROM?<\/p>\n<p>Well Read-only Variables like Read-only Memory is something the value of which can\u2019t be change once it is assigned. Hence it is called Read-only. You can\u2019t write, edit or modify a new value for that variable. Here is an illustration using example.<\/p>\n<p>Decalre a read only (<b>-r<\/b>) variable name, the value of which is \u201cTecmint.com\u201d.<\/p>\n<pre>avi@localhost:~$ declare -r name=\"Tecmint.com\"<\/pre>\n<p>Printf the value of above declared variable.<\/p>\n<pre>avi@localhost:~$ printf \"%s\\n\" \"$name\" \r\n\r\nTecmint.com<\/pre>\n<p>Try to change the value of variable.<\/p>\n<pre>avi@localhost:~$ declare -r name=\"Avishek\" \r\n\r\nbash: declare: name: readonly variable<\/pre>\n<p>As discussed above the attributes of a read-only Variable can be changed using \u2018<b>+<\/b>\u2018 sign.<\/p>\n<h3>Exporting Variables in Linux<\/h3>\n<p>All the shell variables declared in a shell script are available till the script is running. Outside of the script the variable from the script does not exist. The process of making variables available outside of the script is called exporting variables.<\/p>\n<p>A Variable can be exported outside of the shell using switch\u00a0<b>declare -x<\/b>\u00a0(export), which acknowledge the shell what you wanted to export. A declare export switch can be used as.<\/p>\n<pre>avi@localhost:~$ declare -x variable=\u201dConstant_Value\u201d<\/pre>\n<p>All the changes made to the variable while the script is running, is lost when the variable is exported outside of the script. Exporting variable is very important in shell scripting.<\/p>\n<p>We want to have a variable that should be read-only and available outside of the script, we need to use switch\u00a0<b>-r<\/b>and switch\u00a0<b>-x<\/b>\u00a0at the same time.<\/p>\n<pre>avi@localhost:~$ declare -rx variable=\u201dConstant_Value\u201d<\/pre>\n<h3>Environment Variables<\/h3>\n<p>The variables that are shared between the program and the program that execute them. Environment variables can be exported but the attributes can\u2019t be assigned to it.<\/p>\n<p>Understanding the above theory practically. Here we have two scripts\u00a0<b>0.sh<\/b>\u00a0and\u00a0<b>1.sh<\/b>.<\/p>\n<pre># 0.sh\r\n#!\/bin\/bash \r\ndeclare -rx name=Tecmint \r\nbash 0.sh \r\nexit 0<\/pre>\n<p>And the second script is.<\/p>\n<pre># 1.sh\r\n#!\/bin\/bash \r\nprintf \"%s\\n\" \"$name\" \r\nname=Tecmint.com \r\nprintf \"%s\\n\" \"$name\"\r\nexit 0<\/pre>\n<p>Here what is going on, is a variable (name) is declared as read only and exported and immediately after that second script is called.<\/p>\n<p>The second script just printed the variable from the first script that was exported in the first\u00a0<b>printf<\/b>\u00a0statement. In the second printf statement it shows the new value assigned to variable \u2018<b>name<\/b>\u2018.<\/p>\n<p>No need to worry, that the variable was read-only, how can it be reassigned. Don\u2019t you remember that \u201cAll the changes made to the variable while the script is running, is lost when the variable is exported outside of the script.\u201d<\/p>\n<h5>References<\/h5>\n<p>The\u00a0<b>declare<\/b>\u00a0command allows all the switches below along with their combination.<\/p>\n<ol>\n<li><b>-a<\/b>\u00a0: Declares an array.<\/li>\n<li><b>-f<\/b>\u00a0: Display Function and Definition.<\/li>\n<li><b>-F<\/b>\u00a0: Display Function Name.<\/li>\n<li><b>-r<\/b>\u00a0: Declare variable as read-only.<\/li>\n<li><b>-x<\/b>\u00a0: Declare Variable as Exportable.<\/li>\n<li><b>-I<\/b>\u00a0: Declare variable as Integer.<\/li>\n<\/ol>\n<p>That\u2019s all for now. In the very next article we will be discussing ways to substitute variables using \u2018<b>eval<\/b>\u2018 command and the variables already defined in bash before closing this topic.<\/p>\n<h1 class=\"post-title\">Nested Variable Substitution and Predefined BASH Variables in Linux \u2013 Part 11<\/h1>\n<p>The last two article on BASH Shell, where we discussed variables in detail were highly appreciated among our readers. We as\u00a0<strong>Tecmint-Team<\/strong>\u00a0are very keen to provide you with Latest, Up-to-date and relevant topics covered in details. Moreover we always try to touch major perspectives of the corresponding topics.<\/p>\n<div id=\"attachment_7540\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/06\/Nested-Variables-in-Shell-Scripting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7540\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/06\/Nested-Variables-in-Shell-Scripting.png\" alt=\"Nested Variables in Shell Scripting\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-7540\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-7540\" class=\"wp-caption-text\">Nested Variables in Shell Scripting<\/p>\n<\/div>\n<p>Here is the last article on Linux Variables where we are going to see variables substitution and variables defined in Shell before closing this topic.<\/p>\n<p>Bash performs variable substitution before the command is really executed. The Linux Bash Shell searches for all the \u2018$\u2019 sign before executing the command and replace it with the value of variable. The process of Bash Variable substitution is performed only once. What if we have nested variables?<\/p>\n<p><strong>Note<\/strong>: By nested variable we mean, variable declared inside variable. Lets see the above scenario in the example below.<\/p>\n<p>Declare a variable which is Read-Only and Executable as below.<\/p>\n<pre>avi@localhost:~$ declare -rx Linux_best_website=\"www.tecmint.com\"<\/pre>\n<p>Check the value of variable stored.<\/p>\n<pre>avi@localhost:~$ printf \"%s\" \"$Linux_best_website\" \r\n\r\nwww.tecmint.com<\/pre>\n<p>Now declare another variable which again is Read-Only and Executable.<\/p>\n<pre>avi@localhost:~$ declare -rx Linux_website=\"Linux_best_website\"<\/pre>\n<p>Now the situation is, we have defined two variables.<\/p>\n<p>\u2018Linux_best_website\u2019, the value of which is \u201cwww.tecmint.com\u201d<br \/>\nand, \u2018Linux_website\u2019, the value of which is \u201cLinux_best_website\u201d<\/p>\n<p>What would be the result, if we run the below one-line command?<\/p>\n<pre>avi@localhost:~$ printf \"%s\" \"$Linux_website\"<\/pre>\n<p>It should first replace the variable \u2018<b>$Linux_website<\/b>\u2018, with value \u201c<b>Linux_best_website<\/b>\u201d and then \u201c<b>$Linux_best_website<\/b>\u201d is again a variable the value of which is \u201c<b>www.tecmint.com<\/b>\u201d. So the final output of running the below command should be.<\/p>\n<pre>avi@localhost:~$ printf \"%s\" \"$Linux_website\" \r\n\r\nwww.tecmint.com<\/pre>\n<p>But unfortunately, this is not the situation, the output we are getting is\u00a0<b>Linux_best_website<\/b>.<\/p>\n<p>Reason? Yup! Bash substitute the value of variable only once. What about complex scripts and programs where we need to substitute variables frequently as well as needs to substitute the variable more than once?<\/p>\n<p>Here comes the command \u2018<b>eval<\/b>\u2018 which performs additional work of variable substitution more than once in a script. Here is an example to make the whole working as clear as glass.<\/p>\n<p>Declare a variable\u00a0<b>x<\/b>, the value of which is\u00a0<b>10<\/b>.<\/p>\n<pre>avi@localhost:~\/Desktop$ declare x=10<\/pre>\n<p>Check the value of variable\u00a0<b>x<\/b>, we just defined.<\/p>\n<pre>avi@localhost:~\/Desktop$ echo $yx\r\n\r\nx10<\/pre>\n<p>Declare a variable\u00a0<b>y<\/b>, the value of which is\u00a0<b>x<\/b>.<\/p>\n<pre>avi@localhost:~\/Desktop$ declare y=x<\/pre>\n<p>Check the value of variable\u00a0<b>y<\/b>, we just defined.<\/p>\n<pre>avi@localhost:~\/Desktop$ echo $y \r\n\r\nx<\/pre>\n<p>Here is the problem of\u00a0<b>BASH<\/b>\u00a0one time variable substitution, which don\u2019t performs an extra round of variable substitution. We are using \u2018<b>eval<\/b>\u2018 command to fix this.<\/p>\n<pre>avi@localhost:~\/Desktop$ eval y=$x<\/pre>\n<p>Now check the Value of variable \u2018<b>y<\/b>\u2018.<\/p>\n<pre>avi@localhost:~\/Desktop$ echo $y \r\n\r\n10<\/pre>\n<p>Hurrah! The issue was fixed and \u2018<strong>eval<\/strong>\u2018 command won the race \ud83d\ude42<\/p>\n<p>Not to mention, \u2018<b>eval<\/b>\u2018 command is very helpful in large script programs and is a very handy tool.<\/p>\n<p>The last but not the least part of this post is BASH predefined variables. No! Don\u2019t get panic seeing this list. You never need to remember the whole list before you start writing scripts except a few. As a part of learning process, we are presenting the BASH predefined variable List.<\/p>\n<table border=\"0\" cellspacing=\"0\">\n<tbody>\n<tr>\n<td align=\"LEFT\" height=\"19\"><strong>No.<\/strong><\/td>\n<td align=\"LEFT\"><strong>BASH VARIABLE<\/strong><\/td>\n<td align=\"LEFT\"><strong>RESULT<\/strong><\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">1<\/td>\n<td align=\"LEFT\">auto_resume<\/td>\n<td align=\"LEFT\">Process command completion for the stopped jobs.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">2<\/td>\n<td align=\"LEFT\">BASH<\/td>\n<td align=\"LEFT\">PATH of the shell.<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">3<\/td>\n<td align=\"LEFT\">BASH_ENV<\/td>\n<td align=\"LEFT\">Shows the name of the profile file<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">4<\/td>\n<td align=\"LEFT\">BASH_VERSION<\/td>\n<td align=\"LEFT\">Shows the version of Bash<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">5<\/td>\n<td align=\"LEFT\">BASH_VERSINFO<\/td>\n<td align=\"LEFT\">Shows Detailed version information.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">6<\/td>\n<td align=\"LEFT\">BASH_VERSINFO[0]<\/td>\n<td align=\"LEFT\">The major version number (the release).<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">7<\/td>\n<td align=\"LEFT\">BASH_VERSINFO[1]<\/td>\n<td align=\"LEFT\">The minor version number (the version).<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">8<\/td>\n<td align=\"LEFT\">BASH_VERSINFO[2]<\/td>\n<td align=\"LEFT\">The patch level.<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">9<\/td>\n<td align=\"LEFT\">BASH_VERSINFO[3]<\/td>\n<td align=\"LEFT\">The build version.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"21\">10<\/td>\n<td align=\"LEFT\">BASH_VERSINFO[4]<\/td>\n<td align=\"LEFT\">The release status (for example, beta1 ).<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">11<\/td>\n<td align=\"LEFT\">BASH_VERSINFO[5]<\/td>\n<td align=\"LEFT\">The value of MACHTYPE .<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">12<\/td>\n<td align=\"LEFT\">CDPATH<\/td>\n<td align=\"LEFT\">List of directories separated by colon.<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">13<\/td>\n<td align=\"LEFT\">COLUMNS<\/td>\n<td align=\"LEFT\">Number of Characters per line on Standard Output.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">14<\/td>\n<td align=\"LEFT\">EUID<\/td>\n<td align=\"LEFT\">User ID of the current user.<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"21\">15<\/td>\n<td align=\"LEFT\">FCEDIT<\/td>\n<td align=\"LEFT\">The default text editor for the fc command.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">16<\/td>\n<td align=\"LEFT\">FUNCNAME<\/td>\n<td align=\"LEFT\">The name of the fun<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">17<\/td>\n<td align=\"LEFT\">GROUPS<\/td>\n<td align=\"LEFT\">Groups of which the user is a Member.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">18<\/td>\n<td align=\"LEFT\">HISTFILE<\/td>\n<td align=\"LEFT\">The file containing the command history.<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">19<\/td>\n<td align=\"LEFT\">HOME<\/td>\n<td align=\"LEFT\">The name of your home directory.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">20<\/td>\n<td align=\"LEFT\">LINES<\/td>\n<td align=\"LEFT\">Number of horizontal lines on Standard Output.<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">21<\/td>\n<td align=\"LEFT\">MAIL<\/td>\n<td align=\"LEFT\">Name of a file to check for incoming mail<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">22<\/td>\n<td align=\"LEFT\">OSTYPE<\/td>\n<td align=\"LEFT\">Name of the operating system.<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">23<\/td>\n<td align=\"LEFT\">OLDPWD<\/td>\n<td align=\"LEFT\">The previous working directory<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">24<\/td>\n<td align=\"LEFT\">PWD<\/td>\n<td align=\"LEFT\">The current working directory<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">25<\/td>\n<td align=\"LEFT\">RANDOM<\/td>\n<td align=\"LEFT\">Prints a random number<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">26<\/td>\n<td align=\"LEFT\">SHELL<\/td>\n<td align=\"LEFT\">The preferred shell to use<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"LEFT\" height=\"19\">27<\/td>\n<td align=\"LEFT\">TIMEFORMAT<\/td>\n<td align=\"LEFT\">The format for the time command.<\/td>\n<\/tr>\n<tr>\n<td align=\"LEFT\" height=\"19\">28<\/td>\n<td align=\"LEFT\">UID<\/td>\n<td align=\"LEFT\">The ID of the current user<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>There are a huge list of Predefined BASH Variable. We have tried to produce a list of most frequently used.<\/p>\n<p>That\u2019s all for now.<\/p>\n<h1 class=\"post-title\">SSH Passwordless Login Using SSH Keygen in 5 Easy Steps<\/h1>\n<p><strong>SSH<\/strong>\u00a0(<strong>Secure SHELL<\/strong>) is an open source and most trusted network protocol that is used to login into remote servers for execution of commands and programs. It is also used to transfer files from one computer to another computer over the network using secure copy (<strong>SCP<\/strong>) Protocol.<\/p>\n<p>In this article we will show you how to setup password-less login on\u00a0<strong>RHEL\/CentOS 7.x\/6.x\/5.x<\/strong>\u00a0and\u00a0<strong>Fedora<\/strong>\u00a0using\u00a0<strong>ssh keys<\/strong>\u00a0to connect to remote\u00a0<strong>Linux<\/strong>\u00a0servers without entering password. Using Password-less login with\u00a0<strong>SSH keys<\/strong>\u00a0will increase the trust between two\u00a0<strong>Linux<\/strong>\u00a0servers for easy file synchronization or transfer.<\/p>\n<div id=\"attachment_1322\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/SSH-Passwordless-Login.jpg\"><img decoding=\"async\" class=\"size-medium wp-image-1322\" title=\"SSH Passwordless Login\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/SSH-Passwordless-Login.jpg\" sizes=\"(max-width: 513px) 100vw, 513px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/SSH-Passwordless-Login.jpg 513w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/SSH-Passwordless-Login-300x197.jpg 300w\" alt=\"SSH Passwordless Login\" aria-describedby=\"caption-attachment-1322\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-1322\" class=\"wp-caption-text\">Setup SSH Passwordless Login<\/p>\n<\/div>\n<h5>My Setup Environment<\/h5>\n<pre>SSH Client : 192.168.0.12 ( Fedora 21 )\r\nSSH Remote Host : 192.168.0.11 ( CentOS 7 )\r\n<\/pre>\n<p>If you are dealing with number of\u00a0<strong>Linux<\/strong>\u00a0remote servers, then\u00a0<strong>SSH Password-less<\/strong>\u00a0login is one of the best way to automate tasks such as automatic backups with scripts, synchronization files using scp and remote command execution.<\/p>\n<p>In this example we will setup\u00a0<strong>SSH password-less<\/strong>\u00a0automatic login from server<strong>\u00a0192.168.0.12<\/strong>\u00a0as user\u00a0<strong>tecmint<\/strong>\u00a0to\u00a0<strong>192.168.0.11<\/strong>\u00a0with user\u00a0<strong>sheena<\/strong>.<\/p>\n<h3>Step 1: Create Authentication SSH-Kegen Keys on \u2013 (192.168.0.12)<\/h3>\n<p>&nbsp;<\/p>\n<p>First login into server\u00a0<strong>192.168.0.12<\/strong>\u00a0with user\u00a0<strong>tecmint<\/strong>\u00a0and generate a pair of public keys using following command.<\/p>\n<pre><strong>[tecmint@tecmint.com ~]$ ssh-keygen -t rsa<\/strong>\r\n\r\nGenerating public\/private rsa key pair.\r\nEnter file in which to save the key (\/home\/tecmint\/.ssh\/id_rsa): [Press enter key]\r\nCreated directory '\/home\/tecmint\/.ssh'.\r\nEnter passphrase (empty for no passphrase): [Press enter key]\r\nEnter same passphrase again: [Press enter key]\r\nYour identification has been saved in \/home\/tecmint\/.ssh\/id_rsa.\r\nYour public key has been saved in \/home\/tecmint\/.ssh\/id_rsa.pub.\r\nThe key fingerprint is:\r\n5f:ad:40:00:8a:d1:9b:99:b3:b0:f8:08:99:c3:ed:d3 tecmint@tecmint.com\r\nThe key's randomart image is:\r\n+--[ RSA 2048]----+\r\n|        ..oooE.++|\r\n|         o. o.o  |\r\n|          ..   . |\r\n|         o  . . o|\r\n|        S .  . + |\r\n|       . .    . o|\r\n|      . o o    ..|\r\n|       + +       |\r\n|        +.       |\r\n+-----------------+\r\n<\/pre>\n<div id=\"attachment_12519\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/Create-SSH-RSA-Key.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12519\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/Create-SSH-RSA-Key.gif\" alt=\"Create SSH RSA Key\" aria-describedby=\"caption-attachment-12519\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-12519\" class=\"wp-caption-text\">Create SSH RSA Key<\/p>\n<\/div>\n<h3>Step 2: Create .ssh Directory on \u2013 192.168.0.11<\/h3>\n<p>Use SSH from server\u00a0<strong>192.168.0.12<\/strong>\u00a0to connect server\u00a0<strong>192.168.0.11<\/strong>\u00a0using\u00a0<strong>sheena<\/strong>\u00a0as user and create\u00a0<strong>.ssh<\/strong>directory under it, using following command.<\/p>\n<pre><strong>[tecmint@tecmint ~]$ ssh sheena@192.168.0.11 mkdir -p .ssh<\/strong>\r\n\r\nThe authenticity of host '192.168.0.11 (192.168.0.11)' can't be established.\r\nRSA key fingerprint is 45:0e:28:11:d6:81:62:16:04:3f:db:38:02:la:22:4e.\r\nAre you sure you want to continue connecting (yes\/no)? yes\r\nWarning: Permanently added '192.168.0.11' (ECDSA) to the list of known hosts.\r\n<strong>sheena<\/strong>@192.168.0.11's password: [<strong>Enter Your Password Here<\/strong>]<\/pre>\n<div id=\"attachment_12521\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/Create-SSH-Directory.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12521\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/Create-SSH-Directory.gif\" alt=\"Create SSH Directory Under User Home\" aria-describedby=\"caption-attachment-12521\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-12521\" class=\"wp-caption-text\">Create SSH Directory Under User Home<\/p>\n<\/div>\n<h3>Step 3: Upload Generated Public Keys to \u2013 192.168.0.11<\/h3>\n<p>Use SSH from server\u00a0<strong>192.168.0.12<\/strong>\u00a0and upload new generated public key (<strong>id_rsa.pub<\/strong>) on server\u00a0<strong>192.168.0.11<\/strong>under\u00a0<strong>sheena<\/strong>\u2018s\u00a0<strong>.ssh<\/strong>\u00a0directory as a file name\u00a0<strong>authorized_keys<\/strong>.<\/p>\n<pre><strong>[tecmint@tecmint ~]$ cat .ssh\/id_rsa.pub | ssh sheena@192.168.0.11 'cat &gt;&gt; .ssh\/authorized_keys'<\/strong>\r\n\r\n<strong>sheena<\/strong>@192.168.1.2's password: [<strong>Enter Your Password Here<\/strong>]<\/pre>\n<div id=\"attachment_12523\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/Upload-RSA-Key.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12523\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/Upload-RSA-Key.gif\" alt=\"Upload RSA Key\" aria-describedby=\"caption-attachment-12523\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-12523\" class=\"wp-caption-text\">Upload RSA Key<\/p>\n<\/div>\n<h3>Step 4: Set Permissions on \u2013 192.168.0.11<\/h3>\n<p>Due to different SSH versions on servers, we need to set permissions on .ssh directory and authorized_keys file.<\/p>\n<pre><strong>[tecmint@tecmint ~]$ ssh sheena@192.168.0.11 \"chmod 700 .ssh; chmod 640 .ssh\/authorized_keys\"<\/strong>\r\n\r\n<strong>sheena<\/strong>@192.168.0.11's password: [<strong>Enter Your Password Here<\/strong>]<\/pre>\n<div id=\"attachment_12525\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/Set-Permission-on-SSH-Key.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12525\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/Set-Permission-on-SSH-Key.gif\" alt=\"Set Permission on SSH Key\" aria-describedby=\"caption-attachment-12525\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-12525\" class=\"wp-caption-text\">Set Permission on SSH Key<\/p>\n<\/div>\n<h3>Step 5: Login from 192.168.0.12 to 192.168.0.11 Server without Password<\/h3>\n<p>From now onwards you can log into\u00a0<strong>192.168.0.11<\/strong>\u00a0as\u00a0<strong>sheena<\/strong>\u00a0user from server\u00a0<strong>192.168.0.12<\/strong>\u00a0as\u00a0<strong>tecmint<\/strong>\u00a0user without password.<\/p>\n<pre><strong>[tecmint@tecmint ~]$ ssh sheena@192.168.0.11<\/strong><\/pre>\n<div id=\"attachment_12526\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/SSH-Remote-Passwordless-Login.gif\"><img decoding=\"async\" class=\"size-medium wp-image-12526\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2012\/10\/SSH-Remote-Passwordless-Login.gif\" alt=\"SSH Remote Passwordless Login\" aria-describedby=\"caption-attachment-12526\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-12526\" class=\"wp-caption-text\">SSH Remote Passwordless Login<\/p>\n<\/div>\n<h1 class=\"post-title\">4 Free Shell Scripting eBooks for Linux Newbies and Administrators<\/h1>\n<p><strong>System Administration<\/strong>\u00a0is a branch of Information Technology that deals with reliable operation of multi-user computer systems and servers. A person who is responsible for reliable operation of multiuser computer system and server is called\u00a0<strong>System Administrator<\/strong>.<\/p>\n<p>A System Administrator whose area of expertise is Linux is called Linux System Administrator. A typical Linux System Administrator role may vary over a large aspect of things which may include but not restricted to \u2013 Hardware Maintenance, System Maintenance, User Administration, Network Administration, System Performance, Resource utilization Monitoring, Backup, Ensure Security, Update System, Implement Policies, Documentation, Application Installation and blah, blah, blah\u2026<\/p>\n<p>There is a\u00a0<strong>Quote<\/strong>\u00a0in Information Technology Field \u2013 \u201c<strong>A Programmer is known when he\/she do something good while an Administrator is known if he\/she does something bad<\/strong>.\u201d It is always good to be an unknown administrator than a known administrator. Why? because if you are known, it means your setup don\u2019t work as it should and you are called often for assistance and fixing.<\/p>\n<p>There are three rules that every System Administrator must follow and should never break.<\/p>\n<ol>\n<li><strong>Rule 1\u00a0<\/strong>: Backup Everything<\/li>\n<li><strong>Rule 2<\/strong>\u00a0: Master Command Line<\/li>\n<li><strong>Rule 3<\/strong>\u00a0: Automate task probably using any Scripting Language or Shell Script<\/li>\n<\/ol>\n<h6>Analyze # Rule 1<\/h6>\n<p>Why Backup Everything? Well you never know when the server or a file system may start acting strange or the storage unit just collapse. You must have backup of everything so that if something goes wrong you don\u2019t have to break a sweat, just restore.<\/p>\n<h6>Analyze # Rule 2<\/h6>\n<p>If you are a true Linux Administrator and Understand Linux System you know that you get immense power while using Command Line. While using command Line you have direct access to system calls. Most of the admin work on a headless server (no-GUI) and then Linux Command Line is your only friend and mind it it is more powerful than you believe.<\/p>\n<h6>Analyze # Rule 3<\/h6>\n<p>Automate task, but why? well an administrator at the first point is lazy and he want to perform various attended task like backup automatically. An Intelligent Administrator would like to automate all his work using some kind of script so that he don\u2019t need to intervene every time. He would schedule backup, log and every other thing possible. As you move up in the levels of System Administration you need scripting not only for automating task but also for looking inside the configuration files and other. Shell Scripting is a Computer Program which can run on UNIX\/Linux Shell.<\/p>\n<h4>Learning Scripting<\/h4>\n<p>The\u00a0<strong>Shell Scripting<\/strong>\u00a0(bash scripting) Language is easy and fun. If you know any other Programming Language you would probably understand most of the Shell Scripts and may start writing your\u2019s own very soon. Even if you don\u2019t have knowledge of any programming Language, learning Scripting won\u2019t be any difficult.<\/p>\n<p>There are other Scripting Language like Python, Perl, Ruby etc which provides you with more function and helps you achieve the result easily. But if you are novice and want to start from shell scripting.<\/p>\n<h6>Where to Learn Shell Scripting Language?<\/h6>\n<p>We have already posted a series of easy to understand articles on shell scripting which you may find in the link below.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/category\/bash-shell\/\" target=\"_blank\" rel=\"noopener\">Learn Linux Shell Scripting<\/a><\/li>\n<\/ol>\n<p>We will be extending this series very soon, before that we\u2019ve compiled a list of 4 books on Shell Scripting. These books are free to download and will help you mentoring your shell scripting skills. No matter you are experienced or newbie you must have these handy documents with you if you are in the field of Linux.<\/p>\n<h3>1. Bash Guide for Beginners<\/h3>\n<p>This book contains a total of 12 chapters spread over 165 pages. This book is written by\u00a0<strong>Machtelt Garrels<\/strong>. This book is must for anyone working on UNIX and like environment. If you are a System Administrator and want to make your life easier this resource is for you. If you are experienced Linux User, this book aims at giving you an insight of the System. The documents are very encouraging and it will help you writing your own scripts. Detailed and wide list of topics covered in easy to understand language is another plus point of this guide.<\/p>\n<p><center><a href=\"http:\/\/tecmint.tradepub.com\/free\/w_mach02\/prgm.cgi\" target=\"_blank\" rel=\"nofollow noopener\"><img decoding=\"async\" src=\"https:\/\/img.tradepub.com\/free\/w_mach02\/images\/w_mach02c4.gif\" data-lazy-loaded=\"true\" \/><\/a><\/center><a href=\"http:\/\/tecmint.tradepub.com\/free\/w_mach02\/prgm.cgi\" target=\"_blank\" rel=\"nofollow noopener\">Download \u2013 Bash Guide for Beginners<\/a><\/p>\n<h3>2. Advanced Bash-Scripting Guide<\/h3>\n<p>This book contains 38 chapters and spread over 901 pages. Having detailed description of everything you may need to learn yet in language that is easy to understand. This book is written by\u00a0<strong>Mendel Cooper<\/strong>\u00a0and it contains plenty of practical examples. The tutorial in the book assumes that you don\u2019t have any previous knowledge of scripting and Programming but progress rapidly to intermediate and advanced level of Instruction. The detailed description in the book makes it a self study guide.<\/p>\n<p><center><a href=\"http:\/\/tecmint.tradepub.com\/free\/w_advb01\/prgm.cgi\" target=\"_blank\" rel=\"nofollow noopener\"><img decoding=\"async\" src=\"https:\/\/img.tradepub.com\/free\/w_advb01\/images\/w_advb01c4.gif\" data-lazy-loaded=\"true\" \/><\/a><\/center><a href=\"http:\/\/tecmint.tradepub.com\/free\/w_advb01\/prgm.cgi\" target=\"_blank\" rel=\"nofollow noopener\">Download \u2013 Advanced Bash-Scripting Guide<\/a><\/p>\n<h3>3. Shell Scripting: Expert Recipes for Linux<\/h3>\n<p>This book is written by\u00a0<strong>Steve Parker<\/strong>. Though you can not download this book completely for free, the first 40 pages are free. It is sufficient to know what the book contains. Personally I am an admirer of Steve for this wonderful piece of guide. His skills and writing style is awesome. Plenty of practical examples, easy to understand theory and his style of presenting adds to the list. The original book is voluminous. You may download the 40 page guide to learn and see if you are going to get around scripting.<\/p>\n<p><center><a href=\"http:\/\/tecmint.tradepub.com\/free\/w_wile48\/prgm.cgi?a=1\" target=\"_blank\" rel=\"nofollow noopener\"><img decoding=\"async\" src=\"https:\/\/img.tradepub.com\/free\/w_wile48\/images\/w_wile48c4.gif\" data-lazy-loaded=\"true\" \/><\/a><\/center><a href=\"http:\/\/tecmint.tradepub.com\/free\/w_wile48\/prgm.cgi?a=1\" target=\"_blank\" rel=\"nofollow noopener\">Download \u2013 Shell Scripting: Expert Recipes for Linux<\/a><\/p>\n<h3>4. Linux Shell Scripting Cookbook, Second Edition<\/h3>\n<p>This book contains a total of 9 chapters spread over 40 pages. This book is written by\u00a0<strong>Shantanu Tushar<\/strong>\u00a0who is a GNU\/Linux user since his early days. This guide contains a balanced combination of theory and practical. I don\u2019t want you to loose your interest for this 40 page guide which may be life Saviour for you. Download and see how this is useful for you.<\/p>\n<p><center><a href=\"http:\/\/tecmint.tradepub.com\/free\/w_pack42\/prgm.cgi?a=1\" target=\"_blank\" rel=\"nofollow noopener\"><img decoding=\"async\" src=\"https:\/\/img.tradepub.com\/free\/w_pack42\/images\/w_pack42c4.gif\" data-lazy-loaded=\"true\" \/><\/a><\/center><a href=\"http:\/\/tecmint.tradepub.com\/free\/w_pack42\/prgm.cgi?a=1\" target=\"_blank\" rel=\"nofollow noopener\">Download \u2013 Linux Shell Scripting Cookbook, Second Edition<\/a><\/p>\n<p>In order to download any book from our partner site you need to fill a small form. All your information are safe with our partner site and we won\u2019t\u00a0<strong>SPAM<\/strong>\u00a0you. Even we hate SPAM. Fill the form with relevant information so that you may get notification and Information from time-to-time. You may opt out to receive any information. You just have to register once and you may Download any books for any number of times and that too free.<\/p>\n<p>It has lots of books on different domains and by registering once you are entitled to download the whole library and be choosy what you want to have in your library. The above shell scripting books will bring a huge change in your skill and will take you to the next level. So what are you waiting for? Want a career in Linux, want to revamp your skill sets, learn something new and interesting, Download the books, have fun!<\/p>\n<h1 class=\"post-title\">A Shell Script to Monitor Network, Disk Usage, Uptime, Load Average and RAM Usage in Linux<\/h1>\n<p>The duty of\u00a0<strong>System Administrator<\/strong>\u00a0is really tough as he\/she has to monitor the servers, users, logs, create backup and blah blah blah. For the most repetitive task most of the administrator write a script to automate their day-to-day repetitive task. Here we have written a shell Script that do not aims to automate the task of a typical system admin, but it may be helpful at places and specially for those newbies who can get most of the information they require about their System, Network, Users, Load, Ram, host, Internal IP, External IP, Uptime, etc.<\/p>\n<p>We have taken care of formatting the output (to certain extent). The Script don\u2019t contains any Malicious contents and it can be run using Normal user Account. In-fact it is recommended to run this script as user and not as root.<\/p>\n<div id=\"attachment_13269\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/05\/Linux-Health-Monitoring.png\"><img decoding=\"async\" class=\"size-medium wp-image-13269\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/05\/Linux-Health-Monitoring.png\" sizes=\"(max-width: 720px) 100vw, 720px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/05\/Linux-Health-Monitoring.png 720w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/05\/Linux-Health-Monitoring-620x297.png 620w\" alt=\"Linux Server Health Monitoring\" aria-describedby=\"caption-attachment-13269\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-13269\" class=\"wp-caption-text\">Shell Script to Monitor Linux System Health<\/p>\n<\/div>\n<p>You are free to use\/modify\/redistribute the below piece of code by giving proper credit to\u00a0<strong>Tecmint<\/strong>\u00a0and\u00a0<strong>Author<\/strong>. We have tried to customize the output to the extent that nothing other than the required output is generated. We have tried to use those variables which are generally not used by Linux System and are probably free.<\/p>\n<h5>Minimum System Requirement<\/h5>\n<p>All you need to have is a working Linux box.<\/p>\n<h5>DependencY<\/h5>\n<p>There is no dependency required to use this package for a standard Linux Distribution. Moreover the script don\u2019t requires root permission for execution purpose. However if you want to Install it, you need to enter root password once.<\/p>\n<h5>Security<\/h5>\n<p>We have taken care to ensure security of the system. Nothing additional package is required\/installed. No root access required to run. Moreover code has been released under\u00a0<strong>Apache 2.0 License<\/strong>, that means you are free to edit, modify and re-distribute by keeping Tecmint copyright.<\/p>\n<h3>How Do I Install and Run Script?<\/h3>\n<p>First, use following\u00a0<a title=\"Download Files Using Wget Command\" href=\"https:\/\/www.tecmint.com\/10-wget-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">wget command<\/a>\u00a0to download the monitor script\u00a0<code>\"tecmint_monitor.sh\"<\/code>\u00a0and make it executable by setting appropriate permissions.<\/p>\n<pre># wget https:\/\/tecmint.com\/wp-content\/scripts\/tecmint_monitor.sh\r\n# chmod 755 tecmint_monitor.sh\r\n<\/pre>\n<p>It is strongly advised to install the script as user and not as root. It will ask for root password and will install the necessary components at required places.<\/p>\n<p>To install\u00a0<code>\"tecmint_monitor.sh\"<\/code>\u00a0script, simple use\u00a0<strong>-i<\/strong>\u00a0(install) option as shown below.<\/p>\n<pre>.\/tecmint_monitor.sh -i \r\n<\/pre>\n<p>Enter\u00a0<strong>root<\/strong>\u00a0password when prompted. If everything goes well you will get a success message like shown below.<\/p>\n<pre>Password: \r\nCongratulations! Script Installed, now run monitor Command\r\n<\/pre>\n<p>After installation, you can run the script by calling command\u00a0<code>'monitor'<\/code>\u00a0from any location or user. If you don\u2019t like to install it, you need to include the location every-time you want to run it.<\/p>\n<pre># .\/Path\/to\/script\/tecmint_monitor.sh\r\n<\/pre>\n<p>Now run monitor command from anywhere using any user account simply as:<\/p>\n<pre>$ monitor\r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/05\/TecMint-Monitor-Script.gif\"><img decoding=\"async\" class=\"size-medium wp-image-13266\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/05\/TecMint-Monitor-Script.gif\" alt=\"TecMint Monitor Script in Action\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>As soon as you run the command you get various System related information which are:<\/p>\n<ol>\n<li>Internet Connectivity<\/li>\n<li>OS Type<\/li>\n<li>OS Name<\/li>\n<li>OS Version<\/li>\n<li>Architecture<\/li>\n<li>Kernel Release<\/li>\n<li>Hostname<\/li>\n<li>Internal IP<\/li>\n<li>External IP<\/li>\n<li>Name Servers<\/li>\n<li>Logged In users<\/li>\n<li>Ram Usages<\/li>\n<li>Swap Usages<\/li>\n<li>Disk Usages<\/li>\n<li>Load Average<\/li>\n<li>System Uptime<\/li>\n<\/ol>\n<p>Check the installed version of script using\u00a0<strong>-v<\/strong>\u00a0(version) switch.<\/p>\n<pre>$ monitor -v\r\n\r\ntecmint_monitor version 0.1\r\nDesigned by Tecmint.com\r\nReleased Under Apache 2.0 License\r\n<\/pre>\n<h3>Conclusion<\/h3>\n<p>This script is working out of the box on a few machines I have checked. It should work the same for you as well. If you find any bug let us know in the comments. This is not the end. This is the beginning. You can take it to any level from here.<\/p>\n<p>We\u2019ve received few complaints that the script is not working on the few Linux distributions, and one of our regular reader\u00a0<strong>Mr. Andres Tarallo<\/strong>, has taken the initiative and made the script compatible with all Linux distributions, you can find the updated script on\u00a0<strong>GitHub<\/strong>\u00a0at\u00a0<a href=\"https:\/\/github.com\/atarallo\/TECMINT_MONITOR\/\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/atarallo\/TECMINT_MONITOR\/<\/a>.<\/p>\n<p>If you feel like editing the script and carry it further you are free to do so giving us proper credit and also share the updated script with us so that we can update this article by giving you proper credit.<\/p>\n<p>Don\u2019t forget to share your thoughts or your script with us. We will be here to help you. Thank you for all the love you have given us. Keep Connected! Stay tuned.<\/p>\n<h1 class=\"post-title\">Powerline \u2013 Adds Powerful Statuslines and Prompts to Vim Editor and Bash Terminal<\/h1>\n<p><strong>Powerline<\/strong>\u00a0is a great statusline plugin for\u00a0<a href=\"https:\/\/www.tecmint.com\/vi-editor-usage\/\" target=\"_blank\" rel=\"noopener\">Vim editor<\/a>, which is developed in\u00a0<strong>Python<\/strong>\u00a0and provides statuslines and prompts for many other applications such as bash, zsh, tmux and many more.<\/p>\n<div id=\"attachment_15979\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Install-Powerline-Statuslines-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15979\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Install-Powerline-Statuslines-in-Linux-620x297.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Install-Powerline-Statuslines-in-Linux-620x297.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Install-Powerline-Statuslines-in-Linux.png 720w\" alt=\"Install Powerline Statuslines in Linux\" width=\"620\" height=\"297\" aria-describedby=\"caption-attachment-15979\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15979\" class=\"wp-caption-text\">Add Power to Linux Terminal with Powerline Tool<\/p>\n<\/div>\n<h4>Features<\/h4>\n<ol>\n<li>It is written in Python, which makes it extensible and feature rich.<\/li>\n<li>Stable and testable code base, which works well with Python 2.6+ and Python 3.<\/li>\n<li>It also supports prompts and statuslines in several Linux utilities and tools.<\/li>\n<li>It has configurations and decorator colors developed using JSON.<\/li>\n<li>Fast and lightweight, with daemon support, which provides even more better performance.<\/li>\n<\/ol>\n<h4>Powerline Screenshots<\/h4>\n<div id=\"attachment_15963\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Powerline-Vim-Statuslines.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-15963\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Powerline-Vim-Statuslines.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Powerline-Vim-Statuslines.png 744w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Powerline-Vim-Statuslines-620x295.png 620w\" alt=\"Powerline Vim Statuslines\" width=\"620\" height=\"295\" aria-describedby=\"caption-attachment-15963\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-15963\" class=\"wp-caption-text\">Powerline Vim Statuslines<\/p>\n<\/div>\n<p>In this article, I will show you how to install\u00a0<strong>Powerline<\/strong>\u00a0and\u00a0<strong>Powerline fonts<\/strong>\u00a0and how to use with\u00a0<strong>Bash<\/strong>\u00a0and\u00a0<strong>Vim<\/strong>under\u00a0<strong>RedHat<\/strong>\u00a0and\u00a0<strong>Debian<\/strong>\u00a0based systems.<\/p>\n<h3>Step 1: Installing Generic Requirements for Powerline<\/h3>\n<p>Due to a naming conflict with some other unrelated projects, powerline program is available on\u00a0<strong>PyPI<\/strong>\u00a0(<strong>Python Package Index<\/strong>) under the package name as\u00a0<strong>powerline-status<\/strong>.<\/p>\n<p>To install packages from\u00a0<strong>PyPI<\/strong>, we need a \u2018<strong>pip<\/strong>\u2018 (package management tool for installing Python packages). So, let\u2019s first install\u00a0<strong>pip<\/strong>\u00a0tool under our Linux systems.<\/p>\n<h4>Install Pip on Debian, Ubuntu and Linux Mint<\/h4>\n<pre># apt-get install python-pip\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>Reading package lists... Done\r\nBuilding dependency tree       \r\nReading state information... Done\r\nRecommended packages:\r\n  python-dev-all python-wheel\r\nThe following NEW packages will be installed:\r\n  python-pip\r\n0 upgraded, 1 newly installed, 0 to remove and 533 not upgraded.\r\nNeed to get 97.2 kB of archives.\r\nAfter this operation, 477 kB of additional disk space will be used.\r\nGet:1 http:\/\/archive.ubuntu.com\/ubuntu\/ trusty-updates\/universe python-pip all 1.5.4-1ubuntu3 [97.2 kB]\r\nFetched 97.2 kB in 1s (73.0 kB\/s)     \r\nSelecting previously unselected package python-pip.\r\n(Reading database ... 216258 files and directories currently installed.)\r\nPreparing to unpack ...\/python-pip_1.5.4-1ubuntu3_all.deb ...\r\nUnpacking python-pip (1.5.4-1ubuntu3) ...\r\nProcessing triggers for man-db (2.6.7.1-1ubuntu1) ...\r\nSetting up python-pip (1.5.4-1ubuntu3) ...\r\n<\/pre>\n<h4>Install Pip on CentOS, RHEL and Fedora<\/h4>\n<p>Under Fedora-based systems, you need to first\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-enable-epel-repository-for-rhel-centos-6-5\/\" target=\"_blank\" rel=\"noopener\">enable epel-repository<\/a>\u00a0and then install\u00a0<strong>pip<\/strong>\u00a0package as shown.<\/p>\n<pre># yum install python-pip          \r\n# dnf install python-pip                     [On <strong>Fedora 22+<\/strong> versions]           \r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>Installing:\r\n python-pip          noarch          7.1.0-1.el7             epel          1.5 M\r\n\r\nTransaction Summary\r\n=================================================================================\r\nInstall  1 Package\r\n\r\nTotal download size: 1.5 M\r\nInstalled size: 6.6 M\r\nIs this ok [y\/d\/N]: y\r\nDownloading packages:\r\npython-pip-7.1.0-1.el7.noarch.rpm                         | 1.5 MB  00:00:01     \r\nRunning transaction check\r\nRunning transaction test\r\nTransaction test succeeded\r\nRunning transaction\r\n  Installing : python-pip-7.1.0-1.el7.noarch                                 1\/1 \r\n  Verifying  : python-pip-7.1.0-1.el7.noarch                                 1\/1 \r\n\r\nInstalled:\r\n  python-pip.noarch 0:7.1.0-1.el7                                                \r\n\r\nComplete!\r\n<\/pre>\n<h3>Step 2: Installing Powerline Tool in Linux<\/h3>\n<p>Now it\u2019s\u2019 time to install\u00a0<strong>Powerline<\/strong>\u00a0latest development version from the\u00a0<strong>Git<\/strong>\u00a0repository. For this, your system must have git package installed in order to fetch the packages from Git.<\/p>\n<pre># apt-get install git\r\n# yum install git\r\n# dnf install git\r\n<\/pre>\n<p>Next you can install\u00a0<strong>Powerline<\/strong>\u00a0with the help of\u00a0<strong>pip<\/strong>\u00a0command as shown.<\/p>\n<pre># pip install git+git:\/\/github.com\/Lokaltog\/powerline\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre> Cloning git:\/\/github.com\/Lokaltog\/powerline to \/tmp\/pip-WAlznH-build\r\n  Running setup.py (path:\/tmp\/pip-WAlznH-build\/setup.py) egg_info for package from git+git:\/\/github.com\/Lokaltog\/powerline\r\n    \r\n    warning: no previously-included files matching '*.pyc' found under directory 'powerline\/bindings'\r\n    warning: no previously-included files matching '*.pyo' found under directory 'powerline\/bindings'\r\nInstalling collected packages: powerline-status\r\n  Found existing installation: powerline-status 2.2\r\n    Uninstalling powerline-status:\r\n      Successfully uninstalled powerline-status\r\n  Running setup.py install for powerline-status\r\n    \r\n    warning: no previously-included files matching '*.pyc' found under directory 'powerline\/bindings'\r\n    warning: no previously-included files matching '*.pyo' found under directory 'powerline\/bindings'\r\n    changing mode of build\/scripts-2.7\/powerline-lint from 644 to 755\r\n    changing mode of build\/scripts-2.7\/powerline-daemon from 644 to 755\r\n    changing mode of build\/scripts-2.7\/powerline-render from 644 to 755\r\n    changing mode of build\/scripts-2.7\/powerline-config from 644 to 755\r\n    changing mode of \/usr\/local\/bin\/powerline-config to 755\r\n    changing mode of \/usr\/local\/bin\/powerline-lint to 755\r\n    changing mode of \/usr\/local\/bin\/powerline-render to 755\r\n    changing mode of \/usr\/local\/bin\/powerline-daemon to 755\r\nSuccessfully installed powerline-status\r\nCleaning up...\r\n<\/pre>\n<h3>Step 3: Installing Powerline Fonts in Linux<\/h3>\n<p>Powerline uses special\u00a0<strong>glyphs<\/strong>\u00a0to show special arrow effect and symbols for developers. For this, you must have a symbol font or a patched font installed on your systems.<\/p>\n<p>Download the most recent version of the symbol font and fontconfig configuration file using following\u00a0<a href=\"https:\/\/www.tecmint.com\/10-wget-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">wget command<\/a>.<\/p>\n<pre># wget https:\/\/github.com\/powerline\/powerline\/raw\/develop\/font\/PowerlineSymbols.otf\r\n# wget https:\/\/github.com\/powerline\/powerline\/raw\/develop\/font\/10-powerline-symbols.conf\r\n<\/pre>\n<p>Then you need to move the font to your fonts directory,\u00a0<strong>\/usr\/share\/fonts\/<\/strong>\u00a0or\u00a0<strong>\/usr\/local\/share\/fonts<\/strong>\u00a0as follows or you can get the valid font paths by using command\u00a0<code>xset q<\/code>.<\/p>\n<pre># mv PowerlineSymbols.otf \/usr\/share\/fonts\/\r\n<\/pre>\n<p>Next, you need to update your system\u2019s font cache as follows.<\/p>\n<pre># fc-cache -vf \/usr\/share\/fonts\/\r\n<\/pre>\n<p>Now install the fontconfig file.<\/p>\n<pre># mv 10-powerline-symbols.conf \/etc\/fonts\/conf.d\/\r\n<\/pre>\n<p><strong>Note<\/strong>: If custom symbols doesn\u2019t appear, then try to close all terminal sessions and restart X window for the changes to take effect.<\/p>\n<h3>Step 4: Setting Powerline for Bash Shell and Vim Statuslines<\/h3>\n<p>In this section we shall look at configuring Powerline for bash shell and vim editor. First make your terminal to support\u00a0<strong>256color<\/strong>\u00a0by adding the following line to\u00a0<strong>~\/.bashrc<\/strong>\u00a0file as follows.<\/p>\n<pre>export TERM=\u201dscreen-256color\u201d \r\n<\/pre>\n<h4>Enable Powerline on Bash Shell<\/h4>\n<p>To enable Powerline in bash shell by default, you need to add the following snippet to your\u00a0<strong>~\/.bashrc<\/strong>\u00a0file.<\/p>\n<p>First get the location of installed\u00a0<strong>powerline<\/strong>\u00a0using following command.<\/p>\n<pre># <strong>pip show powerline-status<\/strong>\r\n\r\nName: powerline-status\r\nVersion: 2.2.dev9999-git.aa33599e3fb363ab7f2744ce95b7c6465eef7f08\r\nLocation: <strong>\/usr\/local\/lib\/python2.7\/dist-packages<\/strong>\r\nRequires: \r\n<\/pre>\n<p>Once you know the actual location of\u00a0<strong>powerline<\/strong>, make sure to replace the location in the below line as per your system suggested.<\/p>\n<pre>powerline-daemon -q\r\nPOWERLINE_BASH_CONTINUATION=1\r\nPOWERLINE_BASH_SELECT=1\r\n. <strong>\/usr\/local\/lib\/python2.7\/dist-packages\/<\/strong>powerline\/bindings\/bash\/powerline.sh\r\n<\/pre>\n<p>Now try to logout and login back again, you will see powerline statuesline as shown below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Bash-Powerline-Statuslines.gif\"><img decoding=\"async\" class=\"size-medium wp-image-15972\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Bash-Powerline-Statuslines.gif\" alt=\"Bash Powerline Statuslines\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>Try changing or switching to different directories and keep a eye on \u201c<strong>breadcrumb<\/strong>\u201d prompt changes to show your current location.<\/p>\n<p>You will also be able to watch pending background jobs and if powerline is installed on a remote Linux machine, you can notice that the prompt adds the hostname when you connect via SSH.<\/p>\n<h4>Enable Powerline for Vim<\/h4>\n<p>If\u00a0<strong>vim<\/strong>\u00a0is your favorite editor, luckily there is a powerful plugin for vim, too. To enable this plugin, add these lines to\u00a0<code>~\/.vimrc<\/code>\u00a0file.<\/p>\n<pre>set  rtp+=\/usr\/local\/lib\/python2.7\/dist-packages\/powerline\/bindings\/vim\/\r\nset laststatus=2\r\nset t_Co=256\r\n<\/pre>\n<p>Now you can launch vim and see a spiffy new status line:<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Vim-Powerline-Statuslines.gif\"><img decoding=\"async\" class=\"size-medium wp-image-15974\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/10\/Vim-Powerline-Statuslines.gif\" alt=\"Vim Powerline Statuslines\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p><strong>Powerline<\/strong>\u00a0helps to set colorful and beautiful statuslines and prompts in several applications, good for coding environments. I hope you find this guide helpful and remember to post a comment if you need any help or have additional ideas.<\/p>\n<h1 class=\"post-title\">How To Enable Shell Script Debugging Mode in Linux<\/h1>\n<p>A script is simply a list of commands stored in a file. Instead of running a sequence of commands by typing them one by one all the time on the terminal, a system user can store all of them (commands) in a file and repeatedly invokes the file to re-execute the commands several times.<\/p>\n<p>While\u00a0<a href=\"https:\/\/www.tecmint.com\/category\/bash-shell\/\" target=\"_blank\" rel=\"noopener\">learning scripting<\/a>\u00a0or during the early stages of writing scripts, we normally start by writing small or short scripts with a few lines of commands. And we usually debug such scripts by doing nothing more than looking at their output and ensuring that they work as we intended.<\/p>\n<p>However, as we begin to write very long and advanced scripts with thousands of lines of commands, for instance scripts that modify system settings,\u00a0<a href=\"https:\/\/www.tecmint.com\/rsync-local-remote-file-synchronization-commands\/\" target=\"_blank\" rel=\"noopener\">perform critical backups over networks<\/a>\u00a0and many more, we will realize that only looking at the output of a script is not enough to find bugs within a script.<\/p>\n<p>Therefore, in this shell script debugging in Linux series, we will walk through how to enable shell script debugging, move over to explain the different shell script debugging modes and how to use them in the subsequent series.<\/p>\n<h3>How To Start A Script<\/h3>\n<p>&nbsp;<\/p>\n<p>A script is distinguished from other files by its first line, that contains a\u00a0<code>#!<\/code>\u00a0(<strong>She-bang<\/strong>\u00a0\u2013 defines the file type) and a path name (path to interpreter) which informs the system that the file is a collection of commands that will be interpreted by the specified program (interpreter).<\/p>\n<p>Below are examples of the \u201cfirst lines\u201d in different types of scripts:<\/p>\n<pre>#!\/bin\/sh          [For <strong>sh<\/strong> scripting]\r\n#!\/bin\/bash        [For <strong>bash<\/strong> scripting] \r\n#!\/usr\/bin\/perl    [For <strong>perl<\/strong> programming]\r\n#!\/bin\/awk -f      [For <strong>awk<\/strong> scripting]   \r\n<\/pre>\n<p><strong>Note<\/strong>: The first line or\u00a0<code>#!<\/code>\u00a0can be left out if a script contains only of a set of standard system commands, without any internal shell directives.<\/p>\n<h3>How To Execute A Shell Script in Linux<\/h3>\n<p>The conventional syntax for invoking a shell script is:<\/p>\n<pre>$ script_name  argument1 ... argumentN\r\n<\/pre>\n<p>Another possible form is by clearly specifying the shell that will execute the script as below:<\/p>\n<pre>$ shell script_name argument1 ... argumentN  \r\n<\/pre>\n<p>For example:<\/p>\n<pre>$ \/bin\/bash script_name argument1 ... argumentN     [For <strong>bash<\/strong> scripting]\r\n$ \/bin\/ksh script_name argument1 ... argumentN      [For <strong>ksh<\/strong> scripting]\r\n$ \/bin\/sh script_name argument1 ... argumentN       [For <strong>sh<\/strong> scripting]\r\n<\/pre>\n<p>For scripts that do not have\u00a0<code>#!<\/code>\u00a0as the first line and only contain basic system commands such as the one below:<\/p>\n<pre>#script containing standard system commands\r\ncd \/home\/$USER\r\nmkdir tmp\r\necho \"tmp directory created under \/home\/$USER\"\r\n<\/pre>\n<p>Simply make it executable and run it as follows:<\/p>\n<pre>$ chmod +x  script_name\r\n$ .\/script_name \r\n<\/pre>\n<h3>Methods of Enabling Shell Script Debugging Mode<\/h3>\n<p>Below are the primary shell script debugging options:<\/p>\n<ol>\n<li><code>-v<\/code>\u00a0(short for verbose) \u2013 tells the shell to show all lines in a script while they are read, it activates verbose mode.<\/li>\n<li><code>-n<\/code>\u00a0(short for noexec or no ecxecution) \u2013 instructs the shell read all the commands, however doesn\u2019t execute them. This options activates syntax checking mode.<\/li>\n<li><code>-x<\/code>\u00a0(short for xtrace or execution trace) \u2013 tells the shell to display all commands and their arguments on the terminal while they are executed. This option enables shell tracing mode.<\/li>\n<\/ol>\n<h4>1. Modifying the First Line of a Shell Script<\/h4>\n<p>The first mechanism is by altering the first line of a shell script as below, this will enable debugging of the whole script.<\/p>\n<pre>#!\/bin\/sh option(s)\r\n<\/pre>\n<p>In the form above, option can be one or combination of the debugging options above.<\/p>\n<h4>2. Invoking Shell With Debugging Options<\/h4>\n<p>The second is by invoking the shell with debugging options as follows, this method will also turn on debugging of the entire script.<\/p>\n<pre>$ shell option(s) script_name argument1 ... argumentN\r\n<\/pre>\n<p>For example:<\/p>\n<pre>$ \/bin\/bash option(s) script_name argument1 ... argumentN   \r\n<\/pre>\n<h4>3. Using set Shell Built-in Command<\/h4>\n<p>The third method is by using the set built-in command to debug a given section of a shell script such as a function. This mechanism is important, as it allows us to activate debugging at any segment of a shell script.<\/p>\n<p>We can turn on debugging mode using\u00a0<strong>set<\/strong>\u00a0command in form below, where option is any of the debugging options.<\/p>\n<pre>$ set option \r\n<\/pre>\n<p>To enable debugging mode, use:<\/p>\n<pre>$ set -option\r\n<\/pre>\n<p>To disable debugging mode, use:<\/p>\n<pre>$ set +option\r\n<\/pre>\n<p>In addition, if we have enabled several debugging modes in different segments of a shell script, we can disable all of them at once like so:<\/p>\n<pre>$ set -\r\n<\/pre>\n<p>That is it for now with enabling shell script debugging mode. As we have seen, we can either debug an entire shell script or a particular section of a script.<\/p>\n<p>In the next two episode of this series, we will cover how to use the shell script debugging options to\u00a0<strong>explain verbose<\/strong>,\u00a0<strong>syntax checking<\/strong>\u00a0and\u00a0<strong>shell tracing debugging<\/strong>\u00a0modes with examples.<\/p>\n<p>Importantly, do not forget to ask any questions about this guide or perhaps provide us feedback through the comment section below.<\/p>\n<h1 class=\"post-title\">How to Perform Syntax Checking Debugging Mode in Shell Scripts<\/h1>\n<p>We started the shell script debugging series by explaining the different debugging options and\u00a0<a href=\"https:\/\/www.tecmint.com\/enable-shell-debug-mode-linux\/\" target=\"_blank\" rel=\"noopener\">how to enable shell script debugging modes<\/a>.<\/p>\n<p>After writing your shell scripts, it is recommended that we practically check the syntax in the scripts before running them, as opposed to looking at their output to confirm that they are working correctly.<\/p>\n<p>In this part of the series, we will go through how to use syntax checking debugging mode. Remember we explained the different debugging options in the first part of this series and here, we will use them to perform script debugging.<\/p>\n<h4>Enabling Verbose Debugging Mode<\/h4>\n<p>Before we move to the primary focus of this guide, let us briefly explore the\u00a0<strong>verbose mode<\/strong>. It is enabled by the\u00a0<code>-v<\/code>\u00a0debugging option, which tells the shell to display all lines in a script while they are read.<\/p>\n<p>To demonstrate how this works, below is a sample shell script to\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-image-conversion-tools\/\" target=\"_blank\" rel=\"noopener\">batch convert PNG images to JPG format<\/a>.<\/p>\n<p>Type ( or copy and paste) it in a file.<\/p>\n<pre>#!\/bin\/bash\r\n#convert\r\nfor image in *.png; do\r\n        convert  \"$image\"  \"${image%.png}.jpg\"\r\n        echo \"image $image converted to ${image%.png}.jpg\"\r\ndone\r\nexit 0\r\n<\/pre>\n<p>Then save the file and make the script executable using the command below:<\/p>\n<pre>$ chmod +x script.sh\r\n<\/pre>\n<p>We can invoke the script and display all the lines in it as they are read by the shell like so:<\/p>\n<pre>$ bash -v script.sh\r\n<\/pre>\n<div id=\"attachment_23790\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Show-Shell-Script-Lines.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23790\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Show-Shell-Script-Lines.png\" alt=\"Display All Lines in Shell Script\" width=\"600\" height=\"192\" aria-describedby=\"caption-attachment-23790\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23790\" class=\"wp-caption-text\">Display All Lines in Shell Script<\/p>\n<\/div>\n<h4>Enabling Syntax Checking Debugging Mode in Shell Scripts<\/h4>\n<p>Coming back to our topic of emphasis, The\u00a0<code>-n<\/code>\u00a0activates syntax checking mode. It instructs the shell to basically read all the commands, however doesn\u2019t execute them, it (shell) only examines the syntax used.<\/p>\n<p>In case there are errors in your shell script, the shell will output the errors on the terminal, otherwise, it displays nothing.<\/p>\n<p>The syntax for activating syntax checking is as follows:<\/p>\n<pre>$ bash -n script.sh\r\n<\/pre>\n<p>Because the syntax in the script is correct, the command above will not display any output. Therefore, let us try to remove the\u00a0<code>done<\/code>\u00a0word that closes the for loop and see if it shows an error:<\/p>\n<p>Below is the modified shell script to batch convert png images to jpg format that contains a bug.<\/p>\n<pre>#!\/bin\/bash\r\n#script with a bug\r\n#convert\r\nfor image in *.png; do\r\n        convert  \"$image\"  \"${image%.png}.jpg\"\r\n        echo \"image $image converted to ${image%.png}.jpg\"\r\n\r\nexit 0\r\n<\/pre>\n<p>Save the file, then run it while performing syntax checking in it:<\/p>\n<pre>$ bash -n script.sh\r\n<\/pre>\n<div id=\"attachment_23791\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Check-Syntax-in-Shell-Script.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23791\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Check-Syntax-in-Shell-Script.png\" alt=\"Check Syntax in Shell Script\" width=\"578\" height=\"97\" aria-describedby=\"caption-attachment-23791\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23791\" class=\"wp-caption-text\">Check Syntax in Shell Script<\/p>\n<\/div>\n<p>From the output above, we can see that there is a syntax problem with our script, the for loop is missing a closing\u00a0<code>done<\/code>\u00a0keyword word. And the shell looked for it up to the end of the file and once it did not find it (<strong>done<\/strong>), the shell printed a syntax error:<\/p>\n<pre>script.sh: line 11: syntax error: unexpected end of file\r\n<\/pre>\n<p>We can as well combine the verbose mode and syntax checking mode together:<\/p>\n<pre>$ bash -vn script.sh\r\n<\/pre>\n<div id=\"attachment_23792\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Enable-Verbose-and-Syntax-Checking-in-Script.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23792\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Enable-Verbose-and-Syntax-Checking-in-Script.png\" alt=\"Enable Verbose and Syntax Checking in Script\" width=\"590\" height=\"249\" aria-describedby=\"caption-attachment-23792\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23792\" class=\"wp-caption-text\">Enable Verbose and Syntax Checking in Script<\/p>\n<\/div>\n<p>Alternatively, we can enable syntax checking by modifying the first line of the script above as in the next example.<\/p>\n<pre><strong>#!\/bin\/bash -n<\/strong>\r\n#altering the first line of a script to enable syntax checking\r\n\r\n#convert\r\nfor image in *.png; do\r\n    convert  \"$image\"  \"${image%.png}.jpg\"\r\n    echo \"image $image converted to ${image%.png}.jpg\"\r\n\r\nexit 0\r\n<\/pre>\n<p>As before, save the file and run it while performing syntax checking:<\/p>\n<pre>$ .\/script.sh\r\n\r\n<strong>script.sh: line 12: syntax error: unexpected end of file<\/strong>\r\n<\/pre>\n<p>In addition, we can employ the set shell built-in command to enable debugging mode in the script above.<\/p>\n<p>In the example below, we are only checking the syntax of the for loop in our script.<\/p>\n<pre>#!\/bin\/bash\r\n#using set shell built-in command to enable debugging\r\n#convert\r\n\r\n#enable debugging\r\nset -n\r\nfor image in *.png; do\r\n    convert  \"$image\"  \"${image%.png}.jpg\"\r\n    echo \"image $image converted to ${image%.png}.jpg\"\r\n\r\n#disable debugging\r\nset +n\r\nexit 0\r\n<\/pre>\n<p>Once again, save the file and invoke the script:<\/p>\n<pre>$ .\/script.sh \r\n<\/pre>\n<p>In summary, we should always ensure that we syntactically check our shell scripts to capture any error before executing them.<\/p>\n<p>To send us any questions or feedback concerning this guide, use the response form below. In the third part of this series, we shall move to explaining and using shell tracing debugging mode.<\/p>\n<h1 class=\"post-title\">How to Trace Execution of Commands in Shell Script with Shell Tracing<\/h1>\n<p>In this article of the\u00a0<a href=\"https:\/\/www.tecmint.com\/enable-shell-debug-mode-linux\/\" target=\"_blank\" rel=\"noopener\">shell script debugging series<\/a>, we will explain the third shell script debugging mode, that is shell tracing and look at some examples to demonstrate how it works, and how it can be used.<\/p>\n<p>The previous part of this series clearly throws light upon the two other shell script debugging modes:\u00a0<strong>verbose mode<\/strong>\u00a0and\u00a0<strong>syntax checking<\/strong>\u00a0mode with easy-to-understand examples of how to enable shell script debugging in these modes.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/enable-shell-debug-mode-linux\/\" target=\"_blank\" rel=\"noopener\">How To Enable Shell Script Debugging Mode in Linux \u2013 Part 1<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/check-syntax-in-shell-script\/\" target=\"_blank\" rel=\"noopener\">How to Perform Syntax Checking Debugging Mode in Shell Scripts \u2013 Part 2<\/a><\/li>\n<\/ol>\n<p>Shell tracing simply means tracing the execution of the commands in a shell script. To switch on shell tracing, use the\u00a0<code>-x<\/code>\u00a0debugging option.<\/p>\n<p>This directs the shell to display all commands and their arguments on the terminal as they are executed.<\/p>\n<p>We will use the\u00a0<code>sys_info.sh<\/code>\u00a0shell script below, which briefly prints your system date and time, number of users logged in and the system uptime. However, it contains syntax errors that we need to find and correct.<\/p>\n<pre>#!\/bin\/bash\r\n#script to print brief system info\r\n\r\nROOT_ID=\"0\"\r\n\r\nDATE=`date`\r\nNO_USERS=`who | wc -l`\r\nUPTIME=`uptime`\r\n\r\ncheck_root(){\r\n    if [ \"$UID\" -ne \"$ROOT_ID\" ]; then\r\n        echo \"You are not allowed to execute this program!\"\r\n        exit 1;    \r\n}\r\n\r\nprint_sys_info(){\r\n    echo \"System Time    : $DATE\"\r\n    echo \"Number of users: $NO_USERS\"\r\n    echo \"System Uptime  : $UPTIME\r\n}\r\n\r\ncheck_root\r\nprint_sys_info\r\n\r\nexit 0\r\n<\/pre>\n<p>Save the file and make the script executable. The script can only be run by root, therefore employ the\u00a0<a href=\"https:\/\/www.tecmint.com\/su-vs-sudo-and-how-to-configure-sudo-in-linux\/\" target=\"_blank\" rel=\"noopener\">sudo command<\/a>\u00a0to run it as below:<\/p>\n<pre>$ chmod +x sys_info.sh\r\n$ sudo bash -x sys_info.sh\r\n<\/pre>\n<div id=\"attachment_23969\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Shell-Tracing-Errors.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23969\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Shell-Tracing-Errors.png\" alt=\"Shell Tracing - Show Error in Script\" width=\"730\" height=\"249\" aria-describedby=\"caption-attachment-23969\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23969\" class=\"wp-caption-text\">Shell Tracing \u2013 Show Error in Script<\/p>\n<\/div>\n<p>From the output above, we can observe that, a command is first executed before its output is substituted as the value of a variable.<\/p>\n<p>For example, the\u00a0<strong>date<\/strong>\u00a0was first executed and the its output was substituted as the value of the variable\u00a0<strong>DATE<\/strong>.<\/p>\n<p>We can perform syntax checking to only display the syntax errors as follows:<\/p>\n<pre>$ sudo bash -n sys_info.sh \r\n<\/pre>\n<div id=\"attachment_23970\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Syntax-Checking-in-Script.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23970\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Syntax-Checking-in-Script.png\" alt=\"Syntax Checking in Script\" width=\"609\" height=\"78\" aria-describedby=\"caption-attachment-23970\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23970\" class=\"wp-caption-text\">Syntax Checking in Script<\/p>\n<\/div>\n<p>If we look at the shell script critically, we will realize that the\u00a0<code>if statement<\/code>\u00a0is missing a closing\u00a0<code>fi<\/code>\u00a0word. Therefore, let us add it and the new script should now look like below:<\/p>\n<pre>#!\/bin\/bash\r\n#script to print brief system info\r\n\r\nROOT_ID=\"0\"\r\n\r\nDATE=`date`\r\nNO_USERS=`who | wc -l`\r\nUPTIME=`uptime`\r\n\r\ncheck_root(){\r\n    if [ \"$UID\" -ne \"$ROOT_ID\" ]; then\r\n        echo \"You are not allowed to execute this program!\"\r\n        exit 1;\r\n   fi    \r\n}\r\n\r\nprint_sys_info(){\r\n    echo \"System Time    : $DATE\"\r\n    echo \"Number of users: $NO_USERS\"\r\n    echo \"System Uptime  : $UPTIME\r\n}\r\n\r\ncheck_root\r\nprint_sys_info\r\n\r\nexit 0\r\n<\/pre>\n<p>Save the file again and invoke it as root and do some syntax checking:<\/p>\n<pre>$ sudo bash -n sys_info.sh\r\n<\/pre>\n<div id=\"attachment_23971\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Syntax-Check-in-Shell-Scripts.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23971\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Syntax-Check-in-Shell-Scripts.png\" alt=\"Perform Syntax Check in Shell Scripts\" width=\"681\" height=\"78\" aria-describedby=\"caption-attachment-23971\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23971\" class=\"wp-caption-text\">Perform Syntax Check in Shell Scripts<\/p>\n<\/div>\n<p>The result of our syntax checking operation above still shows that there is one more bug in our script on\u00a0<strong>line 21<\/strong>. So, we still have some syntax correction to do.<\/p>\n<p>If we look through the script analytically one more time, the error on\u00a0<strong>line 21<\/strong>\u00a0is due to a missing closing double quote\u00a0<code>(\u201d)<\/code>\u00a0in the last\u00a0<a href=\"https:\/\/www.tecmint.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">echo command<\/a>\u00a0inside the\u00a0<code>print_sys_info<\/code>\u00a0function.<\/p>\n<p>We will add the closing double quote in the\u00a0<strong>echo<\/strong>\u00a0command and save the file. The changed script is below:<\/p>\n<pre>#!\/bin\/bash\r\n#script to print brief system info\r\n\r\nROOT_ID=\"0\"\r\n\r\nDATE=`date`\r\nNO_USERS=`who | wc -l`\r\nUPTIME=`uptime`\r\n\r\ncheck_root(){\r\n    if [ \"$UID\" -ne \"$ROOT_ID\" ]; then\r\n        echo \"You are not allowed to execute this program!\"\r\n        exit 1;\r\n    fi\r\n}\r\n\r\nprint_sys_info(){\r\n    echo \"System Time    : $DATE\"\r\n    echo \"Number of users: $NO_USERS\"\r\n    echo \"System Uptime  : $UPTIME\"\r\n}\r\n\r\ncheck_root\r\nprint_sys_info\r\n\r\nexit 0\r\n<\/pre>\n<p>Now syntactically check the script one more time.<\/p>\n<pre>$ sudo bash -n sys_info.sh\r\n<\/pre>\n<p>The command above will not produce any output because our script is now syntactically correct. We can as well trace the execution of the script all for a second time and it should work well:<\/p>\n<pre>$ sudo bash -x sys_info.sh\r\n<\/pre>\n<div id=\"attachment_23972\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Trace-Shell-Execution.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23972\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Trace-Shell-Execution.png\" sizes=\"auto, (max-width: 773px) 100vw, 773px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Trace-Shell-Execution.png 773w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Trace-Shell-Execution-768x398.png 768w\" alt=\"Trace Shell Script Execution\" width=\"773\" height=\"401\" aria-describedby=\"caption-attachment-23972\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23972\" class=\"wp-caption-text\">Trace Shell Script Execution<\/p>\n<\/div>\n<p>Now run the script.<\/p>\n<pre>$ sudo .\/sys_info.sh\r\n<\/pre>\n<div id=\"attachment_23973\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Script-to-Show-Date-and-Uptime.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23973\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Script-to-Show-Date-and-Uptime.png\" sizes=\"auto, (max-width: 775px) 100vw, 775px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Script-to-Show-Date-and-Uptime.png 775w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Script-to-Show-Date-and-Uptime-768x96.png 768w\" alt=\"Shell Script to Show Date, Time and Uptime\" width=\"775\" height=\"97\" aria-describedby=\"caption-attachment-23973\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23973\" class=\"wp-caption-text\">Shell Script to Show Date, Time and Uptime<\/p>\n<\/div>\n<h3>Importance of Shell Script Execution Tracing<\/h3>\n<p>Shell script tracing helps us identify syntax errors and more importantly, logical errors. Take for instance the\u00a0<code>check_root<\/code>\u00a0function in the\u00a0<code>sys_info.sh<\/code>\u00a0shell script, which is intended to determine if a user is root or not, since the script is only allowed to be executed by the superuser.<\/p>\n<pre>check_root(){\r\n    if [ \"$UID\" -ne \"$ROOT_ID\" ]; then\r\n        echo \"You are not allowed to execute this program!\"\r\n        exit 1;\r\n    fi\r\n}\r\n<\/pre>\n<p>The magic here is controlled by the\u00a0<code>if statement<\/code>\u00a0expression\u00a0<code>[ \"$UID\" -ne \"$ROOT_ID\" ]<\/code>, once we do not use the suitable numerical operator (<code>-ne<\/code>\u00a0in this case, which means not equal ), we end up with a possible logical error.<\/p>\n<p>Assuming that we used\u00a0<code>-eq<\/code>\u00a0( means equal to), this would permit any system user as well as the root user to run the script, hence a logical error.<\/p>\n<pre>check_root(){\r\n    if [ \"$UID\" -eq \"$ROOT_ID\" ]; then\r\n        echo \"You are not allowed to execute this program!\"\r\n        exit 1;\r\n    fi\r\n}\r\n<\/pre>\n<p><strong>Note<\/strong>: As we looked at before at the start of this series, the set shell built-in command can activate debugging in a particular section of a shell script.<\/p>\n<p>Therefore, the line below will help us find this logical error in the function by tracing its execution:<\/p>\n<p>The script with a logical error:<\/p>\n<pre>#!\/bin\/bash\r\n#script to print brief system info\r\n\r\nROOT_ID=\"0\"\r\n\r\nDATE=`date`\r\nNO_USERS=`who | wc -l`\r\nUPTIME=`uptime`\r\n\r\ncheck_root(){\r\n    if [ \"$UID\" -eq \"$ROOT_ID\" ]; then\r\n        echo \"You are not allowed to execute this program!\"\r\n        exit 1;\r\n    fi\r\n}\r\n\r\nprint_sys_info(){\r\n    echo \"System Time    : $DATE\"\r\n    echo \"Number of users: $NO_USERS\"\r\n    echo \"System Uptime  : $UPTIME\"\r\n}\r\n\r\n#turning on and off debugging of check_root function\r\nset -x ; check_root;  set +x ;\r\nprint_sys_info\r\n\r\nexit 0\r\n<\/pre>\n<p>Save the file and invoke the script, we can see that a regular system user can run the script without\u00a0<strong>sudo<\/strong>\u00a0as in the output below. This is because the value of\u00a0<strong>USER_ID<\/strong>\u00a0is\u00a0<strong>100<\/strong>\u00a0which is not equal to root\u00a0<strong>ROOT_ID<\/strong>\u00a0which is\u00a0<strong>0<\/strong>.<\/p>\n<pre>$ .\/sys_info.sh\r\n<\/pre>\n<div id=\"attachment_23974\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Run-Shell-Script-Without-Sudo.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23974\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/12\/Run-Shell-Script-Without-Sudo.png\" alt=\"Run Shell Script Without Sudo\" width=\"722\" height=\"173\" aria-describedby=\"caption-attachment-23974\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23974\" class=\"wp-caption-text\">Run Shell Script Without Sudo<\/p>\n<\/div>\n<p>Well, that is it for now, we have come to the end of the\u00a0<a href=\"https:\/\/www.tecmint.com\/enable-shell-debug-mode-linux\/\" target=\"_blank\" rel=\"noopener\">shell script debugging series<\/a>, the response form below can be used to address any questions or feedback to us, concerning this guide or the whole 3-part series.<\/p>\n<h1 class=\"post-title\">How to Customize Bash Colors and Content in Linux Terminal Prompt<\/h1>\n<p>Today, Bash is the default shell in most (if not all) modern Linux distributions. However, you may have noticed that the text color in the terminal and the prompt content can be different from one distro to another.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/different-types-of-linux-shells\/\" target=\"_blank\" rel=\"noopener\">5 Most Frequently Used Open Source Shells for Linux<\/a><\/p>\n<p>In case you have been wondering how to customize this for better accessibility or mere whim, keep reading \u2013 in this article we will explain how to do just that.<\/p>\n<h3>The PS1 Bash Environment Variable<\/h3>\n<p>The command prompt and terminal appearance are governed by an environment variable called\u00a0<code>PS1<\/code>. According to the\u00a0<strong>Bash<\/strong>\u00a0man page,\u00a0<strong>PS1<\/strong>\u00a0represents the primary prompt string which is displayed when the shell is ready to read a command.<\/p>\n<p>The allowed content in\u00a0<strong>PS1<\/strong>\u00a0consists of several backslash-escaped special characters whose meaning is listed in the\u00a0<strong>PROMPTING<\/strong>\u00a0section of the man page.<\/p>\n<p>To illustrate, let\u2019s display the current content of\u00a0<code>PS1<\/code>\u00a0in our system (this may be somewhat different in your case):<\/p>\n<pre>$ echo $PS1\r\n\r\n<strong>[\\u@\\h \\W]$<\/strong>\r\n<\/pre>\n<p>We will now explain how to customize\u00a0<strong>PS1<\/strong>\u00a0as per our needs.<\/p>\n<h4>Customizing the PS1 Format<\/h4>\n<p>According to the PROMPTING section in the man page, this is the meaning of each special character:<\/p>\n<ol>\n<li><code>\\u:<\/code>\u00a0the\u00a0<strong>username<\/strong>\u00a0of the current user.<\/li>\n<li><code>\\h:<\/code>\u00a0the\u00a0<strong>hostname<\/strong>\u00a0up to the first dot\u00a0<strong>(.)<\/strong>\u00a0in the Fully-Qualified Domain Name.<\/li>\n<li><code>\\W:<\/code>\u00a0the\u00a0<strong>basename<\/strong>\u00a0of the current working directory, with\u00a0<strong>$HOME<\/strong>\u00a0abbreviated with a tilde\u00a0<strong>(~)<\/strong>.<\/li>\n<li><code>\\$:<\/code>\u00a0If the current user is root, display\u00a0<strong>#<\/strong>,\u00a0<strong>$<\/strong>\u00a0otherwise.<\/li>\n<\/ol>\n<p>For example, we may want to consider adding\u00a0<code>\\!<\/code>\u00a0If we want to display the history number of the current command, or\u00a0<code>\\H<\/code>\u00a0if we want to display the FQDN instead of the short server name.<\/p>\n<p>In the following example we will import both into our current environment by executing this command:<\/p>\n<pre>PS1=\"[\\u@\\H \\W \\!]$\"\r\n<\/pre>\n<p>When you press\u00a0<strong>Enter<\/strong>\u00a0you will see that the prompt content changes as shown below. Compare the prompt before and after executing the above command:<\/p>\n<div id=\"attachment_24043\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Customize-Linux-Terminal-Prompt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-24043\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Customize-Linux-Terminal-Prompt.png\" alt=\"Customize Linux Terminal Prompt PS1\" width=\"383\" height=\"83\" aria-describedby=\"caption-attachment-24043\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-24043\" class=\"wp-caption-text\">Customize Linux Terminal Prompt PS1<\/p>\n<\/div>\n<p>Now let\u2019s go one step further and change the color of the\u00a0<strong>user<\/strong>\u00a0and\u00a0<strong>hostname<\/strong>\u00a0in command prompt \u2013 both the text and its surrounding background.<\/p>\n<p>Actually, we can customize 3 aspects of the prompt:<\/p>\n<table border=\"0\" cellspacing=\"0\">\n<tbody>\n<tr>\n<td align=\"CENTER\" height=\"19\"><b>Text Format<\/b><\/td>\n<td align=\"CENTER\"><b>Foreground (text) color<\/b><\/td>\n<td align=\"CENTER\"><b>Background color<\/b><\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"CENTER\" height=\"16\">0: normal text<\/td>\n<td align=\"CENTER\">30: Black<\/td>\n<td align=\"CENTER\">40: Black<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"CENTER\" height=\"16\">1: bold<\/td>\n<td align=\"CENTER\">31: Red<\/td>\n<td align=\"CENTER\">41: Red<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"CENTER\" height=\"16\">4: Underlined text<\/td>\n<td align=\"CENTER\">32: Green<\/td>\n<td align=\"CENTER\">42: Green<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"CENTER\" height=\"16\"><\/td>\n<td align=\"CENTER\">33: Yellow<\/td>\n<td align=\"CENTER\">43: Yellow<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"CENTER\" height=\"16\"><\/td>\n<td align=\"CENTER\">34: Blue<\/td>\n<td align=\"CENTER\">44: Blue<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"CENTER\" height=\"16\"><\/td>\n<td align=\"CENTER\">35: Purple<\/td>\n<td align=\"CENTER\">45: Purple<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"CENTER\" height=\"16\"><\/td>\n<td align=\"CENTER\">36: Cyan<\/td>\n<td align=\"CENTER\">46: Cyan<\/td>\n<\/tr>\n<tr class=\"alt\">\n<td align=\"CENTER\" height=\"16\"><\/td>\n<td align=\"CENTER\">37: White<\/td>\n<td align=\"CENTER\">47: White<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>We will use the\u00a0<code>\\e<\/code>\u00a0special character at the beginning and an\u00a0<code>m<\/code>\u00a0at the end to indicate that what follows is a color sequence.<\/p>\n<p>In this sequence the three values (<strong>background<\/strong>,\u00a0<strong>format<\/strong>, and\u00a0<strong>foreground<\/strong>) are separated by commas (if no value is given the default is assumed).<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/category\/bash-shell\/\" target=\"_blank\" rel=\"noopener\">Learn Bash Shell Scripting in Linux<\/a><\/p>\n<p>Also, since the value ranges are different, it does not matter which one (<strong>background<\/strong>,\u00a0<strong>format<\/strong>, or\u00a0<strong>foreground<\/strong>) you specify first.<\/p>\n<p>For example, the following\u00a0<code>PS1<\/code>\u00a0will cause the prompt to appear in\u00a0<strong>yellow<\/strong>\u00a0underlined text with\u00a0<strong>red<\/strong>\u00a0background:<\/p>\n<pre>PS1=<strong>\"\\e[41;4;33m[\\u@\\h \\W]$ \"<\/strong>\r\n<\/pre>\n<div id=\"attachment_24044\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Change-Linux-Terminal-Color-Prompt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-24044\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/01\/Change-Linux-Terminal-Color-Prompt.png\" alt=\"Change Linux Terminal Color Prompt PS1\" width=\"487\" height=\"117\" aria-describedby=\"caption-attachment-24044\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-24044\" class=\"wp-caption-text\">Change Linux Terminal Color Prompt PS1<\/p>\n<\/div>\n<p>As good as it looks, this customization will only last for the current user session. If you close your terminal or exit the session, the changes will be lost.<\/p>\n<p>In order to make these changes permanent, you will have to add the following line to\u00a0<code>~\/.bashrc<\/code>\u00a0or\u00a0<code>~\/.bash_profile<\/code>\u00a0depending on your distribution:<\/p>\n<pre>PS1=<strong>\"\\e[41;4;33m[\\u@\\h \\W]$ \"<\/strong>\r\n<\/pre>\n<p>Feel free to play around with the colors to find what works best for you.<\/p>\n<h5>Summary<\/h5>\n<p>In this article we have explained how to customize the color and content of your Bash prompt. If you have questions or suggestions about this post, feel free to use the comment form below to reach us. We look forward to hearing from you!<\/p>\n<h1 class=\"post-title\">How To Write and Use Custom Shell Functions and Libraries<\/h1>\n<p>In Linux, shell scripts help us in so many different ways including performing or even\u00a0<a href=\"https:\/\/www.tecmint.com\/using-shell-script-to-automate-linux-system-maintenance-tasks\/\" target=\"_blank\" rel=\"noopener\">automating certain system administration tasks<\/a>, creating simple command line tools and many more.<\/p>\n<p>In this guide, we will show new Linux users where to reliably store custom shell scripts, explain how to write custom shell functions and libraries, use functions from libraries in other scripts.<\/p>\n<h3>Where to Store Shell Scripts<\/h3>\n<p>In order to run your scripts without typing a full\/absolute path, they must be stored in one of the directories in the\u00a0<strong>$PATH<\/strong>\u00a0environment variable.<\/p>\n<p>To check your\u00a0<strong>$PATH<\/strong>, issues the command below:<\/p>\n<pre><strong>$ echo $PATH<\/strong>\r\n\r\n\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin:\/usr\/games:\/usr\/local\/games\r\n<\/pre>\n<p>Normally, if the directory\u00a0<strong>bin<\/strong>\u00a0exists in a users home directory, it is automatically included in his\/her\u00a0<strong>$PATH<\/strong>. You can store your shell scripts here.<\/p>\n<p>Therefore, create the\u00a0<strong>bin<\/strong>\u00a0directory (which may also store\u00a0<strong>Perl<\/strong>,\u00a0<a href=\"https:\/\/www.tecmint.com\/use-linux-awk-command-to-filter-text-string-in-files\/\" target=\"_blank\" rel=\"noopener\">Awk<\/a>\u00a0or\u00a0<strong>Python<\/strong>\u00a0scripts or any other programs):<\/p>\n<pre>$ mkdir ~\/bin\r\n<\/pre>\n<p>Next, create a directory called\u00a0<strong>lib<\/strong>\u00a0(short for libraries) where you\u2019ll keep your own libraries. You can also keep libraries for other languages such as C, Python and so on, in it. Under it, create another directory called\u00a0<strong>sh<\/strong>; this will particularly store you shell libraries:<\/p>\n<pre>$ mkdir -p ~\/lib\/sh \r\n<\/pre>\n<h3>Create Your Own Shell Functions and Libraries<\/h3>\n<p>A\u00a0<strong>shell function<\/strong>\u00a0is a group of commands that perform a special task in a script. They work similarly to procedures, subroutines and functions in other programming languages.<\/p>\n<p>The syntax for writing a function is:<\/p>\n<pre>function_name() { list of commands }\r\n<\/pre>\n<p>For example, you can write a function in a script to show the\u00a0<strong>date<\/strong>\u00a0as follows:<\/p>\n<pre>showDATE() {date;}\r\n<\/pre>\n<p>Every time you want to display\u00a0<strong>date<\/strong>, simply invoke the function above using its name:<\/p>\n<pre>$ showDATE\r\n<\/pre>\n<p>A\u00a0<strong>shell library<\/strong>\u00a0is simply a shell script, however, you can write a library to only store your functions that you can later call from other shell scripts.<\/p>\n<p>Below is an example of a library called\u00a0<strong>libMYFUNCS.sh<\/strong>\u00a0in my\u00a0<strong>~\/lib\/sh<\/strong>\u00a0directory with more examples of functions:<\/p>\n<pre>#!\/bin\/bash \r\n\r\n#Function to clearly list directories in PATH \r\nshowPATH() { \r\n        oldifs=\"$IFS\"   #store old internal field separator\r\n        IFS=:              #specify a new internal field separator\r\n        for DIR in $PATH ;  do echo $DIR ;  done\r\n        IFS=\"$oldifs\"    #restore old internal field separator\r\n}\r\n\r\n#Function to show logged user\r\nshowUSERS() {\r\n        echo -e \u201cBelow are the user logged on the system:\\n\u201d\r\n        w\r\n}\r\n\r\n#Print a user\u2019s details \r\nprintUSERDETS() {\r\n        oldifs=\"$IFS\"    #store old internal field separator\r\n        IFS=:                 #specify a new internal field separator\r\n        read -p \"Enter user name to be searched:\" uname   #read username\r\n        echo \"\"\r\n       #read and store from a here string values into variables using : as  a  field delimiter\r\n    read -r username pass uid gid comments homedir shell &lt;&lt;&lt; \"$(cat \/etc\/passwd | grep   \"^$uname\")\"\r\n       #print out captured values\r\n        echo  -e \"Username is            : $username\\n\"\r\n        echo  -e \"User's ID                 : $uid\\n\"\r\n        echo  -e \"User's GID              : $gid\\n\"\r\n        echo  -e \"User's Comments    : $comments\\n\"\r\n        echo  -e \"User's Home Dir     : $homedir\\n\"\r\n        echo  -e \"User's Shell             : $shell\\n\"\r\n        IFS=\"$oldifs\"         #store old internal field separator\r\n}\r\n<\/pre>\n<p>Save the file and make the script executable.<\/p>\n<h3>How To Invoke Functions From a Library<\/h3>\n<p>To use a function in a\u00a0<strong>lib<\/strong>, you need to first of all include the\u00a0<strong>lib<\/strong>\u00a0in the shell script where the function will be used, in the form below:<\/p>\n<pre>$ .\/path\/to\/lib\r\nOR\r\n$ source \/path\/to\/lib\r\n<\/pre>\n<p>So you would use the function\u00a0<strong>printUSERDETS<\/strong>\u00a0from the lib\u00a0<strong>~\/lib\/sh\/libMYFUNCS.sh<\/strong>\u00a0in another script as shown below.<\/p>\n<p>You do not have to write another code in this script to print a particular user\u2019s details, simply call an existing function.<\/p>\n<p>Open a new file with the name\u00a0<strong>test.sh<\/strong>:<\/p>\n<pre>#!\/bin\/bash \r\n\r\n#include lib\r\n.  ~\/lib\/sh\/libMYFUNCS.sh\r\n\r\n#use function from lib\r\nprintUSERDETS\r\n\r\n#exit script\r\nexit 0\r\n<\/pre>\n<p>Save it, then make the script executable and run it:<\/p>\n<pre>$ chmod 755 test.sh\r\n$ .\/test.sh \r\n<\/pre>\n<div id=\"attachment_24494\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/02\/Write-Shell-Functions.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-24494\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/02\/Write-Shell-Functions.png\" alt=\"Write Shell Functions\" width=\"438\" height=\"306\" aria-describedby=\"caption-attachment-24494\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-24494\" class=\"wp-caption-text\">Write Shell Functions<\/p>\n<\/div>\n<p>In this article, we showed you where to reliably store shell scripts, how to write your own shell functions and libraries, invoke functions from libraries in normal shell scripts.<\/p>\n<p>Next, we will explain a straight forward way of configuring\u00a0<strong>Vim<\/strong>\u00a0as an\u00a0<strong>IDE<\/strong>\u00a0for Bash scripting. Until then, always stay connected to TecMint and also share your thoughts about this guide via the feedback form below.<\/p>\n<h1 class=\"post-title\">Understanding Shell Initialization Files and User Profiles in Linux<\/h1>\n<p>Linux is a multi-user, time sharing system, implying that more than one user can log in and use a system. And system administrators have the task of managing various aspects of how different users can operate a system in terms of\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-package-management\/\" target=\"_blank\" rel=\"noopener noreferrer\">installing\/updating\/removing software<\/a>, programs they can run, files they can view\/edit and so on.<\/p>\n<p>Linux also allows users\u2019 environments to be created or maintained in two major ways: using system-wide (global) and user-specific (personal) configurations. Normally, the basic method of working with a Linux system is the shell, and the shell creates an environment depending on certain files it reads during its initialization after a successful user login.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/set-unset-environment-variables-in-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to Set Environment Variables in Linux<\/a><\/p>\n<p>In this article, we will explain shell initialization files in relation to user profiles for local user management in Linux. We will let you know where to keep custom shell functions, aliases, variables as well as startup programs.<\/p>\n<p><strong>Important<\/strong>: For the purpose of this article, we will focus on\u00a0<strong>bash<\/strong>, a\u00a0<strong>sh<\/strong>\u00a0compatible shell which is the\u00a0<a href=\"https:\/\/www.tecmint.com\/different-types-of-linux-shells\/\" target=\"_blank\" rel=\"noopener noreferrer\">most popular\/used shell on Linux systems<\/a>\u00a0out there.<\/p>\n<p>If you are using a different shell (zsh, ash, fish etc..) program, read through its documentation to find out more about some of the related files we will talk about here.<\/p>\n<h3>Shell Initialization in Linux<\/h3>\n<p>When the shell is invoked, there are certain initialization\/startup files it reads which help to\u00a0<a href=\"https:\/\/www.tecmint.com\/set-unset-environment-variables-in-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">setup an environment for the shell<\/a>\u00a0itself and the system user; that is predefined (and customized) functions, variables, aliases and so on.<\/p>\n<p>There are two categories of initialization files read by the shell:<\/p>\n<ul>\n<li><strong>system-wide startup files<\/strong>\u00a0\u2013 theses contain global configurations that apply to all users on the system, and are usually located in the\u00a0<strong>\/etc<\/strong>\u00a0directory. They include:\u00a0<strong>\/etc\/profiles<\/strong>\u00a0and\u00a0<strong>\/etc\/bashrc<\/strong>\u00a0or\u00a0<strong>\/etc\/bash.bashrc<\/strong>.<\/li>\n<li><strong>user-specific startup files<\/strong>\u00a0\u2013 these store configurations that apply to a single user on the system and are normally located in the users home directory as dot files. They can override the system-wide configurations. They include:\u00a0<strong>.profiles<\/strong>,\u00a0<strong>.bash_profile<\/strong>,\u00a0<strong>.bashrc<\/strong>\u00a0and\u00a0<strong>.bash_login<\/strong>.<\/li>\n<\/ul>\n<p>Again, the shell can be invoked in three possible modes:<\/p>\n<h4>1. Interactive Login Shell<\/h4>\n<p>The shell is invoked after a user successfully login into the system, using\u00a0<strong>\/bin\/login<\/strong>, after reading credentials stored in the\u00a0<strong>\/etc\/passwd<\/strong>\u00a0file.<\/p>\n<p>When the shell is started as an interactive login shell, it reads the\u00a0<strong>\/etc\/profile<\/strong>\u00a0and its user-specific equivalent\u00a0<strong>~\/.bash_profile<\/strong>.<\/p>\n<div id=\"attachment_25429\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/interactive-login-shell.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25429\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/interactive-login-shell.png\" alt=\"Linux Interactive Login Shell\" width=\"485\" height=\"197\" aria-describedby=\"caption-attachment-25429\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25429\" class=\"wp-caption-text\">Linux Interactive Login Shell<\/p>\n<\/div>\n<h4>2. Interactive non-login Shell<\/h4>\n<p>The shell is started at the command-line using a shell program for example\u00a0<strong>$\/bin\/bash<\/strong>\u00a0or\u00a0<strong>$\/bin\/zsh<\/strong>. It can as well be started by running the\u00a0<strong>\/bin\/su<\/strong>\u00a0command.<\/p>\n<p>Additionally, an interactive non-login shell can as well be invoked with a terminal program such as\u00a0<strong>konsole<\/strong>,\u00a0<a href=\"https:\/\/www.tecmint.com\/terminator-a-linux-terminal-emulator-to-manage-multiple-terminal-windows\/\" target=\"_blank\" rel=\"noopener noreferrer\">terminator<\/a>\u00a0or\u00a0<a href=\"https:\/\/www.tecmint.com\/install-guake-terminal-ubuntu-mint-fedora\/\" target=\"_blank\" rel=\"noopener noreferrer\">xterm<\/a>\u00a0from within a graphical environment.<\/p>\n<p>When the shell is started in this state, it copies the environment of the parent shell, and reads the user-specific\u00a0<strong>~\/.bashrc<\/strong>\u00a0file for additional startup configuration instructions.<\/p>\n<pre>$ su\r\n# ls -la\r\n<\/pre>\n<div id=\"attachment_25430\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/su-command.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25430\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/su-command.png\" alt=\"Interactive Non-Login Shell\" width=\"703\" height=\"306\" aria-describedby=\"caption-attachment-25430\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25430\" class=\"wp-caption-text\">Interactive Non-Login Shell<\/p>\n<\/div>\n<h4>3. Non-interactive Shell<\/h4>\n<p>The shell is invoked when a shell script is running. In this mode, it\u2019s processing a script (set of shell or generic system commands\/functions) and doesn\u2019t require user input between commands unless otherwise. It operates using the environment inherited from the parent shell.<\/p>\n<h3>Understanding System-wide Shell Startup Files<\/h3>\n<p>In this section, we will shade more light on shell startup files that store configurations for all users on the system and these include:<\/p>\n<p>The\u00a0<strong>\/etc\/profile file<\/strong>\u00a0\u2013 it stores system-wide environment configurations and startup programs for login setup. All configurations that you want to apply to all system users\u2019 environments should be added in this file.<\/p>\n<p>For instance, you can set your the global PATH environment variable here.<\/p>\n<pre># cat \/etc\/profile\r\n<\/pre>\n<div id=\"attachment_25431\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/etc-profile-file.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25431\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/etc-profile-file.png\" alt=\"System Wide Configuration File\" width=\"703\" height=\"591\" aria-describedby=\"caption-attachment-25431\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25431\" class=\"wp-caption-text\">System Wide Configuration File<\/p>\n<\/div>\n<p><strong>Note<\/strong>: In certain systems like\u00a0<strong>RHEL\/CentOS 7<\/strong>, you\u2019ll get such warnings as \u201cIt\u2019s not recommended to change this file unless you know what you are doing. It\u2019s much better to create a custom\u00a0<strong>.sh<\/strong>\u00a0shell script in\u00a0<strong>\/etc\/profile.d\/<\/strong>\u00a0to make custom changes to your environment, as this will prevent the need for merging in future updates\u201d.<\/p>\n<p>The\u00a0<strong>\/etc\/profile.d\/<\/strong>\u00a0directory \u2013 stores shell scripts used to make custom changes to your environment:<\/p>\n<pre># cd \/etc\/profile.d\/\r\n# ls  -l \r\n<\/pre>\n<div id=\"attachment_25432\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/ls-l-custom-scripts.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25432\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/ls-l-custom-scripts.png\" alt=\"Stores Custom Shell Scripts\" width=\"600\" height=\"363\" aria-describedby=\"caption-attachment-25432\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25432\" class=\"wp-caption-text\">Stores Custom Shell Scripts<\/p>\n<\/div>\n<p>The\u00a0<strong>\/etc\/bashrc<\/strong>\u00a0or\u00a0<strong>\/etc\/bash.bashrc<\/strong>\u00a0file \u2013 contains system-wide functions and aliases including other configurations that apply to all system users.<\/p>\n<p>If your system has\u00a0<a href=\"https:\/\/www.tecmint.com\/different-types-of-linux-shells\/\" target=\"_blank\" rel=\"noopener noreferrer\">multiple types of shells<\/a>, it is a good idea to put bash-specific configurations in this file.<\/p>\n<pre># cat \/etc\/bashrc\r\n<\/pre>\n<div id=\"attachment_25433\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/etc-bashrc-file.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25433\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/etc-bashrc-file.png\" alt=\"System Wide Functions and Aliases\" width=\"702\" height=\"648\" aria-describedby=\"caption-attachment-25433\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25433\" class=\"wp-caption-text\">System Wide Functions and Aliases<\/p>\n<\/div>\n<h3>Understanding User-specific Shell Startup Files<\/h3>\n<p>Next, we will explain more concerning user-specific shell (bash) startup dot files, that store configurations for a particular user on the system, they are located in a user\u2019s home directory and they include:<\/p>\n<pre># ls -la\r\n<\/pre>\n<div id=\"attachment_25434\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/User-Specific-Configuration-Files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25434\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/User-Specific-Configuration-Files.png\" alt=\"User Specific Configuration Files\" width=\"700\" height=\"477\" aria-describedby=\"caption-attachment-25434\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25434\" class=\"wp-caption-text\">User Specific Configuration Files<\/p>\n<\/div>\n<p>The\u00a0<strong>~\/.bash_profile<\/strong>\u00a0file \u2013 this stores user specific environment and startup programs configurations. You can set your custom PATH environment variable here, as shown in the screenshot below:<\/p>\n<pre># cat ~\/.bash_profile\r\n<\/pre>\n<div id=\"attachment_25435\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/User-Bash-Profile.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25435\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/User-Bash-Profile.png\" alt=\"User Bash Profile\" width=\"518\" height=\"306\" aria-describedby=\"caption-attachment-25435\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25435\" class=\"wp-caption-text\">User Bash Profile<\/p>\n<\/div>\n<p>The\u00a0<strong>~\/.bashrc<\/strong>\u00a0file \u2013 this file stores user specific aliases and functions.<\/p>\n<pre># cat ~\/.bashrc\r\n<\/pre>\n<div id=\"attachment_25436\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/User-Bashrc-File.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25436\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/User-Bashrc-File.png\" alt=\"User Bashrc File\" width=\"418\" height=\"268\" aria-describedby=\"caption-attachment-25436\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25436\" class=\"wp-caption-text\">User Bashrc File<\/p>\n<\/div>\n<p>The\u00a0<strong>~\/.bash_login<\/strong>\u00a0file \u2013 it contains specific configurations that are normally only executed when you log in to the system. When the\u00a0<strong>~\/.bash_profile<\/strong>\u00a0is absent, this file will be read by bash.<\/p>\n<p>The\u00a0<strong>~\/.profile<\/strong>\u00a0file \u2013 this file is read in the absence of\u00a0<strong>~\/.bash_profile<\/strong>\u00a0and\u00a0<strong>~\/.bash_login<\/strong>; it can store the same configurations, which are can also be accessible by other shells on the system. Because we have mainly talked about bash here, take note that other shells might not understand the bash syntax.<\/p>\n<p>Next, we will also explain two other important user specific files which are not necessarily bash initialization files:<\/p>\n<p>The\u00a0<strong>~\/.bash_history<\/strong>\u00a0file \u2013 bash maintains a\u00a0<a href=\"https:\/\/www.tecmint.com\/history-command-examples\/\" target=\"_blank\" rel=\"noopener noreferrer\">history of commands<\/a>\u00a0that have been entered by a user on the system. This list of commands is kept in a user\u2019s home directory in the\u00a0<strong>~\/.bash_history<\/strong>\u00a0file.<\/p>\n<p>To view this list, type:<\/p>\n<pre>$ history \r\nor \r\n$ history | less\r\n<\/pre>\n<div id=\"attachment_25438\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/List-Last-Executed-Commands.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25438\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/List-Last-Executed-Commands.png\" alt=\"View Last Executed Commands\" width=\"680\" height=\"230\" aria-describedby=\"caption-attachment-25438\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25438\" class=\"wp-caption-text\">View Last Executed Commands<\/p>\n<\/div>\n<p>The\u00a0<strong>~\/.bash_logout<\/strong>\u00a0file \u2013 it\u2019s not used for shell startup, but stores user specific instructions for the logout procedure. It is read and executed when a user exits from an interactive login shell.<\/p>\n<p>One practical example would by clearing the terminal window upon logout. This is important for remote connections, which will leave a clean window after closing them:<\/p>\n<pre># cat bash_logout \r\n<\/pre>\n<div id=\"attachment_25439\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/Clear-History-After-Logout.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25439\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/Clear-History-After-Logout.png\" alt=\"Clear History After Logout\" width=\"376\" height=\"116\" aria-describedby=\"caption-attachment-25439\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25439\" class=\"wp-caption-text\">Clear History After Logout<\/p>\n<\/div>\n<p>For additional insights, checkout the contents of these shell initialization files on various Linux distros and also read through the bash man page:<\/p>\n<p>That\u2019s all for now! In this article, we explained shell startup\/initialization files in Linux. Use the comment form below to write back to us.<\/p>\n<h1 class=\"post-title\">ShellCheck \u2013 A Tool That Shows Warnings and Suggestions for Shell Scripts<\/h1>\n<p><strong>ShellCheck<\/strong>\u00a0is a static analysis tool that shows warnings and suggestions concerning bad code in bash\/sh shell scripts. It can be used in several ways: from the web by pasting your shell script in an online editor (Ace \u2013 a standalone code editor written in JavaScript) in\u00a0<a href=\"https:\/\/www.shellcheck.net\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https:\/\/www.shellcheck.net<\/a>\u00a0(it is always synchronized to the latest git commit, and is the simplest way to give ShellCheck a go) for instant feedback.<\/p>\n<p>Alternatively, you can install it on your machine and run it from the terminal, integrate it with your text editor as well as in your build or test suites.<\/p>\n<p>There are three things ShellCheck does primarily:<\/p>\n<ul>\n<li>It points out and explains typical beginner\u2019s syntax issues that cause a shell to give cryptic error messages.<\/li>\n<li>It points out and explains typical intermediate level semantic problems that cause a shell to behave strangely and counter-intuitively.<\/li>\n<li>It also points out subtle caveats, corner cases and pitfalls that may cause an advanced user\u2019s otherwise working script to fail under future circumstances.<\/li>\n<\/ul>\n<p>In this article, we will show how to install and use ShellCheck in the various ways to find bugs or bad code in your shell scripts in Linux.<\/p>\n<h3>How to Install and Use ShellCheck in Linux<\/h3>\n<p><strong>ShellCheck<\/strong>\u00a0can be easily installed locally through your package manager as shown.<\/p>\n<h4>On Debian\/Ubuntu<\/h4>\n<pre># apt-get install shellcheck\r\n<\/pre>\n<h4>On RHEL\/CentOS<\/h4>\n<pre># yum -y install epel-release\r\n# yum install ShellCheck\r\n<\/pre>\n<h4>On Fedora<\/h4>\n<pre># dnf install ShellCheck\r\n<\/pre>\n<p>Once ShellCheck installed, let\u2019s take a look at how to use ShellCheck in the various methods we mentioned before.<\/p>\n<h4>Using ShellCheck From the Web<\/h4>\n<p>Go to\u00a0<a href=\"https:\/\/www.shellcheck.net\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https:\/\/www.shellcheck.net<\/a>\u00a0and paste your script in the Ace editor provided, you will view the output at the bottom of the editor as shown in the screen shot below.<\/p>\n<p>In the following example, the test shell script consists of the following lines:<\/p>\n<pre>#!\/bin\/bash\r\n#declare variables\r\nMINARGS=2\r\nE_NOTROOT=50\r\nE_MINARGS=100\r\n  \r\n#echo values of variables \r\necho $MINARGS\r\necho $E_NONROOT\r\nexit 0;\r\n<\/pre>\n<div id=\"attachment_25446\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/ShellCheck-Script-Analysis-Tool.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25446\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/ShellCheck-Script-Analysis-Tool.png\" sizes=\"auto, (max-width: 1101px) 100vw, 1101px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/ShellCheck-Script-Analysis-Tool.png 1101w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/ShellCheck-Script-Analysis-Tool-768x617.png 768w\" alt=\"ShellCheck - Online Shell Script Analysis Tool\" width=\"1101\" height=\"884\" aria-describedby=\"caption-attachment-25446\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25446\" class=\"wp-caption-text\">ShellCheck \u2013 Online Shell Script Analysis Tool<\/p>\n<\/div>\n<p>From the screenshot above, the first two variables\u00a0<strong>E_NOTROOT<\/strong>\u00a0and\u00a0<strong>E_MINARGS<\/strong>\u00a0have been declared but are unused, ShellCheck reports these as \u201csuggestive errors\u201d:<\/p>\n<pre>SC2034: E_NOTROOT appears unused. Verify it or export it.\r\nSC2034: E_MINARGS appears unused. Verify it or export it. \r\n<\/pre>\n<p>Then secondly, the wrong name (in the statement\u00a0<strong>echo $E_NONROOT<\/strong>) was used to\u00a0<strong>echo variable E_NOTROOT<\/strong>, that is why ShellCheck shows the error:<\/p>\n<pre>SC2153: Possible misspelling: E_NONROOT may not be assigned, but E_NOTROOT is\r\n<\/pre>\n<p>Again when you look at the\u00a0<a href=\"https:\/\/www.tecmint.com\/echo-command-in-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">echo commands<\/a>, the variables have not been double quoted (helps to prevent globbing and word splitting), therefore Shell Check shows the warning:<\/p>\n<pre>SC2086: Double quote to prevent globbing and word splitting.\r\n<\/pre>\n<h4>Using ShellCheck From the Terminal<\/h4>\n<p>You can also run ShellCheck from the command-line, we\u2019ll use the same shell script above as follows:<\/p>\n<pre>$ shellcheck test.sh\r\n<\/pre>\n<div id=\"attachment_25447\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/ShellCheck-Check-Shell-Script.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25447\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/ShellCheck-Check-Shell-Script.png\" sizes=\"auto, (max-width: 874px) 100vw, 874px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/ShellCheck-Check-Shell-Script.png 874w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/ShellCheck-Check-Shell-Script-768x302.png 768w\" alt=\"ShellCheck - Checks Bad Code in Shell Scripts\" width=\"874\" height=\"344\" aria-describedby=\"caption-attachment-25447\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25447\" class=\"wp-caption-text\">ShellCheck \u2013 Checks Bad Code in Shell Scripts<\/p>\n<\/div>\n<h4>Using ShellCheck From the Text Editor<\/h4>\n<p>You can also view\u00a0<strong>ShellCheck<\/strong>\u00a0suggestions and warnings directly in a variety of editors, this is probably a more efficient way of using ShellCheck, once you save a files, it shows you any errors in the code.<\/p>\n<p>In\u00a0<strong>Vim<\/strong>, use ALE or Syntastic (we will use this):<\/p>\n<p>Start by installing\u00a0<strong>Pathogen<\/strong>\u00a0so that it\u2019s easy to install syntastic. Run the commands below to get the\u00a0<strong>pathogen.vim<\/strong>\u00a0file and the directories it needs:<\/p>\n<pre># mkdir -p ~\/.vim\/autoload ~\/.vim\/bundle &amp;&amp; curl -LSso ~\/.vim\/autoload\/pathogen.vim https:\/\/tpo.pe\/pathogen.vim\r\n<\/pre>\n<p>Then add this to your\u00a0<strong>~\/.vimrc<\/strong>\u00a0file:<\/p>\n<pre>execute pathogen#infect()\r\n<\/pre>\n<p>Once you have installed pathogen, and you now can put syntastic into\u00a0<strong>~\/.vim\/bundle<\/strong>\u00a0as follows:<\/p>\n<pre># cd ~\/.vim\/bundle &amp;&amp; git clone --depth=1 https:\/\/github.com\/vim-syntastic\/syntastic.git\r\n<\/pre>\n<p>Next, close vim and start it back up to reload it, then type the command below:<\/p>\n<pre>:Helptags\r\n<\/pre>\n<p>If all goes well, you should have\u00a0<strong>ShellCheck<\/strong>\u00a0integrated with\u00a0<strong>Vim<\/strong>, the following screenshots show how it works using the same script above.<\/p>\n<div id=\"attachment_25448\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/Check-Bad-Shell-Script-Code-in-Vim.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25448\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/Check-Bad-Shell-Script-Code-in-Vim.png\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/Check-Bad-Shell-Script-Code-in-Vim.png 900w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/04\/Check-Bad-Shell-Script-Code-in-Vim-768x320.png 768w\" alt=\"Check Bad Shell Script Code in Vim\" width=\"900\" height=\"375\" aria-describedby=\"caption-attachment-25448\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25448\" class=\"wp-caption-text\">Check Bad Shell Script Code in Vim<\/p>\n<\/div>\n<p>In case you get an error after following the steps above, then you possibly didn\u2019t install\u00a0<strong>Pathogen<\/strong>\u00a0correctly. Redo the steps but this ensure that you did the following:<\/p>\n<ul>\n<li>Created both the\u00a0<strong>~\/.vim\/autoload<\/strong>\u00a0and\u00a0<strong>~\/.vim\/bundle<\/strong>\u00a0directories.<\/li>\n<li>Added the execute pathogen#infect() line to your\u00a0<strong>~\/.vimrc<\/strong>\u00a0file.<\/li>\n<li>Did the git clone of syntastic inside\u00a0<strong>~\/.vim\/bundle<\/strong>.<\/li>\n<li>Use appropriate permissions to access all of the above directories.<\/li>\n<\/ul>\n<p>You can also use other editors to check bad code in shell scripts like:<\/p>\n<ul>\n<li>In\u00a0<strong>Emacs<\/strong>, use\u00a0<strong>Flycheck<\/strong>.<\/li>\n<li>In\u00a0<a href=\"https:\/\/www.tecmint.com\/install-sublime-text-editor-in-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">Sublime<\/a>, employ SublimeLinter.<\/li>\n<li>In\u00a0<a href=\"https:\/\/www.tecmint.com\/atom-text-and-source-code-editor-for-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">Atom<\/a>, make use of Linter.<\/li>\n<li>In most other editors, use GCC error compatibility.<\/li>\n<\/ul>\n<p><strong>Note<\/strong>: Use the gallery of bad code to carry out more ShellChecking.<\/p>\n<p>ShellCheck Github Repository:\u00a0<a href=\"https:\/\/github.com\/koalaman\/shellcheck\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https:\/\/github.com\/koalaman\/shellcheck<\/a><\/p>\n<p>That\u2019s it! In this article, we showed how to install and use\u00a0<strong>ShellCheck<\/strong>\u00a0to finds bugs or bad code in your shell scripts in Linux. Share your thoughts with us via the comment section below.<\/p>\n<p>Do you know of any other similar tools out there? If yes, then share info about them in the comments as well.<\/p>\n<h1 class=\"post-title\">10 Useful Tips for Writing Effective Bash Scripts in Linux<\/h1>\n<p><a href=\"https:\/\/www.tecmint.com\/category\/bash-shell\/\" target=\"_blank\" rel=\"noopener noreferrer\">Shell scripting<\/a>\u00a0is the easiest form of programming you can learn\/do in Linux. More so, it is a required skill for\u00a0<a href=\"https:\/\/www.tecmint.com\/using-shell-script-to-automate-linux-system-maintenance-tasks\/\" target=\"_blank\" rel=\"noopener noreferrer\">system administration for automating tasks<\/a>, developing new simple utilities\/tools just to mention but a few.<\/p>\n<p>In this article, we will share 10 useful and practical tips for writing effective and reliable bash scripts and they include:<\/p>\n<h3>1. Always Use Comments in Scripts<\/h3>\n<p>This is a recommended practice which is not only applied to shell scripting but all other kinds of programming. Writing comments in a script helps you or some else going through your script understand what the different parts of the script do.<\/p>\n<p>For starters, comments are defined using the\u00a0<code>#<\/code>\u00a0sign.<\/p>\n<pre>#TecMint is the best site for all kind of Linux articles\r\n<\/pre>\n<h3>2. Make a Script exit When Fails<\/h3>\n<p>Sometimes bash may continue to execute a script even when a certain command fails, thus affecting the rest of the script (may eventually result in logical errors). Use the line below to exit a script when a command fails:<\/p>\n<pre>#let script exit if a command fails\r\nset -o errexit \r\nOR\r\nset -e\r\n<\/pre>\n<h3>3. Make a Script exit When Bash Uses Undeclared Variable<\/h3>\n<p>Bash may also try to use an undeclared script which could cause a logical error. Therefore use the following line to instruct bash to exit a script when it attempts to use an undeclared variable:<\/p>\n<pre>#let script exit if an unsed variable is used\r\nset -o nounset\r\nOR\r\nset -u\r\n<\/pre>\n<h3>4. Use Double Quotes to Reference Variables<\/h3>\n<p>Using double quotes while referencing (using a value of a variable) helps to prevent word splitting (regarding whitespace) and unnecessary globbing (recognizing and expanding wildcards).<\/p>\n<p>Check out the example below:<\/p>\n<pre>#!\/bin\/bash\r\n#let script exit if a command fails\r\nset -o errexit \r\n\r\n#let script exit if an unsed variable is used\r\nset -o nounset\r\n\r\necho \"Names without double quotes\" \r\necho\r\nnames=\"Tecmint FOSSMint Linusay\"\r\nfor name in $names; do\r\n        echo \"$name\"\r\ndone\r\necho\r\n\r\necho \"Names with double quotes\" \r\necho\r\nfor name in \"$names\"; do\r\n        echo \"$name\"\r\ndone\r\n\r\nexit 0\r\n<\/pre>\n<p>Save the file and exit, then run it as follows:<\/p>\n<pre>$ .\/names.sh\r\n<\/pre>\n<div id=\"attachment_25667\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/05\/Use-Double-Quotes-in-Scripts.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25667\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/05\/Use-Double-Quotes-in-Scripts.png\" alt=\"Use Double Quotes in Scripts\" width=\"588\" height=\"211\" aria-describedby=\"caption-attachment-25667\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25667\" class=\"wp-caption-text\">Use Double Quotes in Scripts<\/p>\n<\/div>\n<h3>5. Use functions in Scripts<\/h3>\n<p>Except for very small scripts (with a few lines of code), always remember to use functions to modularize your code and make scripts more readable and reusable.<\/p>\n<p>The syntax for writing functions is as follows:<\/p>\n<pre>function check_root(){\r\n\tcommand1; \r\n\tcommand2;\r\n}\r\n\r\nOR\r\ncheck_root(){\r\n\tcommand1; \r\n\tcommand2;\r\n}\r\n<\/pre>\n<p>For single line code, use termination characters after each command like this:<\/p>\n<pre>check_root(){ command1; command2; }\r\n<\/pre>\n<h3>6. Use = instead of == for String Comparisons<\/h3>\n<p>Note that\u00a0<code>==<\/code>\u00a0is a synonym for\u00a0<code>=<\/code>, therefore only use a single\u00a0<code>=<\/code>\u00a0for string comparisons, for instance:<\/p>\n<pre>value1=\u201dtecmint.com\u201d\r\nvalue2=\u201dfossmint.com\u201d\r\nif [ \"$value1\" = \"$value2\" ]\r\n<\/pre>\n<h3>7. Use $(command) instead of legacy \u2018command\u2019 for Substitution<\/h3>\n<p><a href=\"https:\/\/www.tecmint.com\/assign-linux-command-output-to-variable\/\" target=\"_blank\" rel=\"noopener noreferrer\">Command substitution<\/a>\u00a0replaces a command with its output. Use\u00a0<code>$(command)<\/code>\u00a0instead of backquotes\u00a0<code>`command`<\/code>\u00a0for command substitution.<\/p>\n<p>This is recommended even by\u00a0<a href=\"https:\/\/www.tecmint.com\/shellcheck-shell-script-code-analyzer-for-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">shellcheck tool<\/a>\u00a0(shows warnings and suggestions for shell scripts). For example:<\/p>\n<pre>user=`echo \u201c$UID\u201d`\r\nuser=$(echo \u201c$UID\u201d)\r\n<\/pre>\n<h3>8. Use Read-only to Declare Static Variables<\/h3>\n<p>A static variable doesn\u2019t change; its value can not be altered once it\u2019s defined in a script:<\/p>\n<pre>readonly passwd_file=\u201d\/etc\/passwd\u201d\r\nreadonly group_file=\u201d\/etc\/group\u201d\r\n<\/pre>\n<h3>9. Use Uppercase Names for ENVIRONMENT Variables and Lowercase for Custom Variables<\/h3>\n<p>All bash environment variables are named with uppercase letters, therefore use lowercase letters to name your custom variables to avoid variable name conflicts:<\/p>\n<pre>#define custom variables using lowercase and use uppercase for env variables\r\nnikto_file=\u201d$HOME\/Downloads\/nikto-master\/program\/nikto.pl\u201d\r\nperl \u201c$nikto_file\u201d -h  \u201c$1\u201d\r\n<\/pre>\n<h3>10. Always Perform Debugging for Long Scripts<\/h3>\n<p>If you are writing bash scripts with thousands of lines of code, finding errors may become a nightmare. To easily fix things before executing a script, perform some debugging. Master this tip by reading through the guides provided below:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/enable-shell-debug-mode-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Enable Shell Script Debugging Mode in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/check-syntax-in-shell-script\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to Perform Syntax Checking Debugging Mode in Shell Scripts<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/trace-shell-script-execution-in-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to Trace Execution of Commands in Shell Script with Shell Tracing<\/a><\/li>\n<\/ol>\n<p>That\u2019s all! Do you have any other best bash scripting practices to share? If yes, then use the comment form below to do that.<\/p>\n<h1 class=\"post-title\">How to Install and Enable Bash Auto Completion in CentOS\/RHEL<\/h1>\n<p><strong>Bash<\/strong>\u00a0(<strong>Bourne Again Shell<\/strong>) is undoubtedly the\u00a0<a href=\"https:\/\/www.tecmint.com\/different-types-of-linux-shells\/\" target=\"_blank\" rel=\"noopener\">most popular Linux shell<\/a>\u00a0out there, no wonder it is the default shell on many Linux distributions. One of its most charming features is the built-in \u201c<strong>auto-completion<\/strong>\u201d support.<\/p>\n<p>Sometimes referred to as\u00a0<strong>TAB<\/strong>\u00a0completion, this feature permits you to easily complete a command structure. It allows typing a partial command, then pressing the\u00a0<strong>[Tab]<\/strong>\u00a0key to auto-complete the command and it arguments. It lists all multiple completions, where possible.<\/p>\n<p>Just like\u00a0<strong>Bash<\/strong>, nearly all modern Linux shells ship in with command completion support. In this short guide, we will show you how to turn on the Bash auto-completion feature in CentOS and RHEL systems.<\/p>\n<p>To make working on the command line super easy for you, this is one of the many things you ought to do while performing:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/rhel-7-initial-server-setup-and-configurations\/\" target=\"_blank\" rel=\"noopener\">Initial Server Setup and Configurations on RHEL 7<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/centos-7-initial-server-setup-and-configuration\/\" target=\"_blank\" rel=\"noopener\">Initial Server Setup and Configurations on CentOS 7<\/a><\/li>\n<\/ol>\n<p>First, you need to enable the\u00a0<strong>EPEL<\/strong>\u00a0repository on your system, then install the\u00a0<strong>bash-completion<\/strong>\u00a0package plus some extras using\u00a0<a href=\"https:\/\/www.tecmint.com\/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement\/\" target=\"_blank\" rel=\"noopener\">YUM package manager<\/a>, like this.<\/p>\n<pre># yum install bash-completion bash-completion-extras\r\n<\/pre>\n<p>Now that you have installed\u00a0<strong>bash completion<\/strong>, you should enable it to start working. First source the\u00a0<strong>bash_completion.sh<\/strong>\u00a0file. You can use the\u00a0<a href=\"https:\/\/www.tecmint.com\/install-locate-command-to-find-files-in-centos\/\" target=\"_blank\" rel=\"noopener\">locate command<\/a>\u00a0below to find it:<\/p>\n<pre>$ locate bash_completion.sh\r\n$ source \/etc\/profile.d\/bash_completion.sh  \r\n<\/pre>\n<div id=\"attachment_27932\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/find-and-source-bash_completion-file.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27932\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/find-and-source-bash_completion-file.png\" alt=\"Find and Source Bash-Completion\" width=\"732\" height=\"78\" aria-describedby=\"caption-attachment-27932\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27932\" class=\"wp-caption-text\">Find and Source Bash-Completion<\/p>\n<\/div>\n<p>Alternatively, logout of your current login current session and re-login.<\/p>\n<pre>$ logout \r\n<\/pre>\n<p>Now the\u00a0<strong>auto-completion<\/strong>\u00a0feature should be working on your system, you can try it out as shown below.<\/p>\n<pre>$ lo[TAB]\r\n$ ls .bash[TAB]\r\n<\/pre>\n<div id=\"attachment_27931\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/test-auto-completion-feature.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27931\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/test-auto-completion-feature.png\" alt=\"Check Bash Auto-Completion\" width=\"672\" height=\"173\" aria-describedby=\"caption-attachment-27931\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27931\" class=\"wp-caption-text\">Check Bash Auto-Completion<\/p>\n<\/div>\n<p><strong>Note<\/strong>:\u00a0<strong>TAB<\/strong>\u00a0completion works for path names and variables names as well, and it is programmable.<\/p>\n<p>That\u2019s all! In this guide, we showed how to install and enable the Bash auto-completion feature, also known as\u00a0<strong>TAB<\/strong>\u00a0completion in CentOS\/RHEL. You can ask any questions via the comment section below.<\/p>\n<h1 class=\"post-title\">A Shell Script to Send Email Alert When Memory Gets Low<\/h1>\n<p>A powerful aspect of Unix\/Linux shell programs such as\u00a0<strong>bash<\/strong>, is their amazing support for common programming constructs that enable you to make decisions, execute commands repeatedly, create new functions, and so much more. You can write commands in a file known as a shell script and execute them collectively.<\/p>\n<p>This offers you a reliable and effective means of system administration. You can write\u00a0<a href=\"https:\/\/www.tecmint.com\/using-shell-script-to-automate-linux-system-maintenance-tasks\/\" target=\"_blank\" rel=\"noopener\">scripts to automate tasks<\/a>, for instance daily back ups, system updates etc; create new custom commands\/utilities\/tools and beyond. You can write scripts to help you keep up with what\u2019s unfolding on a server.<\/p>\n<p>One of the critical components of a server is memory (<strong>RAM<\/strong>), it greatly impacts on overall performance of a system.<\/p>\n<p>In this article, we will share a small but useful shell script to send an alert email to one or more system administrator(s), if server memory is running low.<\/p>\n<p>This is script is particularly useful for keeping an eye on\u00a0<strong>Linux VPS<\/strong>\u00a0(<strong>Virtual Private Servers<\/strong>) with small amount of memory, say of about\u00a0<strong>1GB<\/strong>\u00a0(approximately\u00a0<strong>990MB<\/strong>).<\/p>\n<h4>Testing Environment Setup<\/h4>\n<ol>\n<li>A\u00a0<strong>CentOS\/RHEL 7<\/strong>\u00a0production server with\u00a0<strong>mailx<\/strong>\u00a0utility installed with working\u00a0<a href=\"https:\/\/www.tecmint.com\/setup-postfix-mail-server-and-dovecot-with-mariadb-in-centos\/\" target=\"_blank\" rel=\"noopener\">postfix mail server<\/a>.<\/li>\n<\/ol>\n<p>This is how the\u00a0<strong>alertmemory.sh<\/strong>\u00a0script works: first it checks the free memory size, then determines if amount of free memory is less or equal to a specified size (<strong>100<\/strong>\u00a0MB for the purpose of this guide), used as a bench mark for the least acceptable free memory size.<\/p>\n<p>If this condition is true, it will generate a list of the\u00a0<a href=\"https:\/\/www.tecmint.com\/find-linux-processes-memory-ram-cpu-usage\/\" target=\"_blank\" rel=\"noopener\">top 10 processes consuming server RAM<\/a>\u00a0and sends an alert email to specified email addresses.<\/p>\n<p><strong>Note<\/strong>: You will have to make a few changes to script (especially the mail sender utility, use the appropriate flags) to meet your Linux distributions requirements.<\/p>\n<div class=\"code-label\">Shell Script to Check Server Memory<\/div>\n<pre>#!\/bin\/bash \r\n#######################################################################################\r\n#Script Name    :alertmemory.sh\r\n#Description    :send alert mail when server memory is running low\r\n#Args           :       \r\n#Author         :Aaron Kili Kisinga\r\n#Email          :aaronkilik@gmail.com\r\n#License       : GNU GPL-3\t\r\n#######################################################################################\r\n## declare mail variables\r\n##email subject \r\nsubject=\"<strong>Server Memory Status Alert<\/strong>\"\r\n##sending mail as\r\nfrom=\"<strong>server.monitor@example.com<\/strong>\"\r\n## sending mail to\r\nto=\"<strong>admin1@example.com<\/strong>\"\r\n## send carbon copy to\r\nalso_to=\"<strong>admin2@example.com<\/strong>\"\r\n\r\n## get total free memory size in megabytes(MB) \r\nfree=$(free -mt | grep Total | awk '{print $4}')\r\n\r\n## check if free memory is less or equals to  <strong>100MB<\/strong>\r\nif [[ \"$free\" -le <strong>100<\/strong>  ]]; then\r\n        ## get top processes consuming system memory and save to temporary file \r\n        ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head &gt;\/tmp\/top_proccesses_consuming_memory.txt\r\n\r\n        file=\/tmp\/top_proccesses_consuming_memory.txt\r\n        ## send email if system memory is running low\r\n        echo -e \"Warning, server memory is running low!\\n\\nFree memory: $free MB\" | mailx -a \"$file\" -s \"$subject\" -r \"$from\" -c \"$to\" \"$also_to\"\r\nfi\r\n\r\nexit 0\r\n<\/pre>\n<p>After creating your script\u00a0<strong>\/etc\/scripts\/alertmemory.sh<\/strong>, make it executable and symlink to cron.hourly.<\/p>\n<pre># chmod +x \/etc\/scripts\/alertmemory.sh\r\n# ln -s -t \/etc\/cron.hourly\/alertmemory.sh \/etc\/scripts\/alertmemory.sh\r\n<\/pre>\n<p>This means that the above script will be run after every 1 hour as long as the server is running.<\/p>\n<p><strong>Tip<\/strong>: You can test if it is working as intended, set the bench mark value a little high to easily trigger an email to be sent, and specify a small interval of about 5 minutes.<\/p>\n<p>Then keep on checking from the command line using the\u00a0<a href=\"https:\/\/www.tecmint.com\/check-memory-usage-in-linux\/\" target=\"_blank\" rel=\"noopener\">free command<\/a>\u00a0provided in the script. Once you confirm that it is working, define the actual values you would like to use.<\/p>\n<p>Below is a screenshot showing a sample alert email.<\/p>\n<div id=\"attachment_28059\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Linux-Memory-Email-Alert.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28059\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/11\/Linux-Memory-Email-Alert.png\" alt=\"Linux Memory Email Alert\" width=\"707\" height=\"484\" aria-describedby=\"caption-attachment-28059\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28059\" class=\"wp-caption-text\">Linux Memory Email Alert<\/p>\n<\/div>\n<p>That\u2019s all! In this article, we explained how to use shell script to send alert emails to system administrators in case server memory (RAM) is running low. You can share any thoughts relating to this topic, with us via the feedback form below.<\/p>\n<h1 class=\"post-title\">How to Create Custom Header Template for Shell Scripts in Vim<\/h1>\n<p>In this article, we will show you a simple way to configure a custom header for all newly created bash scripts in\u00a0<a href=\"https:\/\/www.tecmint.com\/learn-vi-and-vim-editor-tips-and-tricks-in-linux\/\" target=\"_blank\" rel=\"noopener\">Vim editor<\/a>. This means that every time you open a new\u00a0<code>.sh<\/code>\u00a0file using vi\/vim editor, the custom header will be automatically added to the file.<\/p>\n<h3>How to Create Custom Bash Script Header Template File<\/h3>\n<p>First start by creating the template file called\u00a0<strong>sh_header.temp<\/strong>, which contains your custom bash script header, possibly under\u00a0<code>~\/.vim\/<\/code>\u00a0directory under your home.<\/p>\n<pre>$ vi ~\/.vim\/sh_header.temp\r\n<\/pre>\n<p>Next add the following lines in it (feel free to set your own template file location and custom header) and save the file.<\/p>\n<div class=\"code-label\">Custom Header Template for Scripts<\/div>\n<pre>#!\/bin\/bash \r\n\r\n###################################################################\r\n#Script Name\t:                                                                                              \r\n#Description\t:                                                                                 \r\n#Args           \t:                                                                                           \r\n#Author       \t:Aaron Kili Kisinga                                                \r\n#Email         \t:aaronkilik@gmail.com                                           \r\n###################################################################\r\n<\/pre>\n<div id=\"attachment_28548\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/02\/Create-Custom-Header-Template-for-Scripts.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28548\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/02\/Create-Custom-Header-Template-for-Scripts.png\" alt=\"Create Custom Header Template for Scripts\" width=\"508\" height=\"234\" aria-describedby=\"caption-attachment-28548\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28548\" class=\"wp-caption-text\">Create Custom Header Template for Scripts<\/p>\n<\/div>\n<p>The template above will automatically add the required \u201c<strong>shebang<\/strong>\u201d line:\u00a0<code>\u201c#!\/bin\/bash\u201d<\/code>\u00a0and your other custom headers. Note that in this example, you will manually add the script name, description and arguments when editing your script content.<\/p>\n<h3>Configure autocmd in Vimrc File<\/h3>\n<p>Now open your\u00a0<strong>vim<\/strong>\u00a0initialization file\u00a0<code>~\/.vimrc<\/code>\u00a0for editing and add the following line to it.<\/p>\n<pre>au bufnewfile *.sh 0r \/home\/aaronkilik\/.vim\/sh_header.temp\r\n<\/pre>\n<p>Where:<\/p>\n<ul>\n<li><strong>au<\/strong>\u00a0\u2013 means autocmd<\/li>\n<li><strong>bufnewfile<\/strong>\u00a0\u2013 event for opening a file that doesn\u2019t exist for editing.<\/li>\n<li><strong>*.sh<\/strong>\u00a0\u2013 consider all files with\u00a0<strong>.sh<\/strong>\u00a0extension.<\/li>\n<\/ul>\n<p>So the above line instructs\u00a0<a href=\"https:\/\/www.tecmint.com\/vi-editor-usage\/\" target=\"_blank\" rel=\"noopener\">vi\/vim editor<\/a>\u00a0to read the contents of the template file (<strong>\/home\/aaronkilik\/.vim\/sh_header.temp<\/strong>) and insert it into every new\u00a0<code>.sh<\/code>\u00a0file opened by a user.<\/p>\n<div id=\"attachment_28549\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/02\/add-configuration-in-vimrc-file.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28549\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/02\/add-configuration-in-vimrc-file.png\" alt=\"Configure Vimrc File\" width=\"662\" height=\"173\" aria-describedby=\"caption-attachment-28549\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28549\" class=\"wp-caption-text\">Configure Vimrc File<\/p>\n<\/div>\n<h3>Test Custom Bash Script Header in New Script File<\/h3>\n<p>Now you can test if all is working by opening a new\u00a0<code>.sh<\/code>\u00a0file using vi\/vim editor, and your custom header should be auto-added there.<\/p>\n<pre>$ vi test.sh\r\n<\/pre>\n<div id=\"attachment_28550\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/02\/Verify-Custom-Header-in-New-Scripts.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-28550\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/02\/Verify-Custom-Header-in-New-Scripts.png\" alt=\"Verify Custom Header in New Scripts\" width=\"586\" height=\"276\" aria-describedby=\"caption-attachment-28550\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-28550\" class=\"wp-caption-text\">Verify Custom Header in New Scripts<\/p>\n<\/div>\n<p>For more information, see the\u00a0<a href=\"http:\/\/vimdoc.sourceforge.net\/htmldoc\/autocmd.html\" target=\"_blank\" rel=\"nofollow noopener\">Vim autocmd documentation<\/a>.<\/p>\n<p>Lastly, here are some useful guides concerning bash scripting and vim editor:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/useful-tips-for-writing-bash-scripts-in-linux\/\" target=\"_blank\" rel=\"noopener\">10 Useful Tips for Writing Effective Bash Scripts in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/reasons-to-learn-vi-vim-editor-in-linux\/\" target=\"_blank\" rel=\"noopener\">10 Reasons Why You Should Use Vi\/Vim Text Editor in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/password-protect-vim-file-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Password Protect a Vim File in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/enable-syntax-highlighting-in-vi-editor\/\" target=\"_blank\" rel=\"noopener\">How to Enable Syntax Highlighting in Vi\/Vim Editor<\/a><\/li>\n<\/ol>\n<p>That\u2019s all! If you have any questions or useful bash scripting tips and tricks to share, use the comment form below.<\/p>\n<h1 class=\"post-title\">jm-shell \u2013 A Highly Informative and Customized Bash Shell<\/h1>\n<p><strong>jm-shell<\/strong>\u00a0is a free open source, small, highly informative and customized Bash shell, that gives you a great wealth of information about your shell activity as well as certain useful system information such as system load average,\u00a0<a href=\"https:\/\/www.tecmint.com\/tlp-increase-and-optimize-linux-battery-life\/\" target=\"_blank\" rel=\"noopener\">battery status of laptops\/computers<\/a>\u00a0and much more.<\/p>\n<p>Importantly, unlike\u00a0<strong>Bash<\/strong>\u00a0which only stores unique\u00a0<a href=\"https:\/\/www.tecmint.com\/clear-command-line-history-in-linux\/\" target=\"_blank\" rel=\"noopener\">commands in a history file<\/a>, for searching previously run commands \u2013 jm-shell records each and every shell activity in a log file.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/history-command-examples\/\" target=\"_blank\" rel=\"noopener\">The Power of Linux \u201cHistory Command\u201d in Bash Shell<\/a><\/p>\n<p>In addition, if your current directory is a code repository for any version control systems such as\u00a0<strong>Git<\/strong>,\u00a0<strong>Subversion<\/strong>, or\u00a0<strong>Mercurial<\/strong>, it will provide information about your repositories (such as\u00a0<strong>active branch<\/strong>).<\/p>\n<div id=\"attachment_29488\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/jm-shell-preview.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29488\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/jm-shell-preview.png\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/jm-shell-preview.png 882w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/jm-shell-preview-768x691.png 768w\" alt=\"jm-shell Preview\" width=\"882\" height=\"793\" aria-describedby=\"caption-attachment-29488\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-29488\" class=\"wp-caption-text\">jm-shell Preview<\/p>\n<\/div>\n<h4>Jm-shell Features<\/h4>\n<ul>\n<li>Has a status line (divider) to separate commands.<\/li>\n<li>Displays the number of items in current directory.<\/li>\n<li>Shows current location in the filesystem.<\/li>\n<li>It maintains a shell log file \u2013 full history of your shell activity.<\/li>\n<li>Displays current system load average if higher than, in red if critical (higher than 2).<\/li>\n<li>Shows the time last command finished.<\/li>\n<li>It prints an error code of last command, if any.<\/li>\n<li>Displays total time of last command if higher than 4 seconds.<\/li>\n<li>Has a prompt in the form;\u00a0<strong>username@hostname:path<\/strong>.<\/li>\n<li>Supports multiple prompt styles.<\/li>\n<li>Supports background jobs.<\/li>\n<li>It also displays laptop battery charge status, in case it\u2019s not full and many other features.<\/li>\n<\/ul>\n<h3>How to Install jm-shell in Linux Systems<\/h3>\n<p>To install most recent version of\u00a0<strong>jm-shell<\/strong>, you need to clone git repository of\u00a0<strong>jm-shell<\/strong>\u00a0sources to your system and move into the local repository using following commands.<\/p>\n<pre>$ git clone https:\/\/github.com\/jmcclare\/jm-shell.git\r\n$ cd jm-shell\r\n<\/pre>\n<p>Next, configure\u00a0<strong>Bash<\/strong>\u00a0to use\u00a0<strong>jm-shell<\/strong>\u00a0by creating or copying a symlink from\u00a0<strong>ps1<\/strong>,\u00a0<strong>colors.sh<\/strong>, and\u00a0<strong>color_unset.sh<\/strong>\u00a0to the directory\u00a0<code>~\/.local\/lib\/bash<\/code>\u00a0(you need to create this directory if it doesn\u2019t exist) as shown.<\/p>\n<pre>$ mkdir ~\/.local\/lib\/bash\t#create the directory if it doesn\u2019t exist \r\n$ cp -v colors.sh colors_unset.sh ps1 -t ~\/.local\/lib\/bash\/\r\n<\/pre>\n<div id=\"attachment_29483\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Configure-Bash-to-Use-jm-shell.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29483\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Configure-Bash-to-Use-jm-shell.png\" sizes=\"auto, (max-width: 822px) 100vw, 822px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Configure-Bash-to-Use-jm-shell.png 822w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Configure-Bash-to-Use-jm-shell-768x144.png 768w\" alt=\"Configure Bash to Use jm-shell\" width=\"822\" height=\"154\" aria-describedby=\"caption-attachment-29483\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-29483\" class=\"wp-caption-text\">Configure Bash to Use jm-shell<\/p>\n<\/div>\n<p>Then\u00a0<strong>source<\/strong>\u00a0the\u00a0<code>ps1<\/code>\u00a0file by adding the following line in your\u00a0<strong>~\/.bashrc<\/strong>\u00a0shell initialization file.<\/p>\n<pre>source ~\/.local\/lib\/bash\/ps1\r\n<\/pre>\n<p>Then use the\u00a0<strong>prompt_style<\/strong>\u00a0variable in your\u00a0<strong>~\/.bashrc<\/strong>\u00a0to set your prompt styles (available styles include\u00a0<strong>standard<\/strong>, tweaked,\u00a0<strong>extensive<\/strong>,\u00a0<strong>minimal<\/strong>\u00a0or\u00a0<strong>kirby<\/strong>) as shown.<\/p>\n<pre>prompt_style=extensive\r\n<\/pre>\n<div id=\"attachment_29484\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Source-PS1-and-Set-Prompt-Style.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29484\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Source-PS1-and-Set-Prompt-Style.png\" alt=\"Source PS1 and Set Prompt Style\" width=\"502\" height=\"211\" aria-describedby=\"caption-attachment-29484\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-29484\" class=\"wp-caption-text\">Source PS1 and Set Prompt Style<\/p>\n<\/div>\n<p>Save and close\u00a0<strong>~\/bashrc<\/strong>\u00a0file, then\u00a0<strong>source<\/strong>\u00a0it to see the changes.<\/p>\n<pre>$ source ~\/.bashrc\r\n<\/pre>\n<div id=\"attachment_29485\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/jm-shell.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29485\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/jm-shell.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/jm-shell.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/jm-shell-768x493.png 768w\" alt=\"jm-shell for Linux\" width=\"802\" height=\"515\" aria-describedby=\"caption-attachment-29485\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-29485\" class=\"wp-caption-text\">jm-shell for Linux<\/p>\n<\/div>\n<p>To change the shell log file location (default is\u00a0<strong>~\/.local\/share\/bash\/shell.log<\/strong>), use the\u00a0<strong>BASHSHELLLOGFILE<\/strong>variable in\u00a0<strong>~\/.bashrc<\/strong>\u00a0file.<\/p>\n<pre>BASHSHELLLOGFILE=~\/.bash-shell.log\r\n<\/pre>\n<p>For more information, go to the jm-shell Github Repository:\u00a0<a href=\"https:\/\/github.com\/jmcclare\/jm-shell\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/github.com\/jmcclare\/jm-shell<\/a><\/p>\n<p><strong>jm-shell<\/strong>\u00a0is a highly informative tool that includes set of scripts for customizing your Bash shell, with numerous practical and informative features for daily usage. Try it out and give us your feedback via the comment section below.<\/p>\n<h1 class=\"post-title\">Useful Linux Command Line Bash Shortcuts You Should Know<\/h1>\n<p>In this article, we will share a number of Bash command-line shortcuts useful for any Linux user. These shortcuts allow you to easily and in a fast manner, perform certain activities such as accessing and running previously executed commands, opening an editor, editing\/deleting\/changing text on the command line, moving the cursor, controlling processes etc. on the command line.<\/p>\n<p>Although this article will mostly benefit Linux beginners getting their way around with command line basics, those with intermediate skills and advanced users might also find it practically helpful. We will group the bash keyboard shortcuts according to categories as follows.<\/p>\n<h3>Launch an Editor<\/h3>\n<p>Open a terminal and press\u00a0<code>Ctrl+X<\/code>\u00a0and\u00a0<code>Ctrl+E<\/code>\u00a0to open an editor (<strong>nano editor<\/strong>) with an empty buffer. Bash will try to launch the editor defined by the\u00a0<strong>$EDITOR<\/strong>\u00a0environment variable.<\/p>\n<div id=\"attachment_29562\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Nano-Editor.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-29562\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Nano-Editor.png\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Nano-Editor.png 906w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/05\/Nano-Editor-768x480.png 768w\" alt=\"Nano Editor\" width=\"906\" height=\"566\" aria-describedby=\"caption-attachment-29562\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-29562\" class=\"wp-caption-text\">Nano Editor<\/p>\n<\/div>\n<h3>Controlling The Screen<\/h3>\n<p>These shortcuts are used to control terminal screen output:<\/p>\n<ul>\n<li><code>Ctrl+L<\/code>\u00a0\u2013 clears the screen (same effect as the \u201c<strong>clear<\/strong>\u201d command).<\/li>\n<li><code>Ctrl+S<\/code>\u00a0\u2013 pause all command output to the screen. If you have executed a command that produces verbose, long output, use this to pause the output scrolling down the screen.<\/li>\n<li><code>Ctrl+Q<\/code>\u00a0\u2013 resume output to the screen after pausing it with\u00a0<strong>Ctrl+S<\/strong>.<\/li>\n<\/ul>\n<h3>Move Cursor on The Command Line<\/h3>\n<p>The next shortcuts are used for moving the cursor within the command-line:<\/p>\n<ul>\n<li><code>Ctrl+A<\/code>\u00a0or\u00a0<code>Home<\/code>\u00a0\u2013 moves the cursor to the start of a line.<\/li>\n<li><code>Ctrl+E<\/code>\u00a0or\u00a0<code>End<\/code>\u00a0\u2013 moves the cursor to the end of the line.<\/li>\n<li><code>Ctrl+B<\/code>\u00a0or\u00a0<code>Left Arrow<\/code>\u00a0\u2013 moves the cursor back one character at a time.<\/li>\n<li><code>Ctrl+F<\/code>\u00a0or\u00a0<code>Right Arrow<\/code>\u00a0\u2013 moves the cursor forward one character at a time.<\/li>\n<li><code>Ctrl<\/code>\u00a0+\u00a0<code>Left Arrow<\/code>\u00a0or\u00a0<code>Alt+B<\/code>\u00a0or\u00a0<code>Esc<\/code>\u00a0and then\u00a0<code>B<\/code>\u00a0\u2013 moves the cursor back one word at a time.<\/li>\n<li><code>Ctrl<\/code>\u00a0+\u00a0<code>Right Arrow<\/code>\u00a0or\u00a0<code>Alt+C<\/code>\u00a0or\u00a0<code>Esc<\/code>\u00a0and then\u00a0<code>F<\/code>\u00a0\u2013 moves the cursor forward one word at a time.<\/li>\n<\/ul>\n<h3>Search Through Bash History<\/h3>\n<p>The following shortcuts are used for searching for commands in the bash history:<\/p>\n<ul>\n<li><code>Up arrow key<\/code>\u00a0\u2013 retrieves the previous command. If you press it constantly, it takes you through multiple commands in history, so you can find the one you want. Use the\u00a0<strong>Down arrow<\/strong>\u00a0to move in the reverse direction through the history.<\/li>\n<li><code>Ctrl+P<\/code>\u00a0and\u00a0<code>Ctrl+N<\/code>\u00a0\u2013 alternatives for the\u00a0<strong>Up<\/strong>\u00a0and\u00a0<strong>Down<\/strong>\u00a0arrow keys, respectively.<\/li>\n<li><code>Ctrl+R<\/code>\u00a0\u2013 starts a reverse search, through the bash history, simply type characters that should be unique to the command you want to find in the history.<\/li>\n<li><code>Ctrl+S<\/code>\u00a0\u2013 launches a forward search, through the bash history.<\/li>\n<li><code>Ctrl+G<\/code>\u00a0\u2013 quits reverse or forward search, through the bash history.<\/li>\n<\/ul>\n<h3>Delete Text on the Command Line<\/h3>\n<p>The following shortcuts are used for deleting text on the command line:<\/p>\n<ul>\n<li><code>Ctrl+D<\/code>\u00a0or\u00a0<code>Delete<\/code>\u00a0\u2013 remove or deletes the character under the cursor.<\/li>\n<li><code>Ctrl+K<\/code>\u00a0\u2013 removes all text from the cursor to the end of the line.<\/li>\n<li><code>Ctrl+X<\/code>\u00a0and then\u00a0<code>Backspace<\/code>\u00a0\u2013 removes all the text from the cursor to the beginning of the line.<\/li>\n<\/ul>\n<h3>Transpose Text or Change Case on the Command Line<\/h3>\n<p>These shortcuts will transpose or change the case of letters or words on the command line:<\/p>\n<ul>\n<li><code>Ctrl+T<\/code>\u00a0\u2013 transposes the character before the cursor with the character under the cursor.<\/li>\n<li><code>Esc<\/code>\u00a0and then\u00a0<code>T<\/code>\u00a0\u2013 transposes the two words immediately before (or under) the cursor.<\/li>\n<li><code>Esc<\/code>\u00a0and then\u00a0<code>U<\/code>\u00a0\u2013 transforms the text from the cursor to the end of the word to uppercase.<\/li>\n<li><code>Esc<\/code>\u00a0and then\u00a0<code>L<\/code>\u00a0\u2013 transforms the text from the cursor to the end of the word to lowercase.<\/li>\n<li><code>Esc<\/code>\u00a0and then\u00a0<code>C<\/code>\u00a0\u2013 changes the letter under the cursor (or the first letter of the next word) to uppercase, leaving the rest of the word unchanged.<\/li>\n<\/ul>\n<h3>Working With Processes in Linux<\/h3>\n<p>The following shortcuts help you to control running Linux processes.<\/p>\n<ul>\n<li><code>Ctrl+Z<\/code>\u00a0\u2013 suspend the current foreground process. This sends the\u00a0<strong>SIGTSTP<\/strong>\u00a0signal to the process. You can get the process back to the foreground later using the\u00a0<strong>fg<\/strong>\u00a0process_name (or\u00a0<strong>%bgprocess_number<\/strong>\u00a0like<strong>\u00a0%1<\/strong>,\u00a0<strong>%2<\/strong>\u00a0and so on) command.<\/li>\n<li><code>Ctrl+C<\/code>\u00a0\u2013 interrupt the current foreground process, by sending the\u00a0<strong>SIGINT<\/strong>\u00a0signal to it. The default behavior is to terminate a process gracefully, but the process can either honor or ignore it.<\/li>\n<li><code>Ctrl+D<\/code>\u00a0\u2013 exit the bash shell (same as running the\u00a0<strong>exit<\/strong>\u00a0command).<\/li>\n<\/ul>\n<p>Learn more about:\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-process-management\/\" target=\"_blank\" rel=\"noopener\">All You Need To Know About Processes in Linux [Comprehensive Guide]<\/a><\/p>\n<h3>Bash Bang (!) Commands<\/h3>\n<p>In the final part of this article, we will explain some useful\u00a0<code>!<\/code>\u00a0(bang) operations:<\/p>\n<ul>\n<li><code>!!<\/code>\u00a0\u2013 execute last command.<\/li>\n<li><code>!top<\/code>\u00a0\u2013 execute the most recent command that starts with\u00a0<strong>\u2018top\u2019<\/strong>\u00a0(e.g.\u00a0<strong>!<\/strong>).<\/li>\n<li><code>!top:p<\/code>\u00a0\u2013 displays the command that\u00a0<strong>!top<\/strong>\u00a0would run (also adds it as the latest command in the command history).<\/li>\n<li><code>!$<\/code>\u00a0\u2013 execute the last word of the previous command (same as\u00a0<strong>Alt +<\/strong>., e.g. if last command is \u2018<strong>cat tecmint.txt<\/strong>\u2019, then\u00a0<strong>!$<\/strong>\u00a0would try to run \u2018<strong>tecmint.txt<\/strong>\u2019).<\/li>\n<li><code>!$:p<\/code>\u00a0\u2013 displays the word that\u00a0<strong>!$<\/strong>\u00a0would execute.<\/li>\n<li><code>!*<\/code>\u00a0\u2013 displays the last word of the previous command.<\/li>\n<li><code>!*:p<\/code>\u00a0\u2013 displays the last word that\u00a0<strong>!*<\/strong>\u00a0would substitute.<\/li>\n<\/ul>\n<p>For more information, see the bash man page:<\/p>\n<pre>$ man bash \r\n<\/pre>\n<p>That\u2019s all for now! In this article, we shared some common and useful Bash command-line shortcuts and operations. Use the comment form below to make any additions or ask questions.<\/p>\n<h1 class=\"post-title\">Bash-it \u2013 Bash Framework to Control Your Scripts and Aliases<\/h1>\n<p><strong>Bash-it<\/strong>\u00a0is a bundle of community Bash commands and scripts for\u00a0<strong>Bash 3.2+<\/strong>, which comes with autocompletion, themes, aliases, custom functions, and more. It offers a useful framework for developing, maintaining and using shell scripts and custom commands for your daily work.<\/p>\n<p>If you are using the Bash shell on a daily basis and looking for an easy way to keep track of all your scripts, aliases and functions, then\u00a0<strong>Bash-it<\/strong>\u00a0is for you! Stop polluting your\u00a0<strong>~\/bin<\/strong>\u00a0directory and\u00a0<strong>.bashrc<\/strong>\u00a0file, fork\/clone Bash-it and begin hacking away.<\/p>\n<h3>How to Install Bash-it in Linux<\/h3>\n<p>To install\u00a0<strong>Bash-it<\/strong>, first you need to clone the following repository to a location of your choice, for example:<\/p>\n<pre>$ git clone --depth=1 https:\/\/github.com\/Bash-it\/bash-it.git ~\/.bash_it\r\n<\/pre>\n<p>Then run the following command to install\u00a0<strong>Bash-it<\/strong>\u00a0(it automatically backup your\u00a0<strong>~\/.bash_profile<\/strong>\u00a0or\u00a0<strong>~\/.bashrc<\/strong>, depending on your OS). You will be asked \u201c<strong>Would you like to keep your .bashrc and append bash-it templates at the end? [y\/N]<\/strong>\u201d, answer according to your preference.<\/p>\n<pre>$ ~\/.bash_it\/install.sh \r\n<\/pre>\n<div id=\"attachment_31789\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/install-bash-it.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31789\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/install-bash-it.png\" sizes=\"auto, (max-width: 952px) 100vw, 952px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/install-bash-it.png 952w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/install-bash-it-768x538.png 768w\" alt=\"Install Bash-It in Linux\" width=\"952\" height=\"667\" aria-describedby=\"caption-attachment-31789\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31789\" class=\"wp-caption-text\">Install Bash-It in Linux<\/p>\n<\/div>\n<p><center><ins class=\"adsbygoogle\" data-ad-client=\"ca-pub-2601749019656699\" data-ad-slot=\"5590002574\" data-ad-format=\"auto\" data-adsbygoogle-status=\"done\"><ins id=\"aswift_4_expand\"><ins id=\"aswift_4_anchor\"><iframe id=\"aswift_4\" name=\"aswift_4\" width=\"780\" height=\"90\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" allowfullscreen=\"allowfullscreen\" data-mce-fragment=\"1\"><\/iframe><\/ins><\/ins><\/ins><\/center>After installation, you can use\u00a0<a href=\"https:\/\/www.tecmint.com\/tag\/linux-ls-command\/\" target=\"_blank\" rel=\"noopener\">ls command<\/a>\u00a0to verify the\u00a0<strong>bash-it<\/strong>\u00a0installation files and directories as shown.<\/p>\n<pre>$ ls .bash_it\/\r\n<\/pre>\n<div id=\"attachment_31792\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/bash-it-installation-directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31792\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/bash-it-installation-directory.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/bash-it-installation-directory.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/bash-it-installation-directory-768x93.png 768w\" alt=\"Verify Bash-It Installation\" width=\"802\" height=\"97\" aria-describedby=\"caption-attachment-31792\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31792\" class=\"wp-caption-text\">Verify Bash-It Installation<\/p>\n<\/div>\n<p>To start using\u00a0<strong>Bash-it<\/strong>, open a new tab or run:<\/p>\n<pre>$ source $HOME\/.bashrc\r\n<\/pre>\n<h3>How to Customize Bash-it in Linux<\/h3>\n<p>To customize\u00a0<strong>Bash-it<\/strong>, you need to edit your modified\u00a0<strong>~\/.bashrc<\/strong>\u00a0shell startup file. To list all installed and available aliases, completions, and plugins run the following commands, which should also shows you how to enable or disable them:<\/p>\n<pre>  \r\n$ bash-it show aliases        \t\r\n$ bash-it show completions  \r\n$ bash-it show plugins        \t\r\n<\/pre>\n<p>Next, we will demonstrate how to enable aliases, but before that, first list the current aliases with the following command.<\/p>\n<pre>$ alias \r\n<\/pre>\n<div id=\"attachment_31793\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/view-current-aliases.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31793\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/view-current-aliases.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/view-current-aliases.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/view-current-aliases-768x366.png 768w\" alt=\"View Current Aliases in Linux\" width=\"802\" height=\"382\" aria-describedby=\"caption-attachment-31793\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31793\" class=\"wp-caption-text\">View Current Aliases in Linux<\/p>\n<\/div>\n<p>All the aliases are located in the\u00a0<strong>$HOME\/.bash_it\/aliases\/<\/strong>\u00a0directory. Now let\u2019s enable the\u00a0<a href=\"https:\/\/www.tecmint.com\/apt-advanced-package-command-examples-in-ubuntu\/\" target=\"_blank\" rel=\"noopener\">apt<\/a>\u00a0aliases as shown.<\/p>\n<pre>$ bash-it enable alias apt\r\n<\/pre>\n<div id=\"attachment_31794\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/enable-an-alias.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31794\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/enable-an-alias.png\" alt=\"Enable Alias in Linux\" width=\"602\" height=\"116\" aria-describedby=\"caption-attachment-31794\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31794\" class=\"wp-caption-text\">Enable Alias in Linux<\/p>\n<\/div>\n<p>Then reload\u00a0<strong>bash-it<\/strong>\u00a0configs and check the current aliases once more.<\/p>\n<pre>$ bash-it reload\t\r\n$ alias\r\n<\/pre>\n<p>From the output of the\u00a0<a href=\"https:\/\/www.tecmint.com\/create-alias-in-linux\/\" target=\"_blank\" rel=\"noopener\">alias command<\/a>, the\u00a0<strong>apt aliases<\/strong>\u00a0are now enabled.<\/p>\n<div id=\"attachment_31795\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/reload-bash-it-and-check-current-aliases.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31795\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/reload-bash-it-and-check-current-aliases.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/reload-bash-it-and-check-current-aliases.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/reload-bash-it-and-check-current-aliases-768x475.png 768w\" alt=\"Check Current Aliases in Linux\" width=\"802\" height=\"496\" aria-describedby=\"caption-attachment-31795\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31795\" class=\"wp-caption-text\">Check Current Aliases in Linux<\/p>\n<\/div>\n<p>You can disable newly enabled alias with the following commands.<\/p>\n<pre>$ bash-it disable alias apt\r\n$ bash-it reload\r\n<\/pre>\n<div id=\"attachment_31796\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/disable-apt-aliases.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31796\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/disable-apt-aliases.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/disable-apt-aliases.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/disable-apt-aliases-768x147.png 768w\" alt=\"Disable Aliases in Linux\" width=\"802\" height=\"154\" aria-describedby=\"caption-attachment-31796\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31796\" class=\"wp-caption-text\">Disable Aliases in Linux<\/p>\n<\/div>\n<p>In the next section, we will use similar steps to enable or disable completions (<strong>$HOME\/.bash_it\/completion\/<\/strong>) and plugins (<strong>$HOME\/..bash_it\/plugins\/<\/strong>). All enabled features are located in the\u00a0<strong>$HOME\/.bash_it\/enabled<\/strong>directory.<\/p>\n<h3>How to Manage Bash-it Theme<\/h3>\n<p>The default theme for\u00a0<strong>bash-it<\/strong>\u00a0is\u00a0<strong>bobby<\/strong>; you can check this using the\u00a0<strong>BASH_IT_THEME env<\/strong>\u00a0variable as shown.<\/p>\n<pre>echo $BASH_IT_THEME\r\n<\/pre>\n<div id=\"attachment_31797\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/check-default-theme.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31797\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/check-default-theme.png\" alt=\"Check Bash-it Theme\" width=\"602\" height=\"116\" aria-describedby=\"caption-attachment-31797\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31797\" class=\"wp-caption-text\">Check Bash-it Theme<\/p>\n<\/div>\n<p>You can find over\u00a0<strong>50+ Bash-it<\/strong>\u00a0themes in the\u00a0<strong>$BASH_IT\/themes<\/strong>\u00a0directory.<\/p>\n<pre>$ ls $BASH_IT\/themes\r\n<\/pre>\n<div id=\"attachment_31798\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/view-bash-it-themes.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31798\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/view-bash-it-themes.png\" alt=\"View Bash-It Themes\" width=\"602\" height=\"781\" aria-describedby=\"caption-attachment-31798\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31798\" class=\"wp-caption-text\">View Bash-It Themes<\/p>\n<\/div>\n<p>To preview all the themes in your shell before using any, run the following command.<\/p>\n<pre>$ BASH_PREVIEW=true bash-it reload\r\n<\/pre>\n<div id=\"attachment_31799\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/preview-all-bash-it-themes.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31799\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/preview-all-bash-it-themes.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/preview-all-bash-it-themes.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/preview-all-bash-it-themes-768x839.png 768w\" alt=\"Preview All Bash-It Themes\" width=\"802\" height=\"876\" aria-describedby=\"caption-attachment-31799\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31799\" class=\"wp-caption-text\">Preview All Bash-It Themes<\/p>\n<\/div>\n<p>Once you have identified a theme to use, open your\u00a0<strong>.bashrc<\/strong>\u00a0file and find the following line in it and change it value to the name of the theme you want, for example:<\/p>\n<pre>$ export BASH_IT_THEME='essential'\r\n<\/pre>\n<div id=\"attachment_31800\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/change-bash-it-theme.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31800\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/change-bash-it-theme.png\" sizes=\"auto, (max-width: 772px) 100vw, 772px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/change-bash-it-theme.png 772w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/change-bash-it-theme-768x342.png 768w\" alt=\"Change Bash-It Theme\" width=\"772\" height=\"344\" aria-describedby=\"caption-attachment-31800\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31800\" class=\"wp-caption-text\">Change Bash-It Theme<\/p>\n<\/div>\n<p>Save the file and close, and source it as shown before.<\/p>\n<pre>$ source $HOME\/.bashrc\r\n<\/pre>\n<p><strong>Note<\/strong>: In case you have built a your own custom themes outside of\u00a0<strong>$BASH_IT\/themes<\/strong>\u00a0directory, point the\u00a0<strong>BASH_IT_THEME<\/strong>\u00a0variable directly to the theme file:<\/p>\n<pre>export BASH_IT_THEME='\/path\/to\/your\/custom\/theme\/'\r\n<\/pre>\n<p>And to disable theming, leave the above env variable empty.<\/p>\n<pre>export BASH_IT_THEME=''\r\n<\/pre>\n<h3>How to Search Plugins, Aliases or Completions<\/h3>\n<p>You can easily check out which of the plugins, aliases or completions are available for a specific programming language, framework or an environment.<\/p>\n<p>The trick is simple: just search for multiple terms related to some of the commands you use frequently, for example:<\/p>\n<pre>$ bash-it search python pip pip3 pipenv\r\n$ bash-it search git\r\n<\/pre>\n<div id=\"attachment_31801\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/search-in-bash-it.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31801\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2019\/02\/search-in-bash-it.png\" alt=\"Search in Bash-It\" width=\"662\" height=\"211\" aria-describedby=\"caption-attachment-31801\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31801\" class=\"wp-caption-text\">Search in Bash-It<\/p>\n<\/div>\n<p>To view help messages for the aliases, completions and plugins, run:<\/p>\n<pre>$ bash-it help aliases        \t\r\n$ bash-it help completions\r\n$ bash-it help plugins     \r\n<\/pre>\n<p>You can create you own custom scripts, and aliases, in the following files in the respective directories:<\/p>\n<pre>aliases\/custom.aliases.bash \r\ncompletion\/custom.completion.bash \r\nlib\/custom.bash \r\nplugins\/custom.plugins.bash \r\ncustom\/themes\/\/&lt;custom theme name&gt;.theme.bash \r\n<\/pre>\n<h3>Updating and Uninstalling Bash-It<\/h3>\n<p>To update Bash-it to the latest version, simply run:<\/p>\n<pre>$ bash-it update\r\n<\/pre>\n<p>If you don\u2019t like Bash-it anymore, you can uninstall it by running the following commands.<\/p>\n<pre>$ cd $BASH_IT\r\n$ .\/uninstall.sh\r\n<\/pre>\n<p>The\u00a0<strong>uninstall.sh<\/strong>\u00a0script will restore your previous Bash startup file. Once it has completed the operation, you need to remove the Bash-it directory from your machine by running.<\/p>\n<pre>$ rm -rf $BASH_IT  \r\n<\/pre>\n<p>And remember to start a new shell for the recent changes to work or source it again as shown.<\/p>\n<pre>$ source $HOME\/.bashrc\r\n<\/pre>\n<p>You can see all usage options by running:<\/p>\n<pre>$ bash-it help\r\n<\/pre>\n<p>Finally,\u00a0<strong>Bash-it<\/strong>\u00a0comes with a number of cool features related to\u00a0<strong>Git<\/strong>.<\/p>\n<p>For more information, see the Bash-it Github repository:\u00a0<a href=\"https:\/\/github.com\/Bash-it\/bash-it\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/github.com\/Bash-it\/bash-it<\/a>.<\/p>\n<p>That\u2019s all!\u00a0<strong>Bash-it<\/strong>\u00a0is an easy and productive way to keep all your bash scripts and aliases under control. If you have any questions to ask, use the feedback form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/category\/bash-shell\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understand Linux Shell and Basic Shell Scripting Language Tips \u2013 Part I Picture speak more than words and the below picture says all about the working of\u00a0Linux. &nbsp; Understanding Linux Shell Read Also 5 Shell Scripts to Learn Shell Programming \u2013 Part II Sailing Through The World of Linux BASH Scripting \u2013 Part III Understanding &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/bash-shell\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;BASH SHELL&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13185","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13185"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13185\/revisions"}],"predecessor-version":[{"id":13186,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13185\/revisions\/13186"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}