Difference between revisions of "BASH/C2/Array-Operations-in-BASH/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 12: Line 12:
 
|-
 
|-
 
| 00:01
 
| 00:01
| Welcome to the spoken tutorial on '''Array operations in BASH '''
+
| Welcome to the '''spoken tutorial''' on '''Array operations in BASH'''.
  
 
|-
 
|-
 
| 00:05
 
| 00:05
| In this tutorial, we will learn how to
+
| In this tutorial, we will learn how to:
 
* Declare an ''' Array''' and assign value to it.
 
* Declare an ''' Array''' and assign value to it.
  
 
|-
 
|-
 
| 00:12
 
| 00:12
| * Initialize an''' Array''' during declaration  
+
| * Initialize an''' Array''' during declaration.
  
 
|-
 
|-
 
| 00:15
 
| 00:15
| * To find length of an ''' Array''' and its '''n'''th''' element'''
+
| * To find length of an ''' Array''' and its n'th '''element'''.
  
 
|-
 
|-
 
| 00:20
 
| 00:20
|  * To print an '''Array'''  
+
|  * To print an '''Array'''.
  
 
|-
 
|-
Line 37: Line 37:
 
|-
 
|-
 
|  00:27
 
|  00:27
| For relevant tutorials please visit ''' spoken hyphen tutorial dot org.'''
+
| For relevant tutorials, please visit: spoken hyphen tutorial dot org.
  
 
|-
 
|-
 
| 00:33
 
| 00:33
|For this tutorial I am using  
+
|For this tutorial, I am using:
  
 
|-
 
|-
Line 53: Line 53:
 
|-
 
|-
 
| 00:45
 
| 00:45
| '''GNU Bash '''version '''4''' or above is recommended for practise.
+
| '''GNU Bash '''version 4 or above is recommended for practice.
  
 
|-
 
|-
Line 61: Line 61:
 
|-
 
|-
 
| 00:55
 
| 00:55
| * An '''Array''' is a variable with multiple values.
+
| * An '''Array''' is a '''variable''' with multiple '''values'''.
  
 
|-
 
|-
 
| 01:01
 
| 01:01
| * The values can be of same or different types
+
| * The values can be of same or different types.
  
 
|-
 
|-
 
| 01:04   
 
| 01:04   
| * There is no maximum limit for the size of an '''array'''
+
| * There is no maximum limit for the '''size''' of an '''array'''.
  
 
|-
 
|-
 
| 01:08   
 
| 01:08   
| * '''Array''' members need not be consecutive  
+
| * '''Array''' members need not be consecutive.
  
 
|-
 
|-
 
| 01:12   
 
| 01:12   
| * '''Array index''' always starts with '''zero'''
+
| * '''Array index''' always starts with '''zero'''.
  
 
|-
 
|-
 
|  01:16
 
|  01:16
| We will now see how to declare and assign a value to an '''Array'''.
+
| We will now see how to declare and assign a '''value''' to an '''Array'''.
  
 
|-
 
|-
 
|  01:21
 
|  01:21
| The syntax to declare an '''Array''' is -
+
| The syntax to declare an '''Array''' is-  
  
 
|-
 
|-
Line 97: Line 97:
 
|-
 
|-
 
| 01:31
 
| 01:31
| It is a built-in command in '''Bash'''.
+
| It is a built-in '''command''' in '''Bash'''.
  
 
|-
 
|-
Line 105: Line 105:
 
|-
 
|-
 
| 01:38
 
| 01:38
| '''Name within square brackets index equals to within single quotes value.'''
+
| '''Name''' within square brackets '''index''' equals to within single quotes '''value.'''
  
 
|-
 
|-
 
|  01:46
 
|  01:46
| Now let see how to initialize an '''Array''' during declaration.
+
| Now, let see how to initialize an '''Array''' during declaration.
  
 
|-
 
|-
Line 117: Line 117:
 
|-
 
|-
 
| 01:56
 
| 01:56
|* Element Should be separated by a '''space''' .
+
|* '''Elements''' Should be separated by a '''space''' .
  
 
|-
 
|-
 
| 02:00
 
| 02:00
| Each element should be within '''parentheses'''.
+
| Each '''element''' should be within '''parentheses'''.
  
 
|-
 
|-
 
| 02:03
 
| 02:03
| The syntax is '''declare hyphen `a` arrayname equal-to within round brackets within single quotes 'element1' , 'element2'''' and '''element3''' .
+
| The syntax is '''declare hyphen `a` arrayname equal to within round brackets within single quotes 'element1' , 'element2'''' and '''element3''' .
  
 
|-
 
|-
Line 141: Line 141:
 
|-
 
|-
 
| 02:36
 
| 02:36
| We use the ampersand to free up the prompt. Press Enter  
+
| We use the ampersand to free up the prompt. Press '''Enter'''.
  
 
|-
 
|-
 
| 02:41
 
| 02:41
| Type the code as shown here in your ''' array.sh '''file'''.
+
| Type the '''code''' as shown here, in your ''' array.sh '''file'''.
  
 
|-
 
|-
Line 154: Line 154:
 
* '''Redhat, '''
 
* '''Redhat, '''
 
* '''Ubuntu and '''
 
* '''Ubuntu and '''
* '''Fedora'''
+
* '''Fedora'''.
  
 
|-
 
|-
 
| 02:57  
 
| 02:57  
| Here '''hyphen `a` ''' is a '''flag.'''
+
| Here hyphen `a` is a '''flag.'''
  
 
|-
 
|-
Line 166: Line 166:
 
|-
 
|-
 
| 03:05
 
| 03:05
| Let us switch back to the slides.
+
| Let us switch back to the '''slides'''.
  
 
|-
 
|-
Line 174: Line 174:
 
|-
 
|-
 
|  03:12
 
|  03:12
| '''Dollar sign opening curly bracket hash arrayname within square bracket At sign and closing curly bracket'''
+
| Dollar sign opening curly bracket hash '''arrayname''' within square bracket At sign (@) and closing curly bracket.
  
 
|-
 
|-
 
| 03:22
 
| 03:22
| The length of the '''nth ''' element can be obtained by this syntax:
+
| The length of the n'th '''element''' can be obtained by this syntax:
  
 
|-
 
|-
 
| 03:28
 
| 03:28
| '''Dollar sign opening curly bracket hash arrayname within square brackets  `n` and closing curly bracket'''.
+
| Dollar sign opening curly bracket hash arrayname within square brackets  `n` and closing curly bracket.
  
 
|-
 
|-
 
| 03:37
 
| 03:37
| Here '''n''' is the element number, whose length is to be found.
+
| Here 'n' is the '''element''' number whose length is to be found.
  
 
|-
 
|-
Line 194: Line 194:
 
|-
 
|-
 
| 03:48
 
| 03:48
| '''Dollar sign opening curly bracket Arrayname within square brackets `At sign` and closing curly bracket.'''
+
| Dollar sign opening curly bracket '''arrayname''' within square brackets `At sign` and closing curly bracket.'''
  
 
|-
 
|-
Line 230: Line 230:
 
|-
 
|-
 
| 04:40
 
| 04:40
| Now switch to the '''Terminal.'''
+
| Now, switch to the '''Terminal.'''
  
 
|-
 
|-
Line 238: Line 238:
 
|-
 
|-
 
| 04:56
 
| 04:56
| Type, '''dot slash array .sh'''. Press '''Enter.'''
+
| Type: '''dot slash array .sh'''. Press '''Enter.'''
  
 
|-
 
|-
Line 246: Line 246:
 
|-
 
|-
 
| 05:04
 
| 05:04
|The number of elements or the length of the '''Array `Linux`''' is '''four.'''
+
|The number of elements or the length of the '''Array `Linux`''' is four.
  
 
|-
 
|-
Line 254: Line 254:
 
|-
 
|-
 
| 05:18
 
| 05:18
| The '''3rd''' element of  '''Array Linux''' is ''' Ubuntu'''.
+
| The 3rd element of  '''Array Linux''' is ''' Ubuntu'''.
  
 
|-
 
|-
 
| 05:22
 
| 05:22
| And the number of characters in the '''third element''' is '''six,''' as expected.
+
| And the number of characters in the third element is six, as expected.
  
 
|-
 
|-
 
| 05:29
 
| 05:29
| This bring us to the end of this tutorial.
+
| This brings us to the end of this tutorial.
  
 
|-
 
|-
 
| 05:32
 
| 05:32
| Let us summarize. Come back to our slides.
+
| Let us summarize. Come back to our '''slides'''.
  
 
|-
 
|-
 
| 05:35
 
| 05:35
| In this tutorial we learnt to ,
+
| In this tutorial, we learnt to
  
 
|-
 
|-
Line 286: Line 286:
 
|-
 
|-
 
| 05:51
 
| 05:51
| * To print whole ''' Array'''  
+
| * To print whole ''' Array'''.
  
 
|-
 
|-
 
| 05:53
 
| 05:53
|As an assignment.
+
|As an assignment-
  
 
|-
 
|-
 
| 05:55
 
| 05:55
| Declare an array '''names''' of length '''7''' and find:
+
| Declare an array '''names''' of length 7 and find:
  
 
|-
 
|-
Line 306: Line 306:
 
|-
 
|-
 
| 06:04
 
| 06:04
|* And print the 5th element
+
|* And print the 5th element.
  
 
|-
 
|-
 
| 06:06
 
| 06:06
|Watch the video available at the link shown below
+
|Watch the video available at the link shown below.
  
 
|-
 
|-
 
| 06:10
 
| 06:10
| It summarises the Spoken Tutorial project  
+
| It summarizes the Spoken-Tutorial project.
  
 
|-
 
|-
 
| 06:13
 
| 06:13
| 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.
  
 
|-
 
|-
 
| 06:18
 
| 06:18
| The Spoken Tutorial Project Team
+
| The Spoken Tutorial Project team:
  
 
|-
 
|-
 
| 06:20
 
| 06:20
| Conducts workshops using spoken tutorials  
+
| Conducts workshops using spoken tutorials.
  
 
|-
 
|-
 
| 06:24
 
| 06:24
| Gives certificates to those who pass an online test  
+
| Gives certificates to those who pass an online test.
  
 
|-
 
|-
Line 338: Line 338:
 
|-
 
|-
 
| 06:35
 
| 06:35
|Spoken Tutorial Project is a part of the Talk to a Teacher project
+
|Spoken Tutorial Project is a part of the "Talk to a Teacher" project
  
 
|-
 
|-
 
| 06:40
 
| 06:40
| It is supported by the National Mission on Education through ICT, MHRD, Government of India
+
| It is supported by the National Mission on Education through ICT, MHRD, Government of India.
  
 
|-
 
|-
 
| 06:47
 
| 06:47
| More information on this Mission is available at the link shown below.
+
| More information on this mission is available at the link shown below.
  
 
|-
 
|-
 
|  06:52
 
|  06:52
| The script has been contributed by FOSSEE and spoken-tutorial team.
+
| The script has been contributed by FOSSEE and spoken-tutorial teams.
  
 
|-
 
|-

Revision as of 14:39, 2 July 2015

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:
  • Declare an Array and assign value to it.
00:12 * Initialize an Array during declaration.
00:15 * To find length of an Array and its n'th 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 &
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 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 n'th 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 brings 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 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.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Ranjana, Sandhya.np14