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

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "'''Title of script: Array Operations In BASH''' '''Author:''' Lavitha Pereira '''Keywords: Video tutorial, Bash shell, Array''' {| border=1 !Time !Narration |- | 00:01...")
 
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''Title of script: Array Operations In BASH'''
 
 
'''Author:''' Lavitha Pereira
 
 
'''Keywords: Video tutorial, Bash shell, Array'''
 
 
 
 
{| border=1  
 
{| border=1  
!Time  
+
|'''Time'''
!Narration  
+
|'''Narration'''
  
 
|-
 
|-
 
| 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 values 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<sup>th</sup> '''element'''.
  
 
|-
 
|-
 
| 00:20
 
| 00:20
| * To print an '''Array'''  
+
| To print an '''array'''.
  
 
|-
 
|-
Line 37: Line 29:
 
|-
 
|-
 
|  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:
  
 
|-
 
|-
 
| 00:37
 
| 00:37
| * '''Ubuntu Linux 12.04''' OS  
+
| '''Ubuntu Linux 12.04''' OS  
  
 
|-
 
|-
 
| 00:41
 
| 00:41
| * '''GNU Bash''' version '''4.1.10'''
+
| '''GNU Bash''' version '''4.1.10'''
  
 
|-
 
|-
 
| 00:45
 
| 00:45
| '''GNU Bash '''version '''4''' or above is recommended for practise.
+
| '''GNU Bash '''version 4 or above is recommended for practice.
  
 
|-
 
|-
 
| 00:50
 
| 00:50
|Let us start with the definition of an ''' Array''' and its characteristics.
+
|Let us start with the definition of an ''' array''' and its characteristics.
  
 
|-
 
|-
 
| 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-  
  
 
|-
 
|-
 
|  01:24
 
|  01:24
| '''declare hyphen `a` arrayname'''
+
| '''declare hyphen 'a' arrayname'''
  
 
|-
 
|-
 
| 01:28
 
| 01:28
| '''“declare”''' keyword is used to declare an '''Array'''.
+
| '''“declare”''' keyword is used to declare an '''array'''.
  
 
|-
 
|-
 
| 01:31
 
| 01:31
| It is a built-in command in '''Bash'''.
+
| It is a built-in '''command''' in '''Bash'''.
  
 
|-
 
|-
 
| 01:35
 
| 01:35
| The syntax to assign a value to an '''Array '''is-  
+
| The syntax to assign a value to an '''array '''is-  
  
 
|-
 
|-
 
| 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.
  
 
|-
 
|-
 
|  01:51
 
|  01:51
| * '''Array''' can be declared and initialized at the same time.
+
| '''Array''' can be declared and initialized at the same time.
  
 
|-
 
|-
 
| 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 139: Line 129:
 
|-
 
|-
 
| 02:28
 
| 02:28
| Now Type: '''gedit''' '''space array.sh''' space &
+
| Now Type: '''gedit''' '''space array.sh''' space ampersand (&)
  
 
|-
 
|-
 
| 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.
  
 
|-
 
|-
 
| 02:47
 
| 02:47
| This line declares an '''Array''' named '''Linux''' with elements -
+
| This line declares an '''array''' named '''Linux''' with elements -
 
+
'''"Debian", "Redhat", "Ubuntu" and "Fedora"'''.
* '''Debian, '''
+
* '''Redhat, '''
+
* '''Ubuntu and '''
+
* '''Fedora'''
+
  
 
|-
 
|-
 
| 02:57  
 
| 02:57  
| Here '''hyphen `a` ''' is a '''flag.'''
+
| Here hyphen '''a''' is a '''flag.'''
  
 
|-
 
|-
 
| 03:00  
 
| 03:00  
| It allows us to read and assign '''values''' to an '''Array.'''
+
| It allows us to read and assign '''values''' to an '''array.'''
  
 
|-
 
|-
 
| 03:05
 
| 03:05
| Let us switch back to the slides.
+
| Let us switch back to our '''slides'''.
  
 
|-
 
|-
 
|  03:07
 
|  03:07
| The length of an '''Array''' can be obtained by this syntax:
+
| The length of an '''array''' can be obtained by this syntax:
  
 
|-
 
|-
 
|  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 brackets "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<sup>th</sup> '''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.
  
 
|-
 
|-
 
| 03:42
 
| 03:42
| All the elements of the '''Array''' can be printed using this syntax.
+
| All the elements of the '''array''' can be printed using this syntax.
  
 
|-
 
|-
 
| 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.
  
 
|-
 
|-
 
| 03:57
 
| 03:57
| Now come back to the '''text editor.'''
+
| Now come back to our '''text editor.'''
  
 
|-
 
|-
 
| 04:00
 
| 04:00
| This line will display total number of elements in the '''Array Linux'''.
+
| This line will display total number of elements in the '''array Linux'''.
  
 
|-
 
|-
 
| 04:06
 
| 04:06
| '''hyphen `e` '''enables interpretation of '''backslash '''escapes.
+
| hyphen 'e' enables interpretation of backslash escapes.
  
 
|-
 
|-
 
| 04:11
 
| 04:11
| We have included this as we have '''backslash `n` ''' at the end of the line.
+
| We have included this as we have backslash 'n' at the end of the line.
  
 
|-
 
|-
 
| 04:18
 
| 04:18
| The next line displays all the elements of the '''Array Linux.'''
+
| The next line displays all the elements of the '''array Linux.'''
  
 
|-
 
|-
 
| 04:23
 
| 04:23
| This line displays the 3<sup>rd</sup> element of the '''Array Linux.'''
+
| This line displays the 3<sup>rd</sup> element of the '''array Linux.'''
  
 
|-
 
|-
 
| 04:28
 
| 04:28
| Please note that an '''Array''' always starts with '''index''' '''zero.'''
+
| Please note that an '''array''' always starts with '''index''' zero.
  
 
|-
 
|-
Line 232: Line 218:
 
|-
 
|-
 
| 04:40
 
| 04:40
| Now switch to the '''Terminal.'''
+
| Now, switch to the '''Terminal.'''
  
 
|-
 
|-
 
| 04:42
 
| 04:42
| Let's first make the file executable by typing '''chmod''' space plus x space array.sh Press Enter.
+
| Let's first make the file executable by typing '''chmod''' space '''plus x space array.sh'''. Press '''Enter'''.
  
 
|-
 
|-
 
| 04:56
 
| 04:56
| Type, '''dot slash array .sh''' Press '''Enter.'''
+
| Type: '''dot slash array .sh'''. Press '''Enter.'''
  
 
|-
 
|-
 
| 05:01
 
| 05:01
| The output is displayed.
+
| The '''output''' is displayed.
  
 
|-
 
|-
 
| 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.
  
 
|-
 
|-
 
| 05:10
 
| 05:10
| The elements of the '''Array Linux''' are '''Debian, Redhat, Ubuntu and Fedora.'''
+
| The elements of the '''array Linux''' are '''Debian, Redhat, Ubuntu and Fedora.'''
  
 
|-
 
|-
 
| 05:18
 
| 05:18
| The '''3rd''' element of  '''Array Linux''' is ''' Ubuntu'''.
+
| The third 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 learned to
  
 
|-
 
|-
 
| 05:40
 
| 05:40
| * Declare and assign values to an '''Array'''
+
| Declare and assign values to an '''array'''
  
 
|-
 
|-
 
| 05:43
 
| 05:43
|* Initialize an '''Array''' during declaration
+
| Initialize an '''array''' during declaration
  
 
|-
 
|-
 
| 05:46
 
| 05:46
|* To find length of an '''Array''' and its '''nth''' element and
+
| To find length of an '''array''' and its n<sup>th</sup> element and
  
 
|-
 
|-
 
| 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:
  
 
|-
 
|-
 
| 06:00
 
| 06:00
| * the total number of elements
+
| the total number of elements
  
 
|-
 
|-
 
| 06:02
 
| 06:02
|* print all the elements
+
| print all the elements
  
 
|-
 
|-
 
| 06:04
 
| 06:04
|* And print the 5th element
+
| and print the 5<sup>th</sup> 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 343: Line 326:
 
|-
 
|-
 
| 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.
  
 
|-
 
|-

Latest revision as of 16:24, 20 February 2017

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.

Contributors and Content Editors

PoojaMoolya, Pratik kamble, Ranjana, Sandhya.np14