In the process flow, it is explaining when the for loop starts, iterator value, checking the condition if satisfies then runs the process otherwise end the process. In the above flow diagram, we are explaining the flow of for loop which is iterating over a list of filenames and there are four steps in the flow such as process flow, variable value, process, and stdout. Let us consider an example of for loop and discuss the flow of it using the flow diagram. Flow Diagram – For loop in Shell Scripting
The execution in above for loop will start like this, before starting off first iteration expr1 is executed which means initialization will be done after than operations/commands between do and done will be executed iteratively until expr2 evaluates to true and after every iteration expr3 updates the iterator value (counter) so that operations will be performed on next element or value in the list or array or string. In for loop, there are three expressions where the first expression is for initialization, second is for conditional check and the third is for updating iterator. In the above syntax, if we observe this syntax is similar to the syntax of for loop in the c programming language. For example, if the size of the list is 5 having numbers from 1 to 5 then during the first iteration 1 will be store in var and operations on var will be performed by the body of the for loop where commands are there. In the above for loop, it will execute all the commands which are there between do and done for n number of times where n is the size of the list. If a list is not provided then bash will take a positional parameter which we passed in the shell. whereas list is a list of variables or a list of words or a list of numbers and var is a variable name during that iteration. First Syntax Methodįrom the above example, we have pre-defined keywords or built-in keywords such as for, do, done, and in. Hadoop, Data Science, Statistics & others 1.