 Good morning, everyone. So, welcome to the second day of using Linux tools. We were, we had done until tap completion. Any quick questions so far? Yesterday we stopped and we did not keep any time for questions. We have time for a question or two now. Please ask now if you have any questions. Otherwise, we will continue with history. So, what is the slide? What does the slide say? Bash saves history of commands typed. Up and down arrows, up and down arrow keys allow to navigate history. Control R searches for commands used. So, let us see this in little more detail. So, let us look at all the commands that I typed. Here, PWD, LS, this is the directory we are in now. We can do up arrow mark one by one. So, I am pressing up arrow mark and slowly navigating through all the, all the commands I have typed. Not just today after starting the computer, not just after opening this terminal, but they are all there in some particular file called .history, .bash history. So, this is all there in the history. This is in fact, a command we had seen yesterday. So, by up, down arrow mark we can navigate. But then of course, if you think that you typed it only recently over the last 10 minutes, up, down arrow mark will be helpful. But then what if you, what if you, you, you vaguely remember that paste, the last time I used paste is exactly correct. So, you can press control R. Control R is for reverse search. Now, on the command prompt, we will type control R and then we type one letter P. The last command that had a P is PWD. We will continue to type A. Now, it says the last, it has already found paste word. Now, it does not help to type paste anymore. If you type paste, the same thing will keep coming S, T, E. Now, unless you type something else. So, please note on the screen whatever has come here, this corresponds to what you have typed. And this particular pattern has occurred for example, here. That is why it has found this command for us. Has it executed it already? No. It has just found this. As soon as you have satisfied with this, press enter, then it will execute it. So, what will it execute? We press control R, P, A, S. As you type more and more letters, it will keep looking for that pattern in the bash history. As soon as you have satisfied with what is coming on the screen, that this is indeed the command I had typed. These are all commands from your history. So, of course, when you search in your paste, this particular pattern may not come. So, yesterday you may not have typed precisely this, but something else. So, if your history, whatever commands are there, it will search through them and show you which is the recent most command that has this pattern. Which pattern? This particular pattern. Once you have found it, you have brought it to the screen. You can in fact, you can also make some small changes. Most of this is okay, but not marks 1 dot t, but marks dot t. So, you can, once it has come on the prompt, you can also edit, make some small changes and then execute it. So, please note that if it was removed something, then please do not blindly just type enter. You might have to make changes because that command will get executed again as soon as you press enter. So, please use this very carefully. Any other, just like control R is for reverse search on the bash shell. So, this is all, what is it that we are talking about? Let us go back to the slides. This particular bash, what is it? This bash is the shell that we are working in and this control R, up down arrow key, these are all features that bash provides for us. So, bash is some easy interaction for us on this particular shell, on this command prompt, on the terminal. So, another thing that we can know is control L, it is for clearing the screen. You can use this even after you have typed something, you want to just take this to the top of the screen, control L. Of course, you can also type clear, but to type clear, you should not have any command on the, you should not have already typed any command. Clear has to be the only command you type here, but if you have typed something long, L S and you have started typing something. After having typed something, you prefer to make the screen clean, that whatever you have typed will remain like that. Press control L and it has gone to the top. Control L is extremely helpful. It is something that bash provides for you to clear the screen. Clear is of course, actually the command. If you have already typed something and you want to delete, if you want to delete the whole thing, are we going to press backspace one by one. We are looking for lots of keyboard shortcuts. So, control U, we clear the entire line. If you have typed something and now we want to take the last two words. Why? Because this might be some big file name and we do not want to type it again. We have very carefully chosen this. So, control W, we will remove the last line, last word, again control W, we will remove the last word. So, these two words we have removed has got saved somewhere. Saved into some file? No, saved some buffer. Please do not ask me where is that saved. It is saved somewhere. It is useful to have it saved somewhere in some buffer. I will tell you how to retrieve it. That is the most useful thing. After we type something, something we had forgotten. Something we had forgotten is supposed to be typed here perhaps and we have typed something else and now we very neatly did control W one twice and saved two words into our memory, some memory. How will we reproduce it? Control Y, we will put those two words back. In fact, if you do control U and remove the whole thing and then you type something else, again control Y will remove, we will put back the entire thing you removed using control U. These are all different different things to remember. It is control U, control W, control Y has not been included in the slides, but then any typical bash help will provide all of this. If you are typing something, control C for cancelling. If you are, no, no, I was about to write, I was about to remove star dot star. Instead of pressing backspace, backspace control C will cancel that command. It will not execute it. So, what are some shell meta characters? So, the most of what we will spend today are more advanced things within bash. So, we will, the next thing we will see is something called meta characters. We already saw star as a meta character yesterday. So, what are all these? This slash is a meta character. What is the importance of this meta characters? These all characters are not going to be taken literally as a character. If you want, if you want to create a new file with star inside that name of that file, star as one of the characters, that is not allowed unless you, unless you tell that this has to be taken literally. So, these are all, these are all important meta characters which have some special significance, some special meaning. For example, slash we already saw was that if you have too much written on one line and you want to press enter, but not executed, that is when slash is helpful. Then greater than less than sign we already saw. Explamation mark is for pulling out something from the previously typed, if you already typed something then exclamation will reproduce that same command. So, dollar, what is dollar? We already saw that is how you extract out a shell variable. What is percent now? Somebody knows what percent? Percent is something and is for putting something into background, star, there is a whole lot of things. Star, star is important for all of us to know. It can be any, it can be any character there, any one character or more, no empty character, that is important to remember. Pipe we have already seen, open and close curly brackets are important, open and square, open and close square brackets are also, double quote we already saw. Open quote and close quote are important, they are different. Please note open and close quotes have different meaning, very different meaning. So, where are the two quotes now? In typically in all, in all windows environment we use only one quote, the quote that is next to the enter command. The quote that is next to the enter command, let me type here. This is what is vertical, it is so vertical and whether it should be open or closed really depends on the context, that is fine, but not for Linux on the prompt. On the command prompt, this is always going to be having a different meaning than another open quote, another quote which is just open quote. That one you will find above the tab key. So, please note this small difference, I can make this point even larger just for this purpose. Here is open quote, while here is the vertical quote. Vertical quote is what we will call closed quote, while this open one is one right above the tab key. So, open is extremely, extremely different meaning compared to closed. Closed is the vertical one. So, even for latex we have to pay attention to open and close differently unlike word or plain text, where you can always use just closed quote. Since it is vertical people will understand from the context whether it is open or closed, that is not the case in the environments. What meaning does it have? We will see very soon, star. So, let us go back to the slides, LS file dot star. Star can be any extension now, at least one letter is required. We will see an example here. So, if only one character is there that is also ok, but at least one character is required. So, let us see more significance of the star and the open quote. So, let us make a new file called touch, file 4 dot touch, file 4. Now, let us see LS file 4. How many completions are there? When we press tab two times, there is file, there is no x nothing further one option, s, s c, s e m i. Therefore, there could be many more. Why do not we put, why do not we list all of them? We press two tabs. When we press two tabs, there are many completions. In all those many completions, nothing further was included, surprisingly. But when we do star, star includes no character also. So, star includes at least one character is required was the best of my understanding. So, let me take back my words. When you take star, when you put star, no character is also allowed it appears. So, that is certainly not the case in many other search patterns. So, please always, please note this star whether it has to include some characters, any characters are allowed to be included there, any number of characters are allowed to be included there, but any number whether 0 is allowed or not depends on the context. As far as l s file 4 dot star is concerned, no character there meaning 0 number of characters is also allowed here, which was not the way I had understood so far. But then for some other places may be 0 character is not allowed. So, you please pay attention to this particular star later on. We do not want later on some surprises, some unexpected surprises. So, please note that star in many context requires at least one character, star is 0 or more character. Somebody has corrected from here, from I M C C Pune that star is 0 or more character. So, that is what we are checking. So, can I just request from I M C C Pune that is that star 0 or more character in all the contexts especially in the context of grep also. If you know please let me know, let us know on chat, we will just proceed to the next topic. So, please pay attention whether 0 number of characters also allowed or not in star is good to keep note. Another important, very important command is salt, l s minus l, why do not we see marks students, these are the various students. The clearly it is not sorted alphabetically, you might want to sort it alphabetically, sort students. This has shown the output of the sorting on the screen, the output has been spitted out on to the screen, on the standard output. Standard output is screen, so what can this sort do? It will show it on the screen. If you do not want it to come on the screen, you can always redirect it. If it comes on the screen, that is extremely advantageous. Why? Because you do not need read write, you do not need write permission in the directory where you are doing this text processing. After you know whatever is coming on the screen is correct, then you can always redirect it to a file you want to whatever path you specify. So, coming on the screen is advantageous. If you see that it is sorted exactly the way you want, then you can always pipe it to another command for example. In this particular, we can pipe it to something where what example, we can pipe this to what for example, if you for example, if you sort something and it is a very big file, then we can pipe it to less, to the command less, so that it screws one screen full at a time. For example, we might cat marks marks 1 dot marks 1 dot txt students after catting all this we could we could sort it, whether it makes sense or not to sort numbers and students that is another issue, but you can sort it after it is sorted it might be much more than one screen full, you can then pipe it to less. This is how it is sorted 1 2 3 4 5 6. So, let us see one can pipe it to less and after you are satisfied with the output you can always redirect it to a file. Why do not we copy marks another marks, because I am interested in explaining the significance of the n option n option for the sort command. Suppose we have these two extra columns two extra rows, 0 has come on the top, it has gone strictly by the fact that 0 comes before 6, 6 comes before 7, the first letter it is sorting equal to the first letter and it is sort is not trying to say 9 is less than 9 is more than 67, that is not the case. So, 0 of course is the first among these characters 9 is 9 more than 89. So, what do we do, how do we how do we try to say that sort by default means first column whatever comes first on the if we want it to go by the numerical value. So, that 0 should not be the first, 0 9 if it is there it should go by the value of 9 by for example, you might have file sizes you might want to sort equal to file sizes and then you want the value to be taken just because there is some 0 or 1 in the initial does not mean that the total value is less. Similarly, some less number of digits this is genuinely less than less than 67. So, we can do sort minus n, n for numerical value. So, now it has shown both of these together of course the two values are equal it will show any one of them first depending on the particular algorithm. Now, it has sorted based on numerical value, you could ask can I sort based on numerical value of the third column. So, this has sorted based on numerical value of the first column, but clearly third column is not sorted. We might say that n semester mark the final exam are very important let us sort all the students based on the marks they got only in the final exam not based on the total. So, you can say sort minus k 3 n what is this k what is this k 3 k just tells that it is a third column. After k means if you are putting k all these letters are there in if you see help sort. Now, it is asking us to type all this. Now, sort, sort help has given us some man sort yesterday somebody had typed on Moodle how to quit out of man. So, Q is the command to come out of the man, because manual page is default using something like less maybe it is using less itself. So, now you can do man sort and see various options k k had better be here it will tell according to this particular you can also specify sort equal to what key equal to some key default is default is space character. Now, you can also say then according to what particular now you should sort according to third column first column second column these are different options one can give. So, let us see sort is something I have already seen we can also sort based on numerical value you can specify a different delimiter using minus t option instead of space space is the default delimiter. Once you have specified the delimiter you can specify which column which field these are also called fields which field to use on each line these are different fields then nothing, but different columns based on the delimiter here delimiter d option in space but for sort it is a t option do not need to remember all this all you have to remember is this is possible open man sort and find it out you might also want to reverse the sort now instead of ascending you might want descending then you can just put the r option in many whenever you are listing something r r will reverse the sort reverse the listing. So, we have a question from Mufaka Mufaka Amjha college Hyderabad. So, why do not we start and take the question please ask your question now. Good morning sir actually two files are there using sort command using two files can be sort being at a time. Yeah we heard a question your question was whether we can sort two files at a time yeah whether the output is to be merged and then sorted or the two files are to be sorted separately and separate outputs are required that was not clear to us if separate outputs are required you have to do sort separately if you want to combine the output and then sort that is what we already did yeah please come back to the terminal. So, suppose we have students cat students yeah then we might have another file called let us say more students. So, please some of you had asked what editor to use BIM is the editor we will spend some time on later today please please. So, these are some different people who have slightly different names yeah Sven becomes a suddenly he becomes a Indian person. So, now cat students cat more students these are some more students different students yeah please note spellings are different students are different we might want to sort together. So, we can easily cat students more students we can cat all of them on the same yeah. So, if you are going to pipe it through sort anyway see here the output is going to be piped whatever has come on the screen is the concatenation of these two in what order you concatenate them does not matter why because you will anyway pipe it to sort command if you are piping it to sort command it does not matter in what order you concatenate them yeah when you now pipe it to sort you have the two things sorted together and of course, these these seemingly similar spellings are coming together we only change some letter not the first letter and that is now the two things are sorted together if you want to sort separate files then we can just run the command separately if you want to run sort students. Now, if you do not want to execute this this will come on the screen you can write this on a file sorted sorted students dot txt that is spelling mistakes in final names are ok you can always do this then you can do the next one if you do not like doing one first and then the other you can also put semicolon and type the other one sort more students yeah and that that the second one need not come need not get redirected. So, only the second one is shown on the screen the first one has got directed to a particular file which file whatever file name we gave here yeah both are both commands got executed in just one stroke one enter stroke because of this semicolon the semicolon was one of the meta characters did not spend time on there are so many meta characters yeah. So, batch detailed help is available on the net our slides do not have detailed help it is enough that we know these as far as our course is concerned. So, that is how we can sort multiple files multiple may with or without merging them depending on the requirement yeah if there are any more questions please use a hand raised button we will go further. So, reverse is for reversing the sort in many other like in many other cases. So, we will see now grep. So, grep is the command we had to use grep yesterday because many people had wanted to know how to cut the particular line instead of particular column. So, particular line removing is anyway far easier yeah one of the easy ways to do it is using grep, but then grep is not for removing just a line it is far more powerful than that yeah what are its various usages grep is a command line text search utility yeah it is a command for line search. If you so of course this example that is given here is rather long example let us see a simpler example let us see items this is a particular file which you only opened once. Now, we are interested in becoming politically more correct may be and replacing all man by man slash woman yeah why somebody might say why should man month be counted only for man man slash woman we are interested in all those lines where the word man occurs for various reasons yeah we are interested in searching for a particular pattern called pattern man and we want output as all those lines which have the word man which have the pattern man anywhere in it how do we do this grep man items. So, it has shown these lines having the pattern man yeah incidentally just like just like directory name was coming in blue color that may not always happen here the actual pattern has come in red color please do not bank on this yeah it might it may or may not come in red what is important is it has outputted only that line which had the word man there can be multiple occurrences on the same line there can be multiple lines with the word man they all will come on the screen what about grep man here now something else has come from journey man. So, grep is very much case sensitive by default it is case sensitive the the line that has actually come when you type capital man has not come now more over some other some other word some other line had small m and that has come now if you want grep to ignore case I now is not for interactive, but ignore case for man now you can yeah it will show this if you have decided to ignore the case then whether you type capital M yeah m a it will still show the same two lines why because this particular pattern the case of all these letters in this pattern has been ignored yeah. So, that is why both these lines have come is not what you type here is no longer important the case of this is no longer important. So, grep we can use it for searching for a pattern inside every line we can use it for many many more things yeah for example we might do LS one of the question yesterday was how do you look at all the files in not just current directory or sub directory its sub directory everything all together yeah not just that we might want to see the file sizes also that is something we will see little more detail I think there is a fine command inside the slides we will see how to find all sub directories later on in this in today only, but suppose we want to list minus L we already saw list of star dot txt but inside this whatever has come on the screen we can grep it what has it done let me make the font size smaller just for a minute inside every line wherever txt has come it has shown that yeah. So, this is how this is this is almost like LS minus L star dot txt of course txt could have come somewhere else also we can do also LS minus L and pipe it to grep looking for pattern 11 0 6 yeah 11 0 6 for example occurs here it is whatever file was modified today today 6 November yeah this is all these files are modified today last modified created they might have been created yesterday last modified is today that is why that that is a timestamp. So, grep can be used very effectively with pipe whatever comes on the screen you may first want to sort it after it is sorted you might want to look for a better file. So, grep can be used very effectively with after it after it is sorted you might want to look for a very specific pattern now for example. So, what we are whatever we are studying now is also called general regular expressions yeah general regular expressions. So, the best of my understanding is extremely important in computer science language language in automata theory in finite state automata yeah in finite state automata what all regular expressions what is regular about I think some finite length finite length words, but as far as we people who use Linux tools are concerned general regular expression means just looking for this pattern patterns as for finite length. For example, suppose we were looking for man inside which word items now we are see journey man we might not be interested in the man word that occurs inside some other larger word we might be interested only in the entire word man yeah this is out of general regular expression will allow you to do all this that space. Space separates words and we want man to have to be the beginning of a word or end of a word it means it could be on the end of the line and have a space before it could be on the beginning of the line. Many such many such very special requirements we might want how do we do that minus I better to use the code for all like this I think. Now, it will look for word man that occurs at the beginning of the word because of whatever I have highlighted man should occur also at the end of the word yeah both are required now you might only be interested in one of them as long as it occurs in the end of the word it is enough you might say now the journey man also has come luckily it was in the end of the word yeah. So, now you might also be interested in rep might be interested in the word yeah we might be interested in the programming word let us say rep for notice that you do not have to type fully yeah if you are looking for programming pattern you might look for just prog pattern prog will also be there inside programming. So, it has shown all of these you might say no no we want only the programming that occurs in the beginning of the line only those lines which begin with the pattern yeah you might want that for some various reasons who knows. So, we might say I want to put a begin character also there yeah begin character begin line character is not visible, but we want prog to be preceded by the begin line character for that we will put a hat. Now, it has shown only those lines which begin with this you might say I anyway programming we do not have to type fully we will type only ROG yeah ROG is anyway there inside programming. Now, how will you specify beginning of the one you want to say only now will this be okay no there is this letter P. So, well I am just spending one some letter is allowed there yeah that letter that dot means it can be anything dot can be any one character now neither 0 nor more one dot means one character yeah. So, one any one character and luckily all of them where happen to be P capital P. So, all these dot etcetera are extremely useful in my in my just last two years I have found lots of usage of dot hat end of the end of the line character all of these and detailed help is available in help grep in man grep. Let us see something more about grep is written okay I for case insensitive minus V for reverse yeah it will show if you if you want to see only those lines that do not have the search pattern you have to get default grep will show you those lines which have the grep have the search pattern if you are now interested in only those lines which do not have do not have the search pattern you have specified yeah then you will say minus V option yeah to say everyone marks except and marks for example yeah that is when we can do all this PR PR for translating or deleting characters extremely useful. So, TR comes from the takes its input from standard input takes its output from standard output please increase font size sorry. So, TR will make all capital to small small to capital it will allow replacing various things yeah. So, dash dash is just a shorthand for saying all from A to Z all the letters from A to Z should be replaced by capital letters from A to Z some nice notation rather than having to specify everything TR will just translate minus S suppressor sequences of identical adjacent yeah if there are multiple occurrences one after another TR will remove them TR will compress them into just one yeah this will for example if you want to remove multiple lines then slash n occurs multiple times meaning empty lines many many empty lines are occurring together that is when you can use suppress TR could also help you to delete certain characters only a single character yeah. So, please see this carefully if you have some doubts you can ask we will spend some time on this yeah. So, let us do like this yeah I hope all of you have downloaded this item test underscore files zip directory from Moodle if you have not just do like this slash ETC slash password copy as password file yeah no need to go to Moodle now download just copy this we want some test file to try out all this TR commands now on this you try this TR TR minus let us see what this password is yeah these are the different things there TR minus C C for complements the first set of characters we can do D to begin with D and then delete a particular character yeah let us see what this what is that this suppose you want to delete all colon character yeah or we want to replace colon character TR cat with hash. So, this has replaced all colors with hash you can try to delete one some character while I just quickly come in a minute TR can also help us delete various characters it says we can also complement various characters what exactly complement means try this out yourself you will immediately know we might want to remove all alpha non-alpha numeric characters yeah we might want to remove alpha numeric characters meaning what you will only leave all the special symbols colon hash yeah you want to remove all numbers you want to remove all alphabets but there are whole lot of other symbols that you want to keep conversely we might want to remove them we might remove all this non-alpha numeric characters this is how you can specify them that is where square brackets are extremely important unique let us see the next command called unique what is this unique do it will it will unique it there are multiple things multiple lines which are repeated they will get removed yeah. So, after we sort we might know that there are many guys names are repeated we will not know that these names are repeated until you sort them yeah let us see look at students here there are some two there are some yeah we created this list by catting the same files that is expected that they will be repeated but they will not be occurring together yeah quite understandably. So, we can instead of piping it to less we will pipe it to sort they have come together then we can pipe it to unique yeah we could try to pipe it to unique directly yeah now it is not removed why because these multiple occurrences do not occur consequently they do not occur consecutively if they occur consecutively only then they are removed by unique if you want to remove it sort you first pipe it to sort and then unique it yeah. So, incidentally you may or may not want to sort something while doing unique if you want to do unique with sort then I happen to know that minus u option we also do it in sort often very often we use sort and then unique that is why sort itself has given us this option minus u. But then let me tell you there are many situations where we want to use unique without sorting yeah we want that if they are separately placed they should be separately placed still multiple occurrences have to be removed that is also yeah and it will unique it only if the entire line is the same just because first word is the same does not is not enough for removal of this multiple occurrences unique minus u gives line which do not have any duplicate yeah minus u will show you only those lines which are unique to begin with minus d will show you those output which actually had duplicates you can check whether this duplicate will also include triplicate 4 or not this duplicate means multiple occurrences I think but you please check this yourself minus c displays the number of times each line occurs yeah you might want to know that somebody has again again type the same thing you want to know actually how many times this mistakes have been done you want to know how many times this multiple occurrences have occurred that is when this c option it will count c for count simple shell scripts any doubt so far the next topic is going to take lot of time okay simple shell scripts is the next topic we will see simply a sequence of shell commands in a file yeah if you are going to do the same thing repeatedly again again why do not we type all this commands into a file and execute that file and that file is like our command whatever whatever command you want to type you type it nicely into some particular file and run it from there yeah now I have to also tell you what editor to use what editor to use for typing some command for example cat students minus u this particular this particular command is the first thing that we will first type into a file why because we might want to do this repeatedly again and again somebody gives us some student's file and we want to execute this yeah and we want to redirect it to something rather than it coming on the screen you might want to redirect it to sorted unique unique file yeah suppose this is our objective but we want to each time somebody gives us a students.txt file we do not want to again do this yeah why do not we write this into one particular file so now you please do exactly what I am doing just copy this I assume everybody is using Linux yeah everybody is using Ubuntu Linux in that you just copy it like this using your mouse then we will do we will cancel this we will not execute this we have just copied all that into some buffer some different buffer yeah by our mouse we have no you do not have to press control c or anything for copying as soon as you copy it in your mouse you have already it is there in that buffer how to retrieve it is what I will tell now you do nano nano cat cat catting dot sh some some shell we are we are writing a simple shell script for writing a simple shell script we have opened an editor this is the first time we are opening an editor in this course so now we have opened an editor we are free to type what we want so we will go first line it is default it will open first line and for those who have mouse with three buttons press the middle button for those whose mouse has three buttons press the middle button where is the middle button for those whose mouse has only two buttons very very few people know about this surprisingly you press both together then it is like middle button yeah so please press them you press both together at the same time then that will copy whatever you had carefully copied it will paste it will paste whatever you had copied this you have copied it so this is as you can see this is too long you can put this I think this is yeah after you have copied this into this you may or may not want to split it to two lines if you keep it on one line it is okay now we are going to quit out of this and come out yeah how do you come out control x it says at the bottom see here it says control x for exit when you are exiting it will ask you whether you want to save or not we will save it it will now because they are trying to exit it is saying do you want to save or not you press yes now and it will ask you default is this the file name you want to save yeah we started with this file name why don't we continue with the same file name okay so we have now created a new file called catting.sh how did we type this all this we opened it into an editor into the nano editor in the nano editor we did not type everything because we are all very lazy we copied everything using the mouse and then we pasted it for those who of you who have three mouse buttons middle button will paste it and for those of you whose mouse has only two buttons pressing both together typically will make it like three mouse like the middle button of a three mouse so let us see whether it we have really succeeded in typing properly or not yeah so you put cat show it on the screen you also see okay so now whatever command we are supposed to execute that is all come into one file now we want to learn how to execute this file yeah is this so this is only our command now we have created a new command by combining some old commands cat was a command we piped it to sort with some option you all that whatever is screen is whatever is seen on the screen yeah up to here this control C is because I cancelled it I press control C to cancel it I did not execute it if this is a command why do not we execute it catting not a search why don't we catting not a search command not found it doesn't know that catting not a search is a command yeah you you decided it to be a command you opened an editor and typed everything but how does this shell know that that this is supposed to be a command so we will so default commands are found in some long path every word you type it will look for that particular file in some big path how to find what how to see what that path is we will see very soon so now we have to tell our script that we have that catting file is kept here only in the current directory why don't we type this this we are telling where that commander it could not find it now we are telling it yeah so we try to execute it now we are trying to execute this particular file so I request all of you to try this try to execute it and be told that the permission is denied yeah then that is then we will do what whatever is to be done next we will do after that so we have another question from Perrier Manami Tanjavur questions between approach and grip so the question from Perrier was what is the difference between the approach and grip see grip is for looking for a particular pattern inside a file it is something completely we know we want to look for a pattern in what in what file do we want to look for the pattern in the file that we will specify to grip approach is totally different if you if you think there is some command that day in that course in SDS course we were told of some command which is which is for searching regular patterns yeah did it start from G or that you name you name for example I was telling you to starting from U but what is that command for what for setting permissions so permission is the important word then you say apropos permissions apropos permissions when you do it will tell you various commands which all have permission word inside its help page yeah I think it will have permissions word inside the what is page so apropos is for looking in more detail about all the commands that have some specific word and you might know only that word yeah if you know for unique for for removing multiple occurrences unique was the command but this unique how will you remember it is not even the correct English spelling UNIQUE is this actual English spelling but now these people have made a different spelling you might want you do not you don't have to remember all these different wrong wrong spellings yeah so you will say apropos the apropos you have to remember unfortunately yeah apropos unique it will tell you all these commands are something to do with unique surprisingly unique word itself is not okay so the question was what is the difference between apropos and chat so in that context we started seeing that grep is for a very specific purpose that you want to search for a pattern inside a file that is when you will say grep pattern file yeah this is a general regular expression for finding a regular expression inside a file instead of searching in a file you can also pipe that file information through a pipe as the output of another command you can give it to grep of course but pattern of course you have to type now on the other hand apropos is different apropos is for a very specific purpose it is if you vaguely remember that some particular we were told about some command for you for removing a removing directory for removing directory what was the command RM are all short forms surely we are not obliged to remember short forms yeah we it's enough that we know what is the command for removing remove yeah why don't we do apropos remove it will tell us all this and says oh yeah RM is the one apropos is for that purpose it's a different purpose yeah now for example yeah I for unique apropos what was the command for unique was it unique yeah we say unique unique some file marks one dot txt yeah the unique is not even there it's we after a few days you will have forgotten that unique command how do you find out what is the command you say apropos unique we hope UNIQ is there inside this list yeah is it there inside that list oh last one is there last yeah so unique word is there this is the word that we were looking apropos is for that purpose their purpose is that clearly different and grep is for searching for a pattern inside a file of course instead of searching in a file you can pipe that pipe that information through as output of another command so we had been we had been writing a particular command inside a file and then we are trying to execute that then we are trying to execute that I hope everybody has tried to do this it says permission not permission denied that is because let us see LS minus L getting says it is only read and write permission to the user no execute permission yeah if you have not given execute permission for yourself and then if you try to execute this as a command yeah so please note there are other ways of executing this SH file here the way it is written the first thing that comes is command we are now trying to execute this as a command yeah so we should give execute permission to this file so for those who already practice that other number way of giving permission 7 0 0 will give execute permission yeah you might also want to say CH mode for those who please do not ask questions about 7 5 4 now because we already saw this other way user plus execute for catting any one of these two commands is enough I am typing both for those of you who know only one of these now let us see LS minus L yeah so notice that it has been it has given execute permission further it has changed the color also this also be noted yesterday now let us see this upper thing yeah now it has it says there is some error except for that error it has executed for those of you who would have put it in one line for them it would have executed so what we have to now go and see is this particular symbol was not supposed to be that it was supposed to be this character yeah so now again we have open nano we have made that small change now let us execute it so now it has executed fully to execute fully means what it has recreated sorry it has recreated this sorted sorted unique file this file has got created by execution of catting dot sh yeah whatever you wrote inside that has got executed what got executed this particular command has got executed yeah so this is what we will call a shell script now it is convention it is good to write you might be exchanging this catting dot sh with various people so it is good to write sorry it is good to write on the top this to say that sorry not pipe exclamation mark is important sometimes it is important to write this if you are working in bash it is not compulsory if you already if somebody is going to try to execute this in bash it is not compulsory but somebody else you might give this there are various shells bash is just a very popular shell there is some C shell there is a plain shell just sh there is a K shell T C SH yeah T C SH is another shell different people will be exchanging this so for other shells it is really required that you write this on the top yeah so inside the bash script itself inside the bash script comments are written in this comments these these lines are not executed yeah but but the first line first line is telling that you are going to write a bash script please note that for us it doesn't matter why because we will always be executing in bash only this line doesn't matter and if you want to write comments please write hash in the beginning whatever not just in the beginning whatever is written after the hash on each line that will not be executed that is like comment of that line if if hash is the first letter that comes on a line then that entire line is comment again we are saving this and quitting coming out yeah so are there other ways of executing this somebody has written on chat SH catting dot SH you also do this why don't we what let's do like this if the if the file is executing we are not able to see that it is executed why don't we remove that why don't we make this change we go there and remove this why because it is writing to a file it is executing and nothing is coming on the screen now where because they have removed that redirect it will come on the screen when it is executing we will know look it has executed yeah this is our catting file now it has executed this executed means what from here to your output has come yeah are there other ways yeah if you if permissions are not given yeah it might it might turn out that you're not the owner of that file yeah you might you might have gone to somebody's directory and you want to execute the file there and you don't have you're not the owner of the file you cannot change the permission source catting dot SH will also will also execute it without without execute permission and now the command is source it will just execute this the source is a very useful thing for dot bash RC for example dot bash RC is not a command but you want to still execute it that is when dot is that source is required also dot does the same thing I don't know what is the exact difference between source and dot in all the usages it does it behaves the same way some these some such things are not there in the slides but as said somebody told I didn't know about this SH catting also does the same yeah good to know maybe in that case bash also might do bash you know to execute the bash script cutting dot SH so let us see some more complicated shell scripts yeah this is as of now we use this just as a shortcut you write it each time to execute is easier now yeah now but of course what each time when you want to execute each time this file name important information has to still be in this file yeah just for example it is it happens to be the same file but what if different different files you don't want each time to specify in the same file yeah so these are things we will see next so we only saw about the permission giving etc now shell variables yeah so now let us see this particular script so name name equal to foci so this dollar is different from this dollar yeah this dollar is a prompt yeah so on my computer let me change the prompt so that it is not confusing anymore you can also try this PS 1 I don't be put PS 1 equal to hash greater than yeah we will put one space if you are going to put space inside the prompt then you have to put close code each time it is close code only open code has a very important different meaning what is it meaning we have not seen yet we'll see later so from now on this is my prompt yeah why because we don't want this dollar this dollar is almost suggesting it some shell variable or something we have changed our prompt but in the when the slides are made this there is this dollar let's go back to the slides there is this dollar this dollar is certainly very different from this dollar yeah what does this do name equal to foci count equal to word count minus l wonderland or txt yeah it will execute this this please note that this particular quote is open quote this is the quote sitting above the tab key is different from close code the close quote is the vertical one the vertical one is the one we used to modify our prompt for those who are not interested modifying the prompt don't worry about yeah modifying the prompt is not so important close code is different from open code here we have open code so whatever you put in between two open code yeah we start with open code we also end with open code might seem contradictory here also we have the same key above the tab key here also we have open code whatever is between open codes is executed and the output of that is assigned to the variable count yeah count is some variable we are introducing what is getting assigned to that variable you can assign some number to it for example name is another variable we have assigned foci to it instead of foci if you want the output yeah you let us let us do this what does it say name equal to foci how do we see whether this has succeeded or not echo sorry echo name tab key should work that is how you will know there is a mistake the name what is out what if you want to read out the the value of a particular variable then you have to use dollar yeah if you say echo just name it will echo it will echo will whatever you type on the screen let go whatever you type on this after the echo it will just put it on the on the screen but we are not interested in actually name we want to see the value of the variable name for that we will put dollar yeah now for count count equal to what what do we want as a value word count minus l l perhaps is only the number of lines Wonderland what has got assigned to count let us see this command first word count minus l Wonderland dot txt this has told us 4047 Wonderland dot txt and this is the output of the command word count minus l Wonderland dot txt that output instead of making it come on the screen name assigned it equal to is assigning assigning whatever is after the equal to sign into count but is it going to assign literally this no because this is open code this is sitting above the tab key because it is open code the it will get executed whatever is between open codes will get executed after it is executed what had come out this whole thing had come out this whole thing will get assigned to the variable count yeah how do we see that count it will just echo count it does not know you are interested in the value of the variable count echo yeah so that particular output has got assigned to count and then you need able to see it you might want to say you know I was interested only the number 4047 they are not in this word why don't we pipe it okay sorry why don't we do this more slowly let's go back to this using a paro key here and we want cut my delimiter minus f1 yeah only the number 4047 has now come why because we have removed the second column Wonderland dot txt we don't want yeah we only want 4047 so this particular value we can assign to count now echo count yeah bash with bash you can do a whole lot of programming also yeah we are going to of course do much more amount of programming that's why we'll teach python but with bash you can do many such evaluate various things get it you can actually add these numbers yeah just like we multiply add in simple programming languages this is possible in bash also so many same videos not available that might be a bandwidth problem okay please note come back to the slides please note that there is there should be no space before or after the equal to sign in python we will certainly like to keep a space for better readability but now in bash it had better not be there all text following the hash is a command is a command echo command just prints the output yeah make directory this you can do this and it will you can also type all this into a particular file and execute it so whatever is whatever is written here can be put into a file and can be executed yeah I can encourage you to try it but no need to do now somebody is asking me to repeat the prom change prom change is not important yeah anyway all this is recorded you can do up aroma key you can see later we will not repeat that part