Difference between revisions of "BASH/C3/Basics-of-functions/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 5: Line 5:
 
|-
 
|-
 
|  00.01
 
|  00.01
| Dear friends, Welcome to the spoken tutorial on '''Basics of functions in Bash.'''
+
| Dear friends, welcome to the '''spoken tutorial''' on '''Basics of functions''' in '''Bash.'''
  
 
|-
 
|-
 
|  00.08
 
|  00.08
| In this tutorial, we will learn
+
| In this tutorial, we will learn:
  
 
|-
 
|-
Line 25: Line 25:
 
|-
 
|-
 
|  00.19
 
|  00.19
|* with the help of an example  
+
| with the help of an example.
  
 
|-
 
|-
 
|  00.22
 
|  00.22
| To follow this tutorial you should have knowledge of '''Shell Scripting''' in''' BASH.'''
+
| To follow this tutorial, you should have knowledge of '''Shell Scripting''' in''' BASH.'''
  
 
|-
 
|-
 
|  00.28
 
|  00.28
|If not, for relevant tutorials please visit our website which is as shown,'''http://www.spoken-tutorial.org'''
+
|If not, for relevant tutorials, please visit our website which is as shown. '''http://www.spoken-tutorial.org'''
  
 
|-
 
|-
 
| 00.34
 
| 00.34
| For this tutorial I am using''' Ubuntu Linux''' 12.04''' Operating System'''  
+
| For this tutorial, I am using''' Ubuntu Linux''' 12.04''' Operating System'''.
  
 
|-
 
|-
Line 57: Line 57:
 
|-
 
|-
 
|  01.03
 
|  01.03
| * A '''function''' is a collection of commands or an algorithm.
+
| A '''function''' is a collection of '''commands''' or an '''algorithm'''.
  
 
|-
 
|-
 
|  01.08
 
|  01.08
|* It is intended to do a specific task.
+
| It is intended to do a specific task.
  
 
|-
 
|-
 
|  01.12
 
|  01.12
|* It is used to break up a complex program into separate tasks.
+
| It is used to break up a complex program into separate tasks.
  
 
|-
 
|-
 
|  01.18
 
|  01.18
|* This improves overall script readability and ease of use.
+
| This improves overall script readability and ease of use.
  
 
|-
 
|-
Line 77: Line 77:
 
|-
 
|-
 
| 01.28
 
| 01.28
| First syntax is
+
| First syntax is-
  
 
|-
 
|-
Line 89: Line 89:
 
|-
 
|-
 
|  01.34
 
|  01.34
|the '''commands''' to be executed
+
|the '''commands''' to be executed.
  
 
|-
 
|-
 
|  01.37
 
|  01.37
| The second syntax is
+
| The second syntax is-
  
 
|-
 
|-
Line 105: Line 105:
 
|-
 
|-
 
|  01.44
 
|  01.44
|the '''commands''' to be executed
+
|the '''commands''' to be executed.
  
 
|-
 
|-
 
|  01.47
 
|  01.47
| '''Function call'''
+
| '''Function call'''-
  
 
|-
 
|-
Line 129: Line 129:
 
|-
 
|-
 
| 02.07
 
| 02.07
| I have already typed the code in a file '''function.sh'''  
+
| I have already typed the code in a file '''function.sh'''.
  
 
|-
 
|-
Line 177: Line 177:
 
|-
 
|-
 
|03.01   
 
|03.01   
|We display the message ''' “Beginning of main program” '''
+
|We display the message ''' “Beginning of main program” '''.
  
 
|-
 
|-
Line 185: Line 185:
 
|-
 
|-
 
| 03.09
 
| 03.09
| Then we display the message '''“End of main program”'''
+
| Then we display the message '''“End of main program”'''.
  
 
|-
 
|-
Line 205: Line 205:
 
|-
 
|-
 
|  03.36
 
|  03.36
| The '''interperter''' treats '''function name '''as a command.
+
| The '''interpreter''' treats '''function name '''as a command.
 
|-
 
|-
 
|  03.41
 
|  03.41
Line 212: Line 212:
 
|-
 
|-
 
| 03.47
 
| 03.47
| Now go to the''' terminal.''' To make this code file'' ''executable
+
| Now go to the''' terminal.''' To make this code file'' ''executable,
  
 
|-
 
|-
 
|  03.52
 
|  03.52
|Type: '''chmod space plus x space function dot sh'''
+
|type: '''chmod space plus x space function dot sh'''
  
 
|-
 
|-
Line 224: Line 224:
 
|-
 
|-
 
| 04.01
 
| 04.01
type '''dot slash function dot sh'''  
+
Type: '''dot slash function dot sh'''  
  
 
|-
 
|-
Line 232: Line 232:
 
|-
 
|-
 
| 04.07
 
| 04.07
| The output that is the machine details of my system, are seen on the '''terminal.'''
+
| The '''output''' that is the machine details of my system are seen on the '''terminal.'''
  
 
|-
 
|-
 
|  04.14
 
|  04.14
|Please Note: The output will vary from system to system.
+
|Please Note: The '''output''' will vary from system to system.
  
 
|-
 
|-
Line 244: Line 244:
 
|-
 
|-
 
|  04.22
 
|  04.22
|Come back to our slides.
+
|Come back to our '''slides'''.
  
 
|-
 
|-
Line 252: Line 252:
 
|-
 
|-
 
|  04.25
 
|  04.25
|In this tutorial we learnt,
+
|In this tutorial, we learned:
  
 
|-
 
|-
Line 271: Line 271:
 
|-
 
|-
 
|  04.35
 
|  04.35
|* with an example
+
| with an example.
  
 
|-
 
|-
 
| 04.37
 
| 04.37
| As an assignment.
+
| As an assignment-
  
 
|-
 
|-
 
|  04.38
 
|  04.38
|Write a program with two functions
+
|write a program with two functions.
  
 
|-
 
|-
 
|  04.42
 
|  04.42
|# The first function should display the diskspace usage in human readable form '''(Hint: df hyphen h)'''
+
|# The first function should display the disks-pace usage in human readable form '''(Hint: df hyphen h)'''.
  
 
|-
 
|-
 
|  04.51
 
|  04.51
|# The second function should display filesystem usage in human readable form '''(Hint: du hyphen h)'''
+
|# The second function should display filesystem usage in human readable form '''(Hint: du hyphen h)'''.
  
 
|-
 
|-
 
| 05.00
 
| 05.00
| Watch the video available at the link shown below
+
| Watch the video available at the link shown below.
  
 
|-
 
|-
 
|  05.03
 
|  05.03
|It summarises the Spoken Tutorial project
+
|It summarizes the Spoken-Tutorial project.
  
 
|-
 
|-
 
|  05.07
 
|  05.07
|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.
  
 
|-
 
|-
 
|  05.12
 
|  05.12
| The Spoken Tutorial Project Team Conducts workshops using spoken tutorials
+
| The Spoken Tutorial Project team: Conducts workshops using spoken tutorials;
  
 
|-
 
|-
 
|  05.17
 
|  05.17
|Gives certificates to those who pass an online test
+
|Gives certificates to those who pass an online test.
  
 
|-
 
|-
Line 315: Line 315:
 
|-
 
|-
 
|  05.29
 
|  05.29
| 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.
  
 
|-
 
|-
 
| 05.33  
 
| 05.33  
|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.
  
 
|-
 
|-
 
|  05.41
 
|  05.41
|More information on this Mission is available at the link shown below: http://spoken-tutorial.org\NMEICT-Intro
+
|More information on this mission is available at the link shown below: http://spoken-tutorial.org\NMEICT-Intro
  
 
|-
 
|-
 
|  05.47
 
|  05.47
| The script has been contributed by FOSSEE and spoken-tutorial team
+
| The script has been contributed by FOSSEE and spoken-tutorial team.
  
 
|-
 
|-
 
|  05.52
 
|  05.52
|This is Ashwini Patil from IIT Bombay. Signing off
+
|This is Ashwini Patil from IIT Bombay, signing off.
  
 
|-
 
|-

Revision as of 00:13, 6 July 2015

Time Narration
00.01 Dear friends, welcome to the spoken tutorial on Basics of functions in Bash.
00.08 In this tutorial, we will learn:
00.11 * Importance of Functions
00.13 * To declare a function
00.15 * To call a function
00.17 * Work flow of a function
00.19 with the help of an example.
00.22 To follow this tutorial, you should have knowledge of Shell Scripting in BASH.
00.28 If not, for relevant tutorials, please visit our website which is as shown. http://www.spoken-tutorial.org
00.34 For this tutorial, I am using Ubuntu Linux 12.04 Operating System.
00.40 Till now we were using GNU BASH version 4.1.10
00.46 From now onwards, we will use GNU BASH version 4.2
00.52 Please note, GNU Bash version 4 or above is recommended for practice.
00.58 Let us see what is a function and its usage.
01.03 A function is a collection of commands or an algorithm.
01.08 It is intended to do a specific task.
01.12 It is used to break up a complex program into separate tasks.
01.18 This improves overall script readability and ease of use.
01.24 There are two syntaxes for function declaration.
01.28 First syntax is-
01.29 function space function underscore name
01.32 within curly brackets,
01.34 the commands to be executed.
01.37 The second syntax is-
01.39 function underscore name open and close round brackets
01.42 within curly barckets,
01.44 the commands to be executed.
01.47 Function call-
01.48 Function can be called anywhere within the program.
01.53 Type the function name at the location where you want to call it.
01.58 The syntax is the function name itself.
02.02 Let us understand this with the help of a simple example.
02.07 I have already typed the code in a file function.sh.
02.12 This is the shebang line.
02.14 Function is declared by the keyword function followed by function name.
02.21 Here, function name is machine.
02.26 The content within curly brackets is called function definition.
02.32 I have displayed various machine details like-
02.36 uname hyphen a gives machine information.
02.41 w hyphen h gives users logged onto system.
02.46 uptime gives the time since machine was on.
02.51 free gives memory status.
02.54 df hyphen h gives filesystem status.
02.57 The main program starts here.
03.01 We display the message “Beginning of main program” .
03.06 Here, machine is a function call.
03.09 Then we display the message “End of main program”.
03.13 Let us understand the workflow.
03.16 # When the bash interpreter visits the function definition, it simply scans the function.
03.23 # The function is called only when its name appears within the script.
03.28 # When the interpreter reads the function name, it executes the function definition.
03.36 The interpreter treats function name as a command.
03.41 Please remember that we have to define the function before calling it.
03.47 Now go to the terminal. To make this code file executable,
03.52 type: chmod space plus x space function dot sh
03.59 Press Enter.
04.01 Type: dot slash function dot sh
04.05 Press Enter.
04.07 The output that is the machine details of my system are seen on the terminal.
04.14 Please Note: The output will vary from system to system.
04.19 This brings us to the end of this tutorial.
04.22 Come back to our slides.
04.24 Let us summarize.
04.25 In this tutorial, we learned:
04.28 * Importance of functions
04.30 * Function declaration
04.32 * Function call
04.33 * Work flow of function
04.35 with an example.
04.37 As an assignment-
04.38 write a program with two functions.
04.42 # The first function should display the disks-pace usage in human readable form (Hint: df hyphen h).
04.51 # The second function should display filesystem usage in human readable form (Hint: du hyphen h).
05.00 Watch the video available at the link shown below.
05.03 It summarizes the Spoken-Tutorial project.
05.07 If you do not have good bandwidth, you can download and watch it.
05.12 The Spoken Tutorial Project team: Conducts workshops using spoken tutorials;
05.17 Gives certificates to those who pass an online test.
05.21 For more details, please write to contact@spoken-tutorial.org
05.29 Spoken Tutorial Project is a part of the Talk to a Teacher project.
05.33 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
05.41 More information on this mission is available at the link shown below: http://spoken-tutorial.org\NMEICT-Intro
05.47 The script has been contributed by FOSSEE and spoken-tutorial team.
05.52 This is Ashwini Patil from IIT Bombay, signing off.
05.56 Thank you for joining.

Contributors and Content Editors

Gaurav, PoojaMoolya, Pratik kamble, Sandhya.np14