{"id":212,"date":"2018-07-13T07:13:50","date_gmt":"2018-07-13T07:13:50","guid":{"rendered":"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=212"},"modified":"2019-05-16T07:30:08","modified_gmt":"2019-05-16T07:30:08","slug":"bash-shell-scripting-2","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/chapter\/bash-shell-scripting-2\/","title":{"rendered":"Bash Shell Scripting &#8211; 2"},"content":{"raw":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/B0RQs_nVAl0\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n<ol>\r\n \t<li><strong>Performing Calculations in Shell Scripting<\/strong><\/li>\r\n<\/ol>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the previous module, we have seen how to define a variable, assign values to the variable and retrieve the stored values. The values assigned to variables were treated as strings. When we want to perform numerical operations on these values, it cannot be done in a straight forward way like c=a+b because these variables contain strings. Let us see what happens if we perform simple addition operation on string.<\/p>\r\n&nbsp;\r\n\r\na=10\r\n\r\nb=15\r\n\r\nc=$a+$b\r\n\r\necho \"Total is: $c\"\r\n\r\nOutput:\r\n\r\nTotal is:10+15\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the following sections, we will explore how to perform arithmetic operations on shell variables. There are four different ways used to perform calculations in shell scripting. These commands convert strings into numbers and perform the desired arithmetic operation. A programmer is free to use any of the following commands to perform arithmetic operations:<\/p>\r\n\r\n<ul>\r\n \t<li>expr (compiled application for integer arithmetic operations)<\/li>\r\n \t<li>Using $((...))<\/li>\r\n \t<li>let (built-in shell command)<\/li>\r\n \t<li>bc (compiled application for floating point operations)<\/li>\r\n<\/ul>\r\nWe can use the above techniques on command prompt as follows:\r\n\r\n&nbsp;\r\n\r\n$expr 2 + 5\r\n\r\n$echo $((2+5))\r\n\r\n$let x=( 2 + 5 )\r\n\r\n$echo $x\r\n\r\n$echo \"2 + 5\" | bc\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Commands like expr and bc are widely used by shell programmers. Techniques like $((...)) and let command are not used frequently, the main reason is probably they are not supported by other shells. Let us explore expr, let and bc commands in detail with sample shell scripts.<\/p>\r\n&nbsp;\r\n\r\n<strong>expr : Evaluation Expressions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">expr command evaluates arithmetic expressions and helps to perform integer calculations. The syntax of expr is:<\/p>\r\n&nbsp;\r\n\r\n<strong>expr arg1 operator arg2<\/strong>\r\n\r\n&nbsp;\r\n\r\nFew Examples:\r\n\r\n$expr 2 + 3\r\n\r\n$a=5\r\n\r\n$b=10\r\n\r\n$expr $a + $b\r\n\r\n$expr $a \\* $b\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">It must be noted that the operator used for multiplication, asterisk (*) is treated as a wildcard character by shell, that is why we have to use escape sequence (\\) while performing multiplications.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The following shell script performs basic arithmetic calculations using expr command over two variables. Here we have used command substitution so that the expression gets evaluated first and the results are stored in the variable \"ans\".<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-213 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-1.png\" alt=\"\" width=\"693\" height=\"291\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Note: expr command can also be used to find the substring of a given string or length of a given string. We request you to read the manual of expr for more details. (use man expr)<\/p>\r\n&nbsp;\r\n\r\n<strong>let : Assigning and Evaluating expressions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The let command performs integer calculations as we did with expr command. However, when we use let command, there is no need to use the '$' sign with variables and use command substitution as with expr. let command evaluates the expression and stores the values in the variable. The syntax of let command is:<\/p>\r\n<strong>let variable=value\/expression [variable2=value\/expression...]<\/strong>\r\n\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-214 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-2.png\" alt=\"\" width=\"698\" height=\"218\" \/>\r\n\r\n<img class=\"alignnone size-full wp-image-215 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w15-1.png\" alt=\"\" width=\"692\" height=\"88\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>bc : Base Conversion<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The bc calculator can be used within shell scripts to perform floating point operations. However, while using in shell scripts, we have to pass the expression to bc using pipe (|) symbol. As we know that bc can be invoked from command prompt and allows us to perform calculations. We can also specify the variable scale to get precise answers while working with floating point numbers. The following script demonstrates the use of bc:<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-216 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w16-1.png\" alt=\"\" width=\"696\" height=\"291\" \/><\/p>\r\n\r\n<ol start=\"2\">\r\n \t<li><strong> Decision Making<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify;\">Decision making is a key part of any programming language. Every language provides if-else statement for decision making within the programs. However, for each language the syntax and keywords may vary. Bash shell programming provides two different constructs for decision making. The programmer has a choice to use either of the followings:<\/p>\r\n\r\n<ul>\r\n \t<li>if-then-else-fi statement<\/li>\r\n \t<li>case-esac statement<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify;\">The conditional statements in shell programming have far more capabilities when compared to those of programming languages like C, C++ etc. The main reason being, it allows us to use wildcard characters within the statement. Let us explore the syntax of each one of the above.<\/p>\r\n&nbsp;\r\n\r\n<strong>If Statement<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The if-then-else statements are considered as control statements. Depending on the condition, selected statements are executed and hence it decides the flow of script. The if-then-else construct takes three different forms. Let us first see the syntax and later explore the scripts using these forms.<\/p>\r\n&nbsp;\r\n\r\n# First form if condition then commands\r\n\r\nfi\r\n\r\n# Second form if condition thencommands\r\n\r\nelse commands\r\n\r\nfi\r\n\r\n# Third form if condition then\r\n\r\ncommands elif condition then commands\r\n\r\nfi\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the first form, if the condition is true, then commands are executed. If the condition is false, nothing is done and the control comes out of the if statement.<\/p>\r\n&nbsp;\r\n\r\nIn the second form, if the condition is true, then the first set of commands is\u00a0executed and if the condition is false, then second set of commands is executed.\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the third form, if the condition is true, then the first set of commands is executed, if the condition is false, and if the second condition is true, then the second set of commands is executed. In the third form, the if construct checks for two conditions.<\/p>\r\n&nbsp;\r\n\r\nIt must be noted that each if block ends with a fi. Let us see a simple script that demonstrates the working of if-else statement\r\n\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-217 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w17-1.png\" alt=\"\" width=\"706\" height=\"195\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The above script will try to display the contents of \/etc\/passwd file. If the cat command executes successfully (that is, exit status of cat is 0) then the \u201cFile \/etc\/passwd displayed\u201d message will be seen on terminal. In case if the cat command does not execute properly due to insufficient permissions or some other reason (exit status is 1)then the \u201cSome error occurred...\u201d message will be seen on terminal.<\/p>\r\n&nbsp;\r\n\r\n<strong>test and [] command: companion of if<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The test command is used often with if statements to perform true\/false decisions. The test command can be used to compare numbers, check files and directories or check strings. The test command checks the expression and exists with status either 0 (expression is rue) or 1 (expression is false). The test command can be used with the keyword test or using the notation []. It takes two forms as shown below:<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-218 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w18-1.png\" alt=\"\" width=\"682\" height=\"106\" \/><\/p>\r\n\r\n<div>\r\n<p style=\"text-align: justify;\">The test command can be used for three main purposes in conjunction with if statement. Test can be used to:<\/p>\r\n\r\n<ul>\r\n \t<li>\u00a0Compare two numbers<\/li>\r\n \t<li>Compare two strings or a single string for null value<\/li>\r\n \t<li>Check the attributes of a file\/directory<\/li>\r\n<\/ul>\r\n<\/div>\r\n<p style=\"text-align: justify;\">test command can also be used with loop constructs within shell scripts, however, we will explore its usage with if statements. As such, test command does not display any output but simply returns a status of $?. We must take care that there has to be blank space between expression and square brackets ('[' and ']'). Let us explore how test can be used with the above conditions.<\/p>\r\n&nbsp;\r\n\r\n<strong>Numeric Comparison<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe test command can be used to compare two numbers. The comparison operators always begin with a \u2018\u2013\u2018 (hyphen) as shown in below table:\r\n\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-221 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W19.png\" alt=\"\" width=\"560\" height=\"488\" \/>\r\n\r\n&nbsp;\r\n\r\nThe above script displays the larger number from the two numbers input by the user. We can use the following form:\r\n\r\nif test $a -gt $b instead of if [ $a -gt $b ]\r\n\r\n&nbsp;\r\n\r\n<strong>String Comparisons<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Test command can be used to compare two strings for equality, it can also be used to check whether a string is null or not. The following table summarizes the operators used for string comparison.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-223 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W20.png\" alt=\"\" width=\"563\" height=\"439\" \/><\/p>\r\n<strong>Output:<\/strong>\r\n\r\n&nbsp;\r\n\r\nBoth the strings are different.\r\n\r\n&nbsp;\r\n\r\n<strong>File Checks<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The test command can be used to test various file attributes. It also tests whether a string is a file or a directory. The following table summarizes few parameters to check file attributes<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-224 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W21.png\" alt=\"\" width=\"558\" height=\"402\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>Case \u2013 Esac<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The following is a code which helps use to check whether the user has entered yes or no. However, there are few issues in the following program. The user may enter y for yes or YES in capitals. Under such circumstances, the following program may not give expected output.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-225 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W22.png\" alt=\"\" width=\"560\" height=\"162\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The above program has few logical bugs. What if the user enters Yes or YES or yes or Y or y. If we try to incorporate each test condition, the if-else statements will become too complicated. Such kind of issues can be well addressed by using case-esac construct rather than if-else statements. The following code looks much cleaner:<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-226 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W23.png\" alt=\"\" width=\"559\" height=\"171\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The case-esac statements are generally used when there are multiple conditions to be checked. It also supports wildcard characters to match appropriate patterns. The syntax is:<\/p>\r\ncase $variable-name in\r\n\r\npatterns ) commands ;;\r\n\r\npatterns ) commands ;;\r\n\r\n.....\r\n\r\nesac\r\n<p style=\"text-align: justify;\">The following script demonstrates pattern matching with case-esac construct. Using regular expressions within case statements, we can check whether the word entered by a user starts with a vowel or a consonant.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-227 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W24.png\" alt=\"\" width=\"554\" height=\"216\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let us see one more script where we check whether the single character entered by the user is a letter or a digit. Patterns like [:lower:] and [:upper] will classify the typed character as a lower case or upper case<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-228 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W25.png\" alt=\"\" width=\"575\" height=\"265\" \/><\/p>\r\n\r\n<ol start=\"3\">\r\n \t<li><strong> Loop Constructs<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify;\">Loops are important part of any programming language. They are used to perform iterative operations. Usually, a loop has a condition to identify the terminating criteria. A loop may iterate for 'n' number of times depending on some condition. In bash shell scripting, we can use three types of loops. The following loop constructs are explored in this section:<\/p>\r\n\r\n<ul>\r\n \t<li>While loop<\/li>\r\n \t<li>Until loop<\/li>\r\n \t<li>For loop<\/li>\r\n<\/ul>\r\n<strong>\u00a0 \u00a0 While Loop<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The while command causes a block of code to be executed over and over, as long as the exit status of a specified expression is true.<\/p>\r\nSyntax of while loop\r\n\r\nwhile condition is true\r\n\r\ndo\r\n\r\nStatement(s) to be executed if condition is true done\r\n\r\nHere is a simple example of a program that displays from zero to ten:\r\n\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-229 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W26.png\" alt=\"\" width=\"562\" height=\"157\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the above program, we have initialized the number with zero. The loop tests for condition whether number is less that or equal to (le) 10 in each iteration. We have also used the statement number=$((number + 1)) to increment the number variable in each iteration.<\/p>\r\n&nbsp;\r\n\r\n<strong>Until Loop<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The until loop is reverse of while loop. The until command causes a block of code to be executed over and over, as long as the exit status of a specified expression is false.<\/p>\r\n&nbsp;\r\n\r\nSyntax of until loop is:\r\n\r\nuntil condition is false\r\n\r\ndo\r\n\r\nStatement(s) to be executed if condition is false done\r\n\r\nFollowing is a sample script that uses until loop.\r\n\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-230 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W26-1.png\" alt=\"\" width=\"555\" height=\"154\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the above script, notice that we have reversed the condition. The condition is reversed by using '!' sign. We can use either while or until loop. Both the loops behave in similar manner except the interpretation of condition.<\/p>\r\n&nbsp;\r\n\r\n<strong>For Loop<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The for loop of shell programming is different from conventional for loops used in C\/C++ or Java programming languages. In shell scripting, for loop iterates for the list of values specified. We provide a list of values within for loop construct, the looping variable picks up each value and iterates for 'n' number of values provided in the construct. Syntax of for loop is:<\/p>\r\n&nbsp;\r\n\r\nfor variable_name in list\r\n\r\ndo\r\n\r\ncommands\r\n\r\ndone\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The following script demonstrates the use of for loop. In this script the loop will iterate 3 times, in each iteration it will select word1, word2 and word3 respectively.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-231 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W27.png\" alt=\"\" width=\"554\" height=\"234\" \/><\/p>\r\n\r\n<div>\r\n<p style=\"text-align: justify;\">In the above script, the ls command is executed first to generate a list of files and directories. This list is used by the for loop to display line count for each file. We have also used file condition check to avoid the line count of directories, which may generate errors.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let us modify the above script where we accept file names as command line 13\u00a0<span style=\"text-align: initial; font-size: 1em;\">arguments (script parameters). The following script has to be executed by specifying command line arguments at $ prompt.<\/span><\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-232 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W28.png\" alt=\"\" width=\"566\" height=\"208\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the above script, we have used $* and $@ to list all the parameters passed at command line. As we have discussed in previous module, $* will treat all the arguments as a single string whereas \u201c$@\u201d will treat each argument as separate string. Here, we have to generate a list of file names in for loop which is to be processed separately, it is advisable to use \u201c$@\u201d instead of $*.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let us discuss another script that combines loop and case statement together. The following script will iterate until user enters '0' to exit the script. It uses until loop to repetitively ask for a choice and uses case to perform the operation according to the choice entered by the user.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-233 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W29.png\" alt=\"\" width=\"570\" height=\"369\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">We can enhance the functionality of shell scripts when we combine features of bash like command substitution, meta-characters, script parameters with loops and if statements. Looping constructs and if statements can be used to perform file processing. In the next module we will explore few features of file processing along with loops.<\/p>\r\n&nbsp;\r\n\r\n<strong>Summary:<\/strong>\r\n<ul>\r\n \t<li style=\"text-align: justify;\">Numerical calculations can be performed using expr, let or bc command.<\/li>\r\n \t<li style=\"text-align: justify;\">The test command provides conditions to compare numbers, check strings and check file attributes.<\/li>\r\n \t<li style=\"text-align: justify;\">The while loop and until loop iterate depending on some condition. while and until loop have similar syntax, however they are reverse of each other while checking for condition.<\/li>\r\n \t<li style=\"text-align: justify;\">The for loop iterates for a given list of words. The number of iterations depends on the count of words that are listed.<\/li>\r\n \t<li style=\"text-align: justify;\">We can enhance the functionality of shell scripts when we combine features of bash like command substitution, script parameters with loops and if statements.<\/li>\r\n<\/ul>\r\n<strong>Keywords:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">conditional statements, loop construct, test expression, commands:expr, let, bc<\/p>\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on Bash Shell Scripting - 2<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/B0RQs_nVAl0\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\r\n\r\n<\/div>\r\n<strong>References:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">[1] Jain, <em>100 Shell Programs in Unix<\/em>. Pinnacle Technology, 2009.<\/p>\r\n<p style=\"text-align: justify;\">[2] Garrels, <em>Bash Guide for Beginners (Second Edition)<\/em>. Fultus Corporation, 2010.<\/p>\r\n<p style=\"text-align: justify;\">[3] Isrd, <em>Basics Of Os Unix And Shell Programming<\/em>. Tata McGraw-Hill Education, 2006.<\/p>\r\n<p style=\"text-align: justify;\">[4] Seebach, <em>Beginning Portable Shell Scripting: From Novice to Professional<\/em>. Apress, 2008.<\/p>\r\n<p style=\"text-align: justify;\">[5] Foster-Johnson, J. C.Welch, and M. Anderson, <em>Beginning Shell Scripting<\/em>. John Wiley &amp; Sons, 2007.<\/p>\r\n<p style=\"text-align: justify;\">[6] Robbins and N. H. F. Beebe, <em>Classic Shell Scripting: Hidden Commands that Unlock the<\/em> <em>Power of Unix<\/em>. O\u2019Reilly Media, Inc., 2005.<\/p>\r\n<p style=\"text-align: justify;\">[7] Peters, <em>Expert Shell Scripting<\/em>. Apress, 2009.<\/p>\r\n<p style=\"text-align: justify;\">[8] G. Venkateshmurthy, <em>Introduction to Unix and Shell Programming<\/em>. Pearson Education India, 2005.<\/p>\r\n<p style=\"text-align: justify;\">[9] Festari, <em>Learning Shell Scripting with Zsh<\/em>. Packt Publishing Ltd, 2014.<\/p>\r\n<p style=\"text-align: justify;\">[10] Newham, <em>Learning the bash Shell: Unix Shell Programming<\/em>. O\u2019Reilly Media, Inc.,2005.<\/p>\r\n<p style=\"text-align: justify;\">[11] Rosenblatt and A. Robbins, <em>Learning the Korn Shell<\/em>. O\u2019Reilly Media, Inc., 2002.<\/p>\r\n<p style=\"text-align: justify;\">[12] E. S. Jr, <em>Linux Command Line<\/em>. NO STARCH Press, 2012.<\/p>\r\n<p style=\"text-align: justify;\">[13] Blum and C. Bresnahan, <em>Linux Command Line and Shell Scripting Bible<\/em>. John Wiley &amp; Sons, 2015.<\/p>\r\n<p style=\"text-align: justify;\">[14] Blum and C. Bresnahan, <em>Linux Command Line and Shell Scripting Bible<\/em>. John Wiley &amp; Sons, 2015.<\/p>\r\n<p style=\"text-align: justify;\">[15] Lakshman, <em>Linux Shell Scripting Cookbook<\/em>. Packt Publishing Ltd, 2011.<\/p>\r\n<p style=\"text-align: justify;\">[16] Tushar, <em>Linux Shell Scripting Cookbook<\/em>. Packt Publishing Ltd, 2013.<\/p>\r\n<p style=\"text-align: justify;\">[17] O. Burtch, <em>Linux Shell Scripting with Bash<\/em>. Sams, 2004.<\/p>\r\n<p style=\"text-align: justify;\">[18] K. Michael, <em>Mastering Unix Shell Scripting: Bash, Bourne, and Korn Shell Scripting for<\/em> <em>Programmers, System Administrators, and UNIX Gurus<\/em>. John Wiley &amp; Sons, 2011.<\/p>\r\n<p style=\"text-align: justify;\">[19] Johnson, <em>Pro Bash Programming: Scripting the Linux Shell<\/em>. Apress, 2009.<\/p>\r\n<p style=\"text-align: justify;\">[20] Veeraraghavan, <em>Sams Teach Yourself Shell Programming in 24 Hours<\/em>. Sams Publishing, 2002.<\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[21] Parker, <\/span><em style=\"font-size: 1em;\">Shell Scripting: Expert Recipes for Linux, Bash and more<\/em><span style=\"font-size: 1em;\">. John Wiley &amp; Sons, 2011.<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[22] F. A. Johnson, <\/span><em style=\"font-size: 1em;\">Shell Scripting Recipes: A Problem Solution Approach<\/em><span style=\"font-size: 1em;\">. Dreamtech Press, 2007.<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[23] Verma, <\/span><em style=\"font-size: 1em;\">Unix and Shell Programming<\/em><span style=\"font-size: 1em;\">. Laxmi Publications, 2006.<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[<\/span><span style=\"font-size: 1em;\">24] A. Forouzan and R. F. Gilberg, <\/span><em style=\"font-size: 1em;\">UNIX and Shell Programming: A Textbook<\/em><span style=\"font-size: 1em;\">. Brooks\/Cole-Thomson Learning, 2003.<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[25] P. Kanetkar, <\/span><em style=\"font-size: 1em;\">Unix Shell Programming<\/em><span style=\"font-size: 1em;\">. BPB Publications, 2002.<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[26] Sanchez-Clark, <\/span><em style=\"font-size: 1em;\">Unix Shell Scripting Interview Questions, Answers, and Explanations:<\/em> <em style=\"font-size: 1em;\">Unix Shell Certification Review<\/em><span style=\"font-size: 1em;\">. Equity Press, 2007.<\/span><\/p>\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[27] Taylor, <\/span><em style=\"font-size: 1em;\">Wicked Cool Shell Scripts: 101 Scripts for Linux, Mac OS X, and Unix Systems<\/em><span style=\"font-size: 1em;\">. No Starch Press, 2004.<\/span><\/p>","rendered":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/B0RQs_nVAl0\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<ol>\n<li><strong>Performing Calculations in Shell Scripting<\/strong><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the previous module, we have seen how to define a variable, assign values to the variable and retrieve the stored values. The values assigned to variables were treated as strings. When we want to perform numerical operations on these values, it cannot be done in a straight forward way like c=a+b because these variables contain strings. Let us see what happens if we perform simple addition operation on string.<\/p>\n<p>&nbsp;<\/p>\n<p>a=10<\/p>\n<p>b=15<\/p>\n<p>c=$a+$b<\/p>\n<p>echo &#8220;Total is: $c&#8221;<\/p>\n<p>Output:<\/p>\n<p>Total is:10+15<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the following sections, we will explore how to perform arithmetic operations on shell variables. There are four different ways used to perform calculations in shell scripting. These commands convert strings into numbers and perform the desired arithmetic operation. A programmer is free to use any of the following commands to perform arithmetic operations:<\/p>\n<ul>\n<li>expr (compiled application for integer arithmetic operations)<\/li>\n<li>Using $((&#8230;))<\/li>\n<li>let (built-in shell command)<\/li>\n<li>bc (compiled application for floating point operations)<\/li>\n<\/ul>\n<p>We can use the above techniques on command prompt as follows:<\/p>\n<p>&nbsp;<\/p>\n<p>$expr 2 + 5<\/p>\n<p>$echo $((2+5))<\/p>\n<p>$let x=( 2 + 5 )<\/p>\n<p>$echo $x<\/p>\n<p>$echo &#8220;2 + 5&#8221; | bc<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Commands like expr and bc are widely used by shell programmers. Techniques like $((&#8230;)) and let command are not used frequently, the main reason is probably they are not supported by other shells. Let us explore expr, let and bc commands in detail with sample shell scripts.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>expr : Evaluation Expressions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">expr command evaluates arithmetic expressions and helps to perform integer calculations. The syntax of expr is:<\/p>\n<p>&nbsp;<\/p>\n<p><strong>expr arg1 operator arg2<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Few Examples:<\/p>\n<p>$expr 2 + 3<\/p>\n<p>$a=5<\/p>\n<p>$b=10<\/p>\n<p>$expr $a + $b<\/p>\n<p>$expr $a \\* $b<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">It must be noted that the operator used for multiplication, asterisk (*) is treated as a wildcard character by shell, that is why we have to use escape sequence (\\) while performing multiplications.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The following shell script performs basic arithmetic calculations using expr command over two variables. Here we have used command substitution so that the expression gets evaluated first and the results are stored in the variable &#8220;ans&#8221;.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-213 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-1.png\" alt=\"\" width=\"693\" height=\"291\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-1.png 693w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-1-300x126.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-1-65x27.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-1-225x94.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-1-350x147.png 350w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Note: expr command can also be used to find the substring of a given string or length of a given string. We request you to read the manual of expr for more details. (use man expr)<\/p>\n<p>&nbsp;<\/p>\n<p><strong>let : Assigning and Evaluating expressions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The let command performs integer calculations as we did with expr command. However, when we use let command, there is no need to use the &#8216;$&#8217; sign with variables and use command substitution as with expr. let command evaluates the expression and stores the values in the variable. The syntax of let command is:<\/p>\n<p><strong>let variable=value\/expression [variable2=value\/expression&#8230;]<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-214 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-2.png\" alt=\"\" width=\"698\" height=\"218\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-2.png 698w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-2-300x94.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-2-65x20.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-2-225x70.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w14-2-350x109.png 350w\" sizes=\"auto, (max-width: 698px) 100vw, 698px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-215 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w15-1.png\" alt=\"\" width=\"692\" height=\"88\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w15-1.png 692w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w15-1-300x38.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w15-1-65x8.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w15-1-225x29.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w15-1-350x45.png 350w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>bc : Base Conversion<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The bc calculator can be used within shell scripts to perform floating point operations. However, while using in shell scripts, we have to pass the expression to bc using pipe (|) symbol. As we know that bc can be invoked from command prompt and allows us to perform calculations. We can also specify the variable scale to get precise answers while working with floating point numbers. The following script demonstrates the use of bc:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-216 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w16-1.png\" alt=\"\" width=\"696\" height=\"291\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w16-1.png 696w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w16-1-300x125.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w16-1-65x27.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w16-1-225x94.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w16-1-350x146.png 350w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><\/p>\n<ol start=\"2\">\n<li><strong> Decision Making<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Decision making is a key part of any programming language. Every language provides if-else statement for decision making within the programs. However, for each language the syntax and keywords may vary. Bash shell programming provides two different constructs for decision making. The programmer has a choice to use either of the followings:<\/p>\n<ul>\n<li>if-then-else-fi statement<\/li>\n<li>case-esac statement<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">The conditional statements in shell programming have far more capabilities when compared to those of programming languages like C, C++ etc. The main reason being, it allows us to use wildcard characters within the statement. Let us explore the syntax of each one of the above.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>If Statement<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The if-then-else statements are considered as control statements. Depending on the condition, selected statements are executed and hence it decides the flow of script. The if-then-else construct takes three different forms. Let us first see the syntax and later explore the scripts using these forms.<\/p>\n<p>&nbsp;<\/p>\n<p># First form if condition then commands<\/p>\n<p>fi<\/p>\n<p># Second form if condition thencommands<\/p>\n<p>else commands<\/p>\n<p>fi<\/p>\n<p># Third form if condition then<\/p>\n<p>commands elif condition then commands<\/p>\n<p>fi<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the first form, if the condition is true, then commands are executed. If the condition is false, nothing is done and the control comes out of the if statement.<\/p>\n<p>&nbsp;<\/p>\n<p>In the second form, if the condition is true, then the first set of commands is\u00a0executed and if the condition is false, then second set of commands is executed.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the third form, if the condition is true, then the first set of commands is executed, if the condition is false, and if the second condition is true, then the second set of commands is executed. In the third form, the if construct checks for two conditions.<\/p>\n<p>&nbsp;<\/p>\n<p>It must be noted that each if block ends with a fi. Let us see a simple script that demonstrates the working of if-else statement<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-217 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w17-1.png\" alt=\"\" width=\"706\" height=\"195\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w17-1.png 706w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w17-1-300x83.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w17-1-65x18.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w17-1-225x62.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w17-1-350x97.png 350w\" sizes=\"auto, (max-width: 706px) 100vw, 706px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The above script will try to display the contents of \/etc\/passwd file. If the cat command executes successfully (that is, exit status of cat is 0) then the \u201cFile \/etc\/passwd displayed\u201d message will be seen on terminal. In case if the cat command does not execute properly due to insufficient permissions or some other reason (exit status is 1)then the \u201cSome error occurred&#8230;\u201d message will be seen on terminal.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>test and [] command: companion of if<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The test command is used often with if statements to perform true\/false decisions. The test command can be used to compare numbers, check files and directories or check strings. The test command checks the expression and exists with status either 0 (expression is rue) or 1 (expression is false). The test command can be used with the keyword test or using the notation []. It takes two forms as shown below:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-218 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/w18-1.png\" alt=\"\" width=\"682\" height=\"106\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w18-1.png 682w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w18-1-300x47.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w18-1-65x10.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w18-1-225x35.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/w18-1-350x54.png 350w\" sizes=\"auto, (max-width: 682px) 100vw, 682px\" \/><\/p>\n<div>\n<p style=\"text-align: justify;\">The test command can be used for three main purposes in conjunction with if statement. Test can be used to:<\/p>\n<ul>\n<li>\u00a0Compare two numbers<\/li>\n<li>Compare two strings or a single string for null value<\/li>\n<li>Check the attributes of a file\/directory<\/li>\n<\/ul>\n<\/div>\n<p style=\"text-align: justify;\">test command can also be used with loop constructs within shell scripts, however, we will explore its usage with if statements. As such, test command does not display any output but simply returns a status of $?. We must take care that there has to be blank space between expression and square brackets (&#8216;[&#8216; and &#8216;]&#8217;). Let us explore how test can be used with the above conditions.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Numeric Comparison<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The test command can be used to compare two numbers. The comparison operators always begin with a \u2018\u2013\u2018 (hyphen) as shown in below table:<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-221 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W19.png\" alt=\"\" width=\"560\" height=\"488\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W19.png 560w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W19-300x261.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W19-65x57.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W19-225x196.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W19-350x305.png 350w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>The above script displays the larger number from the two numbers input by the user. We can use the following form:<\/p>\n<p>if test $a -gt $b instead of if [ $a -gt $b ]<\/p>\n<p>&nbsp;<\/p>\n<p><strong>String Comparisons<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Test command can be used to compare two strings for equality, it can also be used to check whether a string is null or not. The following table summarizes the operators used for string comparison.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-223 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W20.png\" alt=\"\" width=\"563\" height=\"439\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W20.png 563w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W20-300x234.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W20-65x51.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W20-225x175.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W20-350x273.png 350w\" sizes=\"auto, (max-width: 563px) 100vw, 563px\" \/><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Both the strings are different.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>File Checks<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The test command can be used to test various file attributes. It also tests whether a string is a file or a directory. The following table summarizes few parameters to check file attributes<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-224 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W21.png\" alt=\"\" width=\"558\" height=\"402\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W21.png 558w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W21-300x216.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W21-65x47.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W21-225x162.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W21-350x252.png 350w\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Case \u2013 Esac<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The following is a code which helps use to check whether the user has entered yes or no. However, there are few issues in the following program. The user may enter y for yes or YES in capitals. Under such circumstances, the following program may not give expected output.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-225 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W22.png\" alt=\"\" width=\"560\" height=\"162\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W22.png 560w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W22-300x87.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W22-65x19.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W22-225x65.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W22-350x101.png 350w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The above program has few logical bugs. What if the user enters Yes or YES or yes or Y or y. If we try to incorporate each test condition, the if-else statements will become too complicated. Such kind of issues can be well addressed by using case-esac construct rather than if-else statements. The following code looks much cleaner:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-226 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W23.png\" alt=\"\" width=\"559\" height=\"171\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W23.png 559w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W23-300x92.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W23-65x20.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W23-225x69.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W23-350x107.png 350w\" sizes=\"auto, (max-width: 559px) 100vw, 559px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The case-esac statements are generally used when there are multiple conditions to be checked. It also supports wildcard characters to match appropriate patterns. The syntax is:<\/p>\n<p>case $variable-name in<\/p>\n<p>patterns ) commands ;;<\/p>\n<p>patterns ) commands ;;<\/p>\n<p>&#8230;..<\/p>\n<p>esac<\/p>\n<p style=\"text-align: justify;\">The following script demonstrates pattern matching with case-esac construct. Using regular expressions within case statements, we can check whether the word entered by a user starts with a vowel or a consonant.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-227 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W24.png\" alt=\"\" width=\"554\" height=\"216\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W24.png 554w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W24-300x117.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W24-65x25.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W24-225x88.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W24-350x136.png 350w\" sizes=\"auto, (max-width: 554px) 100vw, 554px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let us see one more script where we check whether the single character entered by the user is a letter or a digit. Patterns like [:lower:] and [:upper] will classify the typed character as a lower case or upper case<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-228 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W25.png\" alt=\"\" width=\"575\" height=\"265\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W25.png 575w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W25-300x138.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W25-65x30.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W25-225x104.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W25-350x161.png 350w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/p>\n<ol start=\"3\">\n<li><strong> Loop Constructs<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Loops are important part of any programming language. They are used to perform iterative operations. Usually, a loop has a condition to identify the terminating criteria. A loop may iterate for &#8216;n&#8217; number of times depending on some condition. In bash shell scripting, we can use three types of loops. The following loop constructs are explored in this section:<\/p>\n<ul>\n<li>While loop<\/li>\n<li>Until loop<\/li>\n<li>For loop<\/li>\n<\/ul>\n<p><strong>\u00a0 \u00a0 While Loop<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The while command causes a block of code to be executed over and over, as long as the exit status of a specified expression is true.<\/p>\n<p>Syntax of while loop<\/p>\n<p>while condition is true<\/p>\n<p>do<\/p>\n<p>Statement(s) to be executed if condition is true done<\/p>\n<p>Here is a simple example of a program that displays from zero to ten:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-229 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W26.png\" alt=\"\" width=\"562\" height=\"157\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W26.png 562w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W26-300x84.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W26-65x18.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W26-225x63.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W26-350x98.png 350w\" sizes=\"auto, (max-width: 562px) 100vw, 562px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the above program, we have initialized the number with zero. The loop tests for condition whether number is less that or equal to (le) 10 in each iteration. We have also used the statement number=$((number + 1)) to increment the number variable in each iteration.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Until Loop<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The until loop is reverse of while loop. The until command causes a block of code to be executed over and over, as long as the exit status of a specified expression is false.<\/p>\n<p>&nbsp;<\/p>\n<p>Syntax of until loop is:<\/p>\n<p>until condition is false<\/p>\n<p>do<\/p>\n<p>Statement(s) to be executed if condition is false done<\/p>\n<p>Following is a sample script that uses until loop.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-230 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W26-1.png\" alt=\"\" width=\"555\" height=\"154\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W26-1.png 555w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W26-1-300x83.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W26-1-65x18.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W26-1-225x62.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W26-1-350x97.png 350w\" sizes=\"auto, (max-width: 555px) 100vw, 555px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the above script, notice that we have reversed the condition. The condition is reversed by using &#8216;!&#8217; sign. We can use either while or until loop. Both the loops behave in similar manner except the interpretation of condition.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>For Loop<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The for loop of shell programming is different from conventional for loops used in C\/C++ or Java programming languages. In shell scripting, for loop iterates for the list of values specified. We provide a list of values within for loop construct, the looping variable picks up each value and iterates for &#8216;n&#8217; number of values provided in the construct. Syntax of for loop is:<\/p>\n<p>&nbsp;<\/p>\n<p>for variable_name in list<\/p>\n<p>do<\/p>\n<p>commands<\/p>\n<p>done<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The following script demonstrates the use of for loop. In this script the loop will iterate 3 times, in each iteration it will select word1, word2 and word3 respectively.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-231 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W27.png\" alt=\"\" width=\"554\" height=\"234\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W27.png 554w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W27-300x127.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W27-65x27.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W27-225x95.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W27-350x148.png 350w\" sizes=\"auto, (max-width: 554px) 100vw, 554px\" \/><\/p>\n<div>\n<p style=\"text-align: justify;\">In the above script, the ls command is executed first to generate a list of files and directories. This list is used by the for loop to display line count for each file. We have also used file condition check to avoid the line count of directories, which may generate errors.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let us modify the above script where we accept file names as command line 13\u00a0<span style=\"text-align: initial; font-size: 1em;\">arguments (script parameters). The following script has to be executed by specifying command line arguments at $ prompt.<\/span><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-232 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W28.png\" alt=\"\" width=\"566\" height=\"208\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W28.png 566w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W28-300x110.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W28-65x24.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W28-225x83.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W28-350x129.png 350w\" sizes=\"auto, (max-width: 566px) 100vw, 566px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the above script, we have used $* and $@ to list all the parameters passed at command line. As we have discussed in previous module, $* will treat all the arguments as a single string whereas \u201c$@\u201d will treat each argument as separate string. Here, we have to generate a list of file names in for loop which is to be processed separately, it is advisable to use \u201c$@\u201d instead of $*.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let us discuss another script that combines loop and case statement together. The following script will iterate until user enters &#8216;0&#8217; to exit the script. It uses until loop to repetitively ask for a choice and uses case to perform the operation according to the choice entered by the user.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-233 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/W29.png\" alt=\"\" width=\"570\" height=\"369\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W29.png 570w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W29-300x194.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W29-65x42.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W29-225x146.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/W29-350x227.png 350w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">We can enhance the functionality of shell scripts when we combine features of bash like command substitution, meta-characters, script parameters with loops and if statements. Looping constructs and if statements can be used to perform file processing. In the next module we will explore few features of file processing along with loops.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Summary:<\/strong><\/p>\n<ul>\n<li style=\"text-align: justify;\">Numerical calculations can be performed using expr, let or bc command.<\/li>\n<li style=\"text-align: justify;\">The test command provides conditions to compare numbers, check strings and check file attributes.<\/li>\n<li style=\"text-align: justify;\">The while loop and until loop iterate depending on some condition. while and until loop have similar syntax, however they are reverse of each other while checking for condition.<\/li>\n<li style=\"text-align: justify;\">The for loop iterates for a given list of words. The number of iterations depends on the count of words that are listed.<\/li>\n<li style=\"text-align: justify;\">We can enhance the functionality of shell scripts when we combine features of bash like command substitution, script parameters with loops and if statements.<\/li>\n<\/ul>\n<p><strong>Keywords:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">conditional statements, loop construct, test expression, commands:expr, let, bc<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on Bash Shell Scripting &#8211; 2<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/B0RQs_nVAl0\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>References:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">[1] Jain, <em>100 Shell Programs in Unix<\/em>. Pinnacle Technology, 2009.<\/p>\n<p style=\"text-align: justify;\">[2] Garrels, <em>Bash Guide for Beginners (Second Edition)<\/em>. Fultus Corporation, 2010.<\/p>\n<p style=\"text-align: justify;\">[3] Isrd, <em>Basics Of Os Unix And Shell Programming<\/em>. Tata McGraw-Hill Education, 2006.<\/p>\n<p style=\"text-align: justify;\">[4] Seebach, <em>Beginning Portable Shell Scripting: From Novice to Professional<\/em>. Apress, 2008.<\/p>\n<p style=\"text-align: justify;\">[5] Foster-Johnson, J. C.Welch, and M. Anderson, <em>Beginning Shell Scripting<\/em>. John Wiley &amp; Sons, 2007.<\/p>\n<p style=\"text-align: justify;\">[6] Robbins and N. H. F. Beebe, <em>Classic Shell Scripting: Hidden Commands that Unlock the<\/em> <em>Power of Unix<\/em>. O\u2019Reilly Media, Inc., 2005.<\/p>\n<p style=\"text-align: justify;\">[7] Peters, <em>Expert Shell Scripting<\/em>. Apress, 2009.<\/p>\n<p style=\"text-align: justify;\">[8] G. Venkateshmurthy, <em>Introduction to Unix and Shell Programming<\/em>. Pearson Education India, 2005.<\/p>\n<p style=\"text-align: justify;\">[9] Festari, <em>Learning Shell Scripting with Zsh<\/em>. Packt Publishing Ltd, 2014.<\/p>\n<p style=\"text-align: justify;\">[10] Newham, <em>Learning the bash Shell: Unix Shell Programming<\/em>. O\u2019Reilly Media, Inc.,2005.<\/p>\n<p style=\"text-align: justify;\">[11] Rosenblatt and A. Robbins, <em>Learning the Korn Shell<\/em>. O\u2019Reilly Media, Inc., 2002.<\/p>\n<p style=\"text-align: justify;\">[12] E. S. Jr, <em>Linux Command Line<\/em>. NO STARCH Press, 2012.<\/p>\n<p style=\"text-align: justify;\">[13] Blum and C. Bresnahan, <em>Linux Command Line and Shell Scripting Bible<\/em>. John Wiley &amp; Sons, 2015.<\/p>\n<p style=\"text-align: justify;\">[14] Blum and C. Bresnahan, <em>Linux Command Line and Shell Scripting Bible<\/em>. John Wiley &amp; Sons, 2015.<\/p>\n<p style=\"text-align: justify;\">[15] Lakshman, <em>Linux Shell Scripting Cookbook<\/em>. Packt Publishing Ltd, 2011.<\/p>\n<p style=\"text-align: justify;\">[16] Tushar, <em>Linux Shell Scripting Cookbook<\/em>. Packt Publishing Ltd, 2013.<\/p>\n<p style=\"text-align: justify;\">[17] O. Burtch, <em>Linux Shell Scripting with Bash<\/em>. Sams, 2004.<\/p>\n<p style=\"text-align: justify;\">[18] K. Michael, <em>Mastering Unix Shell Scripting: Bash, Bourne, and Korn Shell Scripting for<\/em> <em>Programmers, System Administrators, and UNIX Gurus<\/em>. John Wiley &amp; Sons, 2011.<\/p>\n<p style=\"text-align: justify;\">[19] Johnson, <em>Pro Bash Programming: Scripting the Linux Shell<\/em>. Apress, 2009.<\/p>\n<p style=\"text-align: justify;\">[20] Veeraraghavan, <em>Sams Teach Yourself Shell Programming in 24 Hours<\/em>. Sams Publishing, 2002.<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[21] Parker, <\/span><em style=\"font-size: 1em;\">Shell Scripting: Expert Recipes for Linux, Bash and more<\/em><span style=\"font-size: 1em;\">. John Wiley &amp; Sons, 2011.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[22] F. A. Johnson, <\/span><em style=\"font-size: 1em;\">Shell Scripting Recipes: A Problem Solution Approach<\/em><span style=\"font-size: 1em;\">. Dreamtech Press, 2007.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[23] Verma, <\/span><em style=\"font-size: 1em;\">Unix and Shell Programming<\/em><span style=\"font-size: 1em;\">. Laxmi Publications, 2006.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[<\/span><span style=\"font-size: 1em;\">24] A. Forouzan and R. F. Gilberg, <\/span><em style=\"font-size: 1em;\">UNIX and Shell Programming: A Textbook<\/em><span style=\"font-size: 1em;\">. Brooks\/Cole-Thomson Learning, 2003.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[25] P. Kanetkar, <\/span><em style=\"font-size: 1em;\">Unix Shell Programming<\/em><span style=\"font-size: 1em;\">. BPB Publications, 2002.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[26] Sanchez-Clark, <\/span><em style=\"font-size: 1em;\">Unix Shell Scripting Interview Questions, Answers, and Explanations:<\/em> <em style=\"font-size: 1em;\">Unix Shell Certification Review<\/em><span style=\"font-size: 1em;\">. Equity Press, 2007.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em;\">[27] Taylor, <\/span><em style=\"font-size: 1em;\">Wicked Cool Shell Scripts: 101 Scripts for Linux, Mac OS X, and Unix Systems<\/em><span style=\"font-size: 1em;\">. No Starch Press, 2004.<\/span><\/p>\n","protected":false},"author":4,"menu_order":14,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["mr-hardik-joshi"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-212","chapter","type-chapter","status-publish","hentry","contributor-mr-hardik-joshi"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":8,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/212\/revisions"}],"predecessor-version":[{"id":691,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/212\/revisions\/691"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/212\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/media?parent=212"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapter-type?post=212"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/contributor?post=212"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/license?post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}