BASH/C2/Array-Operations-in-BASH/English-timed
From Script | Spoken-Tutorial
Revision as of 16:24, 20 February 2017 by Pratik kamble (Talk | contribs)
| Time | Narration |
| 00:01 | Welcome to the spoken tutorial on Array operations in BASH. |
| 00:05 | In this tutorial, we will learn how to:Declare an array and assign values to it. |
| 00:12 | Initialize an array during declaration. |
| 00:15 | To find length of an array and its nth element. |
| 00:20 | To print an array. |
| 00:22 | To follow this tutorial, You should be familiar with Linux Operating System. |
| 00:27 | For relevant tutorials, please visit: spoken hyphen tutorial dot org. |
| 00:33 | For this tutorial, I am using: |
| 00:37 | Ubuntu Linux 12.04 OS |
| 00:41 | GNU Bash version 4.1.10 |
| 00:45 | GNU Bash version 4 or above is recommended for practice. |
| 00:50 | Let us start with the definition of an array and its characteristics. |
| 00:55 | An array is a variable with multiple values. |
| 01:01 | The values can be of same or different types. |
| 01:04 | There is no maximum limit for the size of an array. |
| 01:08 | Array members need not be consecutive. |
| 01:12 | Array index always starts with zero. |
| 01:16 | We will now see how to declare and assign a value to an array. |
| 01:21 | The syntax to declare an array is- |
| 01:24 | declare hyphen 'a' arrayname |
| 01:28 | “declare” keyword is used to declare an array. |
| 01:31 | It is a built-in command in Bash. |
| 01:35 | The syntax to assign a value to an array is- |
| 01:38 | Name within square brackets index equals to within single quotes value. |
| 01:46 | Now, let see how to initialize an array during declaration. |
| 01:51 | Array can be declared and initialized at the same time. |
| 01:56 | Elements Should be separated by a space . |
| 02:00 | Each element should be within parentheses. |
| 02:03 | The syntax is declare hyphen 'a' arrayname equal to within round brackets within single quotes 'element1' , 'element2' and element3 . |
| 02:19 | Let us try an example. |
| 02:21 | Open the terminal by pressing Ctrl+Alt and T keys simultaneously. |
| 02:28 | Now Type: gedit space array.sh space ampersand (&) |
| 02:36 | We use the ampersand to free up the prompt. Press Enter. |
| 02:41 | Type the code as shown here, in your "array.sh" file. |
| 02:47 | This line declares an array named Linux with elements -
"Debian", "Redhat", "Ubuntu" and "Fedora". |
| 02:57 | Here hyphen a is a flag. |
| 03:00 | It allows us to read and assign values to an array. |
| 03:05 | Let us switch back to our slides. |
| 03:07 | The length of an array can be obtained by this syntax: |
| 03:12 | Dollar sign ($) opening curly bracket hash arrayname within square brackets "At" sign (@) and closing curly bracket. |
| 03:22 | The length of the nth element can be obtained by this syntax: |
| 03:28 | Dollar sign opening curly bracket hash arrayname within square brackets 'n' and closing curly bracket. |
| 03:37 | Here 'n' is the element number whose length is to be found. |
| 03:42 | All the elements of the array can be printed using this syntax. |
| 03:48 | Dollar sign opening curly bracket arrayname within square brackets 'At' sign (@) and closing curly bracket. |
| 03:57 | Now come back to our text editor. |
| 04:00 | This line will display total number of elements in the array Linux. |
| 04:06 | hyphen 'e' enables interpretation of backslash escapes. |
| 04:11 | We have included this as we have backslash 'n' at the end of the line. |
| 04:18 | The next line displays all the elements of the array Linux. |
| 04:23 | This line displays the 3rd element of the array Linux. |
| 04:28 | Please note that an array always starts with index zero. |
| 04:34 | Lastly, this line displays the number of characters present in the 3rd element. |
| 04:40 | Now, switch to the Terminal. |
| 04:42 | Let's first make the file executable by typing chmod space plus x space array.sh. Press Enter. |
| 04:56 | Type: dot slash array .sh. Press Enter. |
| 05:01 | The output is displayed. |
| 05:04 | The number of elements or the length of the array 'Linux' is four. |
| 05:10 | The elements of the array Linux are Debian, Redhat, Ubuntu and Fedora. |
| 05:18 | The third element of array Linux is Ubuntu. |
| 05:22 | And the number of characters in the third element is six, as expected. |
| 05:29 | This brings us to the end of this tutorial. |
| 05:32 | Let us summarize. Come back to our slides. |
| 05:35 | In this tutorial, we learned to: |
| 05:40 | Declare and assign values to an array |
| 05:43 | Initialize an array during declaration |
| 05:46 | To find length of an array and its nth element and |
| 05:51 | To print whole array. |
| 05:53 | As an assignment- |
| 05:55 | Declare an array names of length 7 and find: |
| 06:00 | the total number of elements |
| 06:02 | print all the elements |
| 06:04 | and print the 5th element. |
| 06:06 | Watch the video available at the link shown below. |
| 06:10 | It summarizes the Spoken-Tutorial project. |
| 06:13 | If you do not have good bandwidth, you can download and watch it. |
| 06:18 | The Spoken Tutorial Project team: |
| 06:20 | Conducts workshops using spoken tutorials. |
| 06:24 | Gives certificates to those who pass an online test. |
| 06:27 | For more details, please write to contact@spoken-tutorial.org. |
| 06:35 | Spoken Tutorial Project is a part of the Talk to a Teacher project. |
| 06:40 | It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
| 06:47 | More information on this mission is available at the link shown below. |
| 06:52 | The script has been contributed by FOSSEE and spoken-tutorial teams. |
| 06:58 | This is Ashwini Patil from IIT Bombay. |
| 07:02 | Thank you for joining. |