BASH/C2/Array-Operations-in-BASH/English-timed
From Script | Spoken-Tutorial
Revision as of 17:08, 17 December 2014 by PoojaMoolya (Talk | contribs)
Title of script: Array Operations In BASH
Author: Lavitha Pereira
Keywords: Video tutorial, Bash shell, Array
Time | Narration |
---|---|
00:01 | Welcome to the spoken tutorial on Array operations in BASH |
00:05 | In this tutorial, we will learn how to
|
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 practise. |
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 | * Element 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 & |
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 -
|
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 the 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 bracket 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 the 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 3rd element of Array Linux is Ubuntu. |
05:22 | And the number of characters in the third element is six, as expected. |
05:29 | This bring us to the end of this tutorial. |
05:32 | Let us summarize. Come back to our slides. |
05:35 | In this tutorial we learnt 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 summarises 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 team. |
06:58 | This is Ashwini Patil from IIT Bombay. |
07:02 | Thank you for joining. |