Difference between revisions of "BASH/C3/Advance-topics-in-a-function/English-timed"
From Script | Spoken-Tutorial
(Created page with "{|border=1 |'''Time''' |'''Narration''' |- | 00:01 | Dear friends, Welcome to the spoken tutorial on'''Advance topics in a function ''' |- | 00:08 | In this tutorial, we wil...") |
Sandhya.np14 (Talk | contribs) |
||
Line 5: | Line 5: | ||
|- | |- | ||
| 00:01 | | 00:01 | ||
− | | Dear friends, | + | | Dear friends, welcome to the '''spoken tutorial''' on'''Advance topics in a function '''. |
|- | |- | ||
| 00:08 | | 00:08 | ||
− | | In this tutorial, we will learn | + | | In this tutorial, we will learn: |
|- | |- | ||
| 00:11 | | 00:11 | ||
− | | '''Source '''command | + | |* '''Source '''command |
|- | |- | ||
| 00:12 | | 00:12 | ||
− | | To put a function in the '''background''' | + | |* To put a function in the '''background''' |
|- | |- | ||
| 00:14 | | 00:14 | ||
− | | | + | | with the help of some examples. |
|- | |- | ||
| 00:18 | | 00:18 | ||
− | | 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:24 | | 00:24 | ||
− | |If not, for relevant tutorials, please visit our website which is as shown '''http://spoken-tutorial.org/ | + | |If not, for relevant tutorials, please visit our website which is as shown. '''http://spoken-tutorial.org/What_is_a_Spoken_Tutorial''' |
|- | |- | ||
| 00:30 | | 00:30 | ||
− | | For this tutorial I am using | + | | For this tutorial, I am using: |
|- | |- | ||
Line 41: | Line 41: | ||
|- | |- | ||
| 00:36 | | 00:36 | ||
− | |'''GNU BASH''' version 4.2 | + | |* '''GNU BASH''' version 4.2 |
|- | |- | ||
Line 49: | Line 49: | ||
|- | |- | ||
| 00:46 | | 00:46 | ||
− | | '''Source '''command is used to load a file into '''Shell ''' | + | | '''Source''' '''command''' is used to '''load''' a file into '''Shell script'''. |
|- | |- | ||
| 00:53 | | 00:53 | ||
− | | It reads and | + | | It reads and executes commands from that file. |
|- | |- | ||
| 00:58 | | 00:58 | ||
− | | It also imports code into the script. | + | | It also imports '''code''' into the '''script'''. |
|- | |- | ||
| 01:01 | | 01:01 | ||
− | | This is useful when multiple scripts use a common data or a function library. | + | | This is useful when multiple scripts use a common data or a '''function library'''. |
|- | |- | ||
| 01:09 | | 01:09 | ||
− | | The syntax for '''Source command''' is as follows | + | | The syntax for '''Source command''' is as follows- |
|- | |- | ||
Line 77: | Line 77: | ||
|- | |- | ||
| 01:18 | | 01:18 | ||
− | |'''souce filename arguments''' | + | |'''souce filename arguments'''. |
|- | |- | ||
|01:22 | |01:22 | ||
− | | Let me open a file ''''function dot sh'''' | + | | Let me open a file ''' 'function dot sh'.''' |
|- | |- | ||
Line 89: | Line 89: | ||
|- | |- | ||
|01:29 | |01:29 | ||
− | |'''Source detail dot sh''' will load the file '''detail dot sh '''into''' function dot sh ''' | + | |'''Source detail dot sh''' will load the file '''detail dot sh '''into '''function dot sh'''. |
|- | |- | ||
Line 97: | Line 97: | ||
|- | |- | ||
|01:41 | |01:41 | ||
− | |I have a '''function''' ''' | + | |I have a '''function''' '''machine'''. |
|- | |- | ||
|01:44 | |01:44 | ||
− | |Now type inside the function | + | |Now, type inside the function- |
|- | |- | ||
|01:47 | |01:47 | ||
− | |'''echo | + | |'''echo "function machine is called in function dot sh file" '''. |
|- | |- | ||
Line 117: | Line 117: | ||
|- | |- | ||
|01:59 | |01:59 | ||
− | |Here type '''echo''' '''“Beginning of program”''' | + | |Here, type: '''echo''' '''“Beginning of program”'''. |
|- | |- | ||
|02:04 | |02:04 | ||
− | |Click on''' Save''' | + | |Click on''' Save'''. |
|- | |- | ||
|02:06 | |02:06 | ||
− | |Then type '''machine''' '''echo''' '''“End of program”''' | + | |Then type: '''machine''' '''echo''' '''“End of program”'''. |
|- | |- | ||
|02:12 | |02:12 | ||
− | | This will print the message '''“Beginning of program”''' | + | | This will print the message '''“Beginning of program”'''. |
|- | |- | ||
Line 137: | Line 137: | ||
|- | |- | ||
|02:19 | |02:19 | ||
− | | And this will print the message '''End of program''' | + | | And this will print the message '''End of program'''. |
|- | |- | ||
Line 145: | Line 145: | ||
|- | |- | ||
|02:29 | |02:29 | ||
− | |And we are calling the '''function''' here in '''function dot sh''' file. | + | |And we are calling the '''function''' here, in '''function dot sh''' file. |
|- | |- | ||
Line 153: | Line 153: | ||
|- | |- | ||
| 02:36 | | 02:36 | ||
− | | Let us execute the program. | + | | Let us '''execute''' the program. |
|- | |- | ||
| 02:41 | | 02:41 | ||
− | | So type on the '''terminal''' '''chmod space plus (+) x space function dot sh''' | + | | So, type on the '''terminal''': '''chmod space plus (+) x space function dot sh''' |
|- | |- | ||
|02:51 | |02:51 | ||
− | | Press '''Enter''' | + | | Press '''Enter'''. |
|- | |- | ||
|02:53 | |02:53 | ||
− | | Type '''dot slash function dot sh''' | + | | Type: '''dot slash function dot sh''' |
|- | |- | ||
Line 173: | Line 173: | ||
|- | |- | ||
|02:59 | |02:59 | ||
− | | The output is displayed | + | | The '''output''' is displayed. |
|- | |- | ||
Line 181: | Line 181: | ||
|- | |- | ||
|03:06 | |03:06 | ||
− | | To run a process in the background, we use '''&''' (ampersand) | + | | To run a process in the background, we use '''&''' (ampersand) at the end of a '''function call.''' |
|- | |- | ||
|03:13 | |03:13 | ||
− | | The '''shell''' forks a '''child process''' to run the command. | + | | The '''shell''' forks a '''child process''' to '''run''' the '''command'''. |
|- | |- | ||
|03:19 | |03:19 | ||
− | |The forked process will have a '''job number''' and a '''PID (Process | + | |The forked process will have a '''job number''' and a '''PID (Process Identifier)'''. |
|- | |- | ||
| 03:27 | | 03:27 | ||
− | | Let us understand this with the help of an example. I will open the file '''background dot sh''' | + | | Let us understand this with the help of an example. I will open the file '''background dot sh'''. |
|- | |- | ||
Line 205: | Line 205: | ||
|- | |- | ||
|03:44 | |03:44 | ||
− | | The '''echo statement''' here displays the message '''"Inside bg_function”''' | + | | The '''echo statement''' here displays the message '''"Inside bg_function”'''. |
|- | |- | ||
|03:50 | |03:50 | ||
− | | Next, we will use the '''find | + | | Next, we will use the '''find''' command to find all the dot'''mp3 '''files. |
|- | |- | ||
|03:57 | |03:57 | ||
− | | This statement will find all the files with the extension '''dot mp3''' | + | | This statement will find all the files with the extension '''dot mp3'''. |
|- | |- | ||
|04:03 | |04:03 | ||
− | | It will do so in the current working directory. | + | | It will do so in the current '''working directory'''. |
|- | |- | ||
Line 229: | Line 229: | ||
|- | |- | ||
|04:16 | |04:16 | ||
− | | Now type '''bg underscore function ampersand(&) | + | | Now, type: '''bg underscore function''' ampersand(&). This is the '''function call.''' '&'(Ampersand) puts ''''bg_function'''' in the background. |
|- | |- | ||
Line 237: | Line 237: | ||
|- | |- | ||
|04:31 | |04:31 | ||
− | | Let us execute the program. | + | | Let us '''execute''' the program. |
|- | |- | ||
Line 245: | Line 245: | ||
|- | |- | ||
|04:37 | |04:37 | ||
− | | Type '''chmod space plus x space background dot sh''' | + | | Type: '''chmod space plus x space background dot sh''' |
|- | |- | ||
Line 253: | Line 253: | ||
|- | |- | ||
| 04:46 | | 04:46 | ||
− | |Now type '''dot slash background dot sh''' | + | |Now, type: '''dot slash background dot sh''' |
|- | |- | ||
Line 269: | Line 269: | ||
|- | |- | ||
| 05:05 | | 05:05 | ||
− | |Type '''echo (hyphen) -e " | + | |Type: '''echo (hyphen) -e "Process running in background are slash n" ''' and '''jobs space hyphen l''' |
|- | |- | ||
| 05:19 | | 05:19 | ||
− | |Click on''' Save''' | + | |Click on''' Save'''. |
|- | |- | ||
|05:21 | |05:21 | ||
− | | This '''echo statement''' will | + | | This '''echo statement''' will display the message “'''Process running in background are ”'''. |
|- | |- | ||
Line 289: | Line 289: | ||
|- | |- | ||
| 05:38 | | 05:38 | ||
− | |Now type ''' dot slash background.sh''' | + | |Now, type: ''' dot slash background.sh'''. |
|- | |- | ||
Line 297: | Line 297: | ||
|- | |- | ||
|05:44 | |05:44 | ||
− | | The output is shown. | + | | The '''output''' is shown. |
|- | |- | ||
Line 313: | Line 313: | ||
|- | |- | ||
|06:01 | |06:01 | ||
− | |If the function takes time to execute, it will run in the background. | + | |If the '''function''' takes time to execute, it will run in the background. |
|- | |- | ||
Line 321: | Line 321: | ||
|- | |- | ||
|06:11 | |06:11 | ||
− | |If the function gets executed before the script, we will see the status as '''Done''' | + | |If the '''function''' gets executed before the script, we will see the status as '''Done'''. |
|- | |- | ||
|06:20 | |06:20 | ||
− | |The output will vary from machine to machine. | + | |The '''output''' will vary from machine to machine. |
|- | |- | ||
Line 333: | Line 333: | ||
|- | |- | ||
|06:28 | |06:28 | ||
− | |Let us | + | |Let us Summarize. |
|- | |- | ||
|06:29 | |06:29 | ||
− | |In this tutorial we | + | |In this tutorial, we learned: |
|- | |- | ||
|06:32 | |06:32 | ||
− | | '''Source '''command | + | |* '''Source '''command |
|- | |- | ||
|06:34 | |06:34 | ||
− | | To put a function in the '''background''' | + | |* To put a function in the '''background''' |
|- | |- | ||
|06:36 | |06:36 | ||
− | | | + | | with the help of some examples. |
|- | |- | ||
Line 361: | Line 361: | ||
|- | |- | ||
|06:47 | |06:47 | ||
− | | Watch the video available at the link shown below http://spoken-tutorial.org/ | + | | Watch the video available at the link shown below http://spoken-tutorial.org/What_is_a_Spoken_Tutorial |
|- | |- | ||
| 06:51 | | 06:51 | ||
− | |It | + | |It summarizes the Spoken-Tutorial project. |
|- | |- | ||
Line 373: | Line 373: | ||
|- | |- | ||
| 07:00 | | 07:00 | ||
− | | The Spoken Tutorial Project | + | | The Spoken Tutorial Project team: |
+ | * Conducts workshops using spoken tutorials. | ||
+ | * Gives certificates to those who pass an online test. | ||
|- | |- | ||
Line 381: | Line 383: | ||
|- | |- | ||
|07:18 | |07:18 | ||
− | | 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. |
|- | |- | ||
Line 389: | Line 391: | ||
|- | |- | ||
| 07:30 | | 07:30 | ||
− | | More information on this | + | | More information on this mission is available at the link shown below. http://spoken-tutorial.org\NMEICT-Intro |
|- | |- |
Revision as of 19:36, 6 July 2015
Time | Narration |
00:01 | Dear friends, welcome to the spoken tutorial onAdvance topics in a function . |
00:08 | In this tutorial, we will learn: |
00:11 | * Source command |
00:12 | * To put a function in the background |
00:14 | with the help of some examples. |
00:18 | To follow this tutorial, you should have knowledge of Shell Scripting in BASH. |
00:24 | If not, for relevant tutorials, please visit our website which is as shown. http://spoken-tutorial.org/What_is_a_Spoken_Tutorial |
00:30 | For this tutorial, I am using: |
00:32 | * Ubuntu Linux 12.04 Operating System and |
00:36 | * GNU BASH version 4.2 |
00:40 | Please note, GNU Bash version 4 or above is recommended for practice. |
00:46 | Source command is used to load a file into Shell script. |
00:53 | It reads and executes commands from that file. |
00:58 | It also imports code into the script. |
01:01 | This is useful when multiple scripts use a common data or a function library. |
01:09 | The syntax for Source command is as follows- |
01:12 | source filename |
01:15 | source Path_to_file |
01:18 | souce filename arguments. |
01:22 | Let me open a file 'function dot sh'. |
01:26 | This is theshebang line. |
01:29 | Source detail dot sh will load the file detail dot sh into function dot sh. |
01:37 | Let me open detail dot sh file. |
01:41 | I have a function machine. |
01:44 | Now, type inside the function- |
01:47 | echo "function machine is called in function dot sh file" . |
01:52 | Click on Save. |
01:54 | Now let us go back to function dot sh file. |
01:59 | Here, type: echo “Beginning of program”. |
02:04 | Click on Save. |
02:06 | Then type: machine echo “End of program”. |
02:12 | This will print the message “Beginning of program”. |
02:16 | machine is the function call. |
02:19 | And this will print the message End of program. |
02:23 | Note that machine is the function which we created in the detail dot sh file. |
02:29 | And we are calling the function here, in function dot sh file. |
02:34 | Now click on Save. |
02:36 | Let us execute the program. |
02:41 | So, type on the terminal: chmod space plus (+) x space function dot sh |
02:51 | Press Enter. |
02:53 | Type: dot slash function dot sh |
02:56 | Press Enter. |
02:59 | The output is displayed. |
03:02 | Now let's move on to background function. |
03:06 | To run a process in the background, we use & (ampersand) at the end of a function call. |
03:13 | The shell forks a child process to run the command. |
03:19 | The forked process will have a job number and a PID (Process Identifier). |
03:27 | Let us understand this with the help of an example. I will open the file background dot sh. |
03:35 | This is the shebang line. |
03:38 | bg underscore function marks the beginning of the function. |
03:44 | The echo statement here displays the message "Inside bg_function”. |
03:50 | Next, we will use the find command to find all the dotmp3 files. |
03:57 | This statement will find all the files with the extension dot mp3. |
04:03 | It will do so in the current working directory. |
04:07 | Hyphen iname is used to ignore the case. |
04:11 | And the result is stored in myplaylist.txt. |
04:16 | Now, type: bg underscore function ampersand(&). This is the function call. '&'(Ampersand) puts 'bg_function' in the background. |
04:28 | Now click on Save. |
04:31 | Let us execute the program. |
04:34 | Come back to the terminal. |
04:37 | Type: chmod space plus x space background dot sh |
04:45 | Press Enter. |
04:46 | Now, type: dot slash background dot sh |
04:51 | Press Enter. |
04:53 | Blank output indicates dot mp3 file is not present in current directory. |
05:02 | Now, come back to our program. |
05:05 | Type: echo (hyphen) -e "Process running in background are slash n" and jobs space hyphen l |
05:19 | Click on Save. |
05:21 | This echo statement will display the message “Process running in background are ”. |
05:28 | Jobs space hyphen l lists the status of all background jobs. |
05:34 | Now come back to our terminal. |
05:38 | Now, type: dot slash background.sh. |
05:42 | Press Enter. |
05:44 | The output is shown. |
05:48 | Here, one within opening and closing square bracket is the job number. |
05:53 | 3962 is the PID. |
05:57 | PID will vary accordingly. |
06:01 | If the function takes time to execute, it will run in the background. |
06:06 | And we will see the status as Running. |
06:11 | If the function gets executed before the script, we will see the status as Done. |
06:20 | The output will vary from machine to machine. |
06:23 | This brings us to the end of this tutorial. |
06:28 | Let us Summarize. |
06:29 | In this tutorial, we learned: |
06:32 | * Source command |
06:34 | * To put a function in the background |
06:36 | with the help of some examples. |
06:39 | As an assignment: |
06:40 | Write a function add to add two numbers and call the function in another file. |
06:47 | Watch the video available at the link shown below http://spoken-tutorial.org/What_is_a_Spoken_Tutorial |
06:51 | It summarizes the Spoken-Tutorial project. |
06:55 | If you do not have good bandwidth, you can download and watch it. |
07:00 | The Spoken Tutorial Project team:
|
07:10 | For more details, please write to contact@spoken-tutorial.org |
07:18 | Spoken Tutorial Project is a part of the Talk to a Teacher project. |
07:22 | It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
07:30 | More information on this mission is available at the link shown below. http://spoken-tutorial.org\NMEICT-Intro |
07:36 | The script has been contributed by FOSSEE and Spoken-Tutorial teams. |
07:42 | This is Ashwini from IIT Bombay. Thank you for joining. |