Difference between revisions of "BASH/C2/More-on-Loops/English-timed"
From Script | Spoken-Tutorial
Sandhya.np14 (Talk | contribs) |
|||
Line 5: | Line 5: | ||
|- | |- | ||
| 00:01 | | 00:01 | ||
− | | Welcome to the spoken tutorial on '''Nested for loop in BASH''' | + | | Welcome to the '''spoken tutorial''' on '''Nested for loop''' in '''BASH'''. |
|- | |- | ||
| 00:07 | | 00:07 | ||
− | | In this tutorial, we will learn '''Nested for loop''' | + | | In this tutorial, we will learn '''Nested for loop''' with the help of an example. |
|- | |- | ||
| 00:13 | | 00:13 | ||
− | | To record this tutorial I am using '''Ubuntu Linux''' 12.04 '''Operating System''' and '''GNU BASH''' version 4.1.10 | + | | To record this tutorial, I am using '''Ubuntu Linux''' 12.04 '''Operating System''' and '''GNU BASH''' version 4.1.10 |
|- | |- | ||
Line 25: | Line 25: | ||
|- | |- | ||
| 00:37 | | 00:37 | ||
− | |For relevant tutorials, please visit our website which as shown http://spoken-tutorial.org | + | |For relevant tutorials, please visit our website which is as shown- http://spoken-tutorial.org |
|- | |- | ||
Line 33: | Line 33: | ||
|- | |- | ||
|00:46 | |00:46 | ||
− | |A loop within a loop is known as '''nested loop.''' | + | |A '''loop''' within a '''loop''' is known as '''nested loop.''' |
|- | |- | ||
| 00:51 | | 00:51 | ||
− | | Let us see the syntax Outer '''for loop''' '''expression 1, 2, 3''' | + | | Let us see the syntax. Outer '''for loop''' '''expression 1, 2, 3'''; |
|- | |- | ||
| 00:57 | | 00:57 | ||
− | | | + | |inner '''for loop''' '''expression 1, 2, 3'''; |
|- | |- | ||
| 01:01 | | 01:01 | ||
− | | '''statement 1''' '''statement 2''' | + | | '''statement 1''', '''statement 2''' |
|- | |- | ||
| 01:04 | | 01:04 | ||
− | | | + | | closing inner '''for loop''', closing outer '''for loop'''. |
|- | |- | ||
Line 57: | Line 57: | ||
|- | |- | ||
| 01:12 | | 01:12 | ||
− | | First let us go through the directory structure. | + | | First, let us go through the '''directory structure'''. |
|- | |- | ||
Line 65: | Line 65: | ||
|- | |- | ||
| 01:24 | | 01:24 | ||
− | | We have | + | | We have sub-directories '''test''', '''test2''', '''test3''' and a '''Bash script'''. |
|- | |- | ||
Line 73: | Line 73: | ||
|- | |- | ||
|01:36 | |01:36 | ||
− | | Now we will move on to our code. | + | | Now we will move on to our '''code'''. |
|- | |- | ||
|01:39 | |01:39 | ||
− | |This program displays all the files within each | + | |This program displays all the files within each sub-directory. |
|- | |- | ||
|01:45 | |01:45 | ||
− | |Please note that the same can be | + | |Please note that the same can be achieved with a '''single line command''' '''ls -1 (hyphen one) -R(hyphen R) test*(test asterix)'''. |
|- | |- | ||
Line 89: | Line 89: | ||
|- | |- | ||
| 01:58 | | 01:58 | ||
− | | Note that the name of our''' Bash script''' is''' nested-(Hyphen)for dot sh''' | + | | Note that the name of our''' Bash script''' is''' nested-(Hyphen)for dot sh'''. |
|- | |- | ||
Line 101: | Line 101: | ||
|- | |- | ||
|02:10 | |02:10 | ||
− | |This '''for loop''' will check for directories starting with the name '''test'''. | + | |This '''for loop''' will check for '''directories''' starting with the name '''test'''. |
|- | |- | ||
|02:15 | |02:15 | ||
− | |First '''echo''' line will display the sub-directories name | + | |First '''echo''' line will display the sub-directories name. |
|- | |- | ||
Line 113: | Line 113: | ||
|- | |- | ||
| 02:25 | | 02:25 | ||
− | | This is the inner '''for loop'''.It will check for files present within the directories. | + | | This is the inner '''for loop'''. It will check for files present within the directories. |
|- | |- | ||
Line 125: | Line 125: | ||
|- | |- | ||
| 02:41 | | 02:41 | ||
− | | Here we list the files.'''done''' ends the inner '''for loop'''. | + | | Here, we list the files. '''done''' ends the inner '''for loop'''. |
|- | |- | ||
|02:45 | |02:45 | ||
− | |This command prints a vertical line after completion of every cycle of outer '''for-loop.''' | + | |This '''command''' prints a vertical line after completion of every cycle of outer '''for-loop.''' |
|- | |- | ||
Line 137: | Line 137: | ||
|- | |- | ||
| 02:57 | | 02:57 | ||
− | | Let us execute the program. | + | | Let us '''execute''' the program. |
|- | |- | ||
Line 153: | Line 153: | ||
|- | |- | ||
|03:15 | |03:15 | ||
− | |Type '''cd Desktop'''. Let us go in the folder '''simple-(Hyphen)nested-(Hyphen)for''' | + | |Type: '''cd Desktop'''. Let us go in the '''folder''' '''simple-(Hyphen)nested-(Hyphen)for'''. |
|- | |- | ||
Line 161: | Line 161: | ||
|- | |- | ||
| 03:24 | | 03:24 | ||
− | | Type '''chmod plus +x nested-(Hyphen)for dot sh''' | + | | Type: '''chmod plus +x nested-(Hyphen)for dot sh''' |
|- | |- | ||
Line 169: | Line 169: | ||
|- | |- | ||
|03:34 | |03:34 | ||
− | |Type dot slash '''nested-(Hyphen)for dot sh''' | + | |Type: dot slash '''nested-(Hyphen)for dot sh''' |
|- | |- | ||
Line 177: | Line 177: | ||
|- | |- | ||
|03:40 | |03:40 | ||
− | |The output is displayed. It shows | + | |The '''output''' is displayed. It shows files in '''test''' directory, files in '''test2''' directory and files in '''test3''' directory. |
|- | |- | ||
|03:52 | |03:52 | ||
− | |This brings us to the end of this tutorial. | + | |This brings us to the end of this '''tutorial'''. |
|- | |- | ||
|03:56 | |03:56 | ||
− | |Let us summarize.In this tutorial we | + | |Let us summarize. In this tutorial we learned '''Nested for loop'''. |
|- | |- | ||
| 04:02 | | 04:02 | ||
− | | As an assignment | + | | As an assignment: |
|- | |- | ||
|04:04 | |04:04 | ||
− | |Retype '''nested (hyphen)-for dot sh bash script using nested while loop.''' | + | |* Retype: '''nested (hyphen)-for dot sh bash script using nested while loop.''' |
|- | |- | ||
|04:11 | |04:11 | ||
− | |Save your program with the name ''''nested-(hyphen)while Dot sh'''' | + | |* Save your program with the name ''''nested-(hyphen)while Dot sh''''. |
|- | |- | ||
| 04:17 | | 04:17 | ||
− | | Watch the video available at the link shown below.It | + | | Watch the video available at the link shown below. It summarizes the Spoken-Tutorial project. |
|- | |- | ||
| 04:23 | | 04:23 | ||
− | |If you do not have good bandwidth, you can download and watch it | + | |If you do not have good bandwidth, you can download and watch it. |
|- | |- | ||
| 04:28 | | 04:28 | ||
− | | The Spoken Tutorial Project | + | | The Spoken Tutorial Project team: |
+ | * Conducts workshops using spoken tutorials. | ||
+ | * Gives certificates to those who pass an online test. | ||
|- | |- | ||
Line 217: | Line 219: | ||
|- | |- | ||
| 04:45 | | 04:45 | ||
− | | Spoken Tutorial | + | | '''Spoken Tutorial''' project is a part of the '''Talk to a Teacher''' project. It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
|- | |- | ||
| 04:57 | | 04:57 | ||
− | |More information on this | + | |More information on this mission is available at: http://spoken-tutorial.org\NMEICT-Intro |
|- | |- | ||
Line 229: | Line 231: | ||
|- | |- | ||
| 05:08 | | 05:08 | ||
− | |This is Ashwini Patil from IIT Bombay.Thank You for joining. | + | |This is Ashwini Patil from IIT Bombay. Thank You for joining. |
|} | |} |
Revision as of 21:25, 3 July 2015
Time | Narration |
00:01 | Welcome to the spoken tutorial on Nested for loop in BASH. |
00:07 | In this tutorial, we will learn Nested for loop with the help of an example. |
00:13 | To record this tutorial, I am using Ubuntu Linux 12.04 Operating System and GNU BASH version 4.1.10 |
00:24 | Please note, GNU Bash version 4 or above is recommended for practice. |
00:31 | To learn this tutorial, you should be familiar with loops in Bash. |
00:37 | For relevant tutorials, please visit our website which is as shown- http://spoken-tutorial.org |
00:43 | Let us start with an introduction to nested loop. |
00:46 | A loop within a loop is known as nested loop. |
00:51 | Let us see the syntax. Outer for loop expression 1, 2, 3; |
00:57 | inner for loop expression 1, 2, 3; |
01:01 | statement 1, statement 2 |
01:04 | closing inner for loop, closing outer for loop. |
01:09 | Let us see an example on nested for loop. |
01:12 | First, let us go through the directory structure. |
01:17 | Here is a directory on the Desktop named simple-nested-for. Let's open it. |
01:24 | We have sub-directories test, test2, test3 and a Bash script. |
01:31 | In each sub-directory, there are multiple text files. |
01:36 | Now we will move on to our code. |
01:39 | This program displays all the files within each sub-directory. |
01:45 | Please note that the same can be achieved with a single line command ls -1 (hyphen one) -R(hyphen R) test*(test asterix). |
01:53 | But we will do it using a for loop. |
01:58 | Note that the name of our Bash script is nested-(Hyphen)for dot sh. |
02:05 | This is our shebang line. |
02:08 | This is the outer for loop. |
02:10 | This for loop will check for directories starting with the name test. |
02:15 | First echo line will display the sub-directories name. |
02:21 | The second echo line will create a blank line. |
02:25 | This is the inner for loop. It will check for files present within the directories. |
02:32 | ls displays the directory content. |
02:36 | -1 (hyphen one) is used to list one file per line. |
02:41 | Here, we list the files. done ends the inner for loop. |
02:45 | This command prints a vertical line after completion of every cycle of outer for-loop. |
02:53 | done ends the outer for loop. |
02:57 | Let us execute the program. |
02:58 | Open the terminal by pressing ctrl+alt+t keys simultaneously on your keyboard. |
03:08 | Now, let us go to the directory where our Bash script is. |
03:13 | It is on the Desktop. |
03:15 | Type: cd Desktop. Let us go in the folder simple-(Hyphen)nested-(Hyphen)for. |
03:22 | Press Enter. |
03:24 | Type: chmod plus +x nested-(Hyphen)for dot sh |
03:32 | Press Enter. |
03:34 | Type: dot slash nested-(Hyphen)for dot sh |
03:39 | Press Enter. |
03:40 | The output is displayed. It shows files in test directory, files in test2 directory and files in test3 directory. |
03:52 | This brings us to the end of this tutorial. |
03:56 | Let us summarize. In this tutorial we learned Nested for loop. |
04:02 | As an assignment: |
04:04 | * Retype: nested (hyphen)-for dot sh bash script using nested while loop. |
04:11 | * Save your program with the name 'nested-(hyphen)while Dot sh'. |
04:17 | Watch the video available at the link shown below. It summarizes the Spoken-Tutorial project. |
04:23 | If you do not have good bandwidth, you can download and watch it. |
04:28 | The Spoken Tutorial Project team:
|
04:37 | For more details, please write to contact@spoken-tutorial.org |
04:45 | Spoken Tutorial project is a part of the Talk to a Teacher project. It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
04:57 | More information on this mission is available at: http://spoken-tutorial.org\NMEICT-Intro |
05:03 | The script has been contributed by FOSSEE and Spoken-tutorial team. |
05:08 | This is Ashwini Patil from IIT Bombay. Thank You for joining. |