Difference between revisions of "BASH/C3/Using-File-Descriptors/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{|border = 1
 
{|border = 1
| Time
+
|'''Time'''
| Narration
+
|'''Narration'''
  
 
|-
 
|-
|  00.01
+
|  00:01
|  Dear friends, Welcome to the spoken tutorial on''' Using file descriptors'''
+
|  Dear friends, welcome to the '''spoken tutorial''' on''' Using File Descriptors'''.
  
 
|-
 
|-
|  00.08
+
|  00:08
|  In this tutorial, we will learn to
+
|  In this tutorial, we will learn to:
  
 
|-
 
|-
|  00.11
+
|  00:11
| * Assign an '''output file descriptor'''  
+
|Assign an '''output file descriptor'''  
  
 
|-
 
|-
|  00.14
+
|  00:14
| * Assign an '''input file descriptor'''  
+
|Assign an '''input file descriptor'''  
  
 
|-
 
|-
|  00.17
+
|  00:17
| * Close the '''file descriptor (fd)'''  
+
|Close the '''file descriptor (fd)'''  
  
 
|-
 
|-
| 00.19
+
|00:19
| * With the help of some examples  
+
| with the help of some examples.
  
 
|-
 
|-
|00.23   
+
|00:23   
|  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.29
+
|00:29
| 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.35
+
|00:35
| For this tutorial I am using''' '''
+
|For this tutorial, I am using:
  
 
|-
 
|-
| 00.38
+
|00:38
| * '''Ubuntu Linux''' 12.04''' '''Operating System  
+
|'''Ubuntu Linux''' 12.04''' '''Operating System  
  
 
|-
 
|-
| 00.43
+
|00:43
| * '''GNU BASH''' version 4.2
+
|'''GNU BASH''' version 4.2
  
 
|-
 
|-
| 00.46
+
|00:46
 
| Please note,''' GNU Bash''' '''version 4''' or above is recommended for practice.
 
| Please note,''' GNU Bash''' '''version 4''' or above is recommended for practice.
  
 
|-
 
|-
| 00.54
+
|00:54
| Let us start with an introduction.
+
|Let us start with an introduction.
  
 
|-
 
|-
| 00.56
+
|00:56
| We have already studied about '''file descriptors''' in the previous tutorial.
+
|We have already studied about '''file descriptors''' in the previous tutorial.
  
 
|-
 
|-
| 01.02
+
|01:02
| * 0, 1 and 2 are the standard '''file descriptors''' for''' stdin,''' '''stdout''' and '''stderr'''
+
|0, 1 and 2 are the standard '''file descriptors''' for''' stdin,''' '''stdout''' and '''stderr'''.
  
 
|-
 
|-
| 01.15
+
|01:15
| * '''File descriptors''' are used for '''i/o redirection'''.  
+
|'''File descriptors''' are used for '''i/o redirection'''.  
  
 
|-
 
|-
| 01.20
+
|01:20
| The syntax to assign a '''file descriptor '''to an output file is:
+
|The syntax to assign a '''file descriptor '''to an '''output file''' is:
  
 
|-
 
|-
| 01.25
+
|01:25
 
| '''exec [File descriptor] greater than symbol filename'''
 
| '''exec [File descriptor] greater than symbol filename'''
  
 
|-
 
|-
| 01.31
+
|01:31
 
| Let us see an example.
 
| Let us see an example.
  
 
|-
 
|-
| 01.33
+
|01:33
| I have a code file with the name '''fdassign dot sh'''
+
| I have a '''code file''' with the name '''fdassign dot sh'''.
  
 
|-
 
|-
| 01.43
+
|01:43
| The first line is the '''shebang line.'''
+
|The first line is the '''shebang line.'''
  
 
|-
 
|-
| 01.49
+
|01:49
| The '''exec''' command replaces the current '''shell process'''.
+
|The '''"exec"''' command replaces the current '''shell process'''.
  
 
|-
 
|-
| 01.56
+
|01:56
| It will be executed in the place of the current '''shell '''without creating a new process.
+
|It will be executed in the place of the current '''shell '''without creating a new '''process'''.
  
 
|-
 
|-
| 02.04
+
|02:04
| We know that 0, 1, and 2 are standard '''file descriptors. '''
+
| We know that 0, 1, and 2 are standard '''file descriptors.'''
  
 
|-
 
|-
| 02.09
+
|02:09
 
| For any newly opened file, we have additional '''file descriptors''' from 3 to 9.
 
| For any newly opened file, we have additional '''file descriptors''' from 3 to 9.
  
 
|-
 
|-
|  02.19
+
|  02:19
| Here, '''3 '''is the '''file descriptor'''.
+
| Here, 3 is the '''file descriptor'''.
  
 
|-
 
|-
|  02.22
+
|  02:22
| This will write the output to the '''output dot txt''' file.
+
| This will write the '''output''' to the '''output dot txt''' file.
  
 
|-
 
|-
|  02.30
+
|  02:30
|  The string '''"Welcome to BASH learning" '''is sent to the file '''output dot txt'''  
+
|  The '''string''' "Welcome to BASH learning" is sent to the file '''output dot txt'''.
  
 
|-
 
|-
|  02.36
+
|  02:36
 
| This is done via '''file descriptor 3'''.
 
| This is done via '''file descriptor 3'''.
  
 
|-
 
|-
| 02.42
+
|02:42
| This is similar to redirecting a string to a file.
+
|This is similar to redirecting a '''string''' to a file.
  
 
|-
 
|-
| 02.49
+
|02:49
| Each new string will be appended to the file.
+
|Each new string will be appended to the file.
  
 
|-
 
|-
| 02.52
+
|02:52
| For example:
+
|For example:
  
 
|-
 
|-
| 02.54
+
|02:54
 
| We will append the current '''system date''' to the''' output dot txt''' file.  
 
| We will append the current '''system date''' to the''' output dot txt''' file.  
  
 
|-
 
|-
| 03.00
+
|03:00
| The syntax is: '''date SPACE greater-than symbol ampersand sign 3'''
+
|The syntax is: '''date SPACE greater-than symbol ampersand sign 3'''.
  
 
|-
 
|-
| 03.13
+
|03:13
| Here we close the '''file descriptor'''.
+
|Here, we close the '''file descriptor'''.
  
 
|-
 
|-
| 03.16
+
|03:16
| After this line, the '''descriptor '''cannot write anything to the '''output dot txt''' file.
+
|After this line, the '''descriptor '''cannot write anything to the '''output dot txt''' file.
  
 
|-
 
|-
| 03.23
+
|03:23
| Let us execute the code and see the output.
+
|Let us '''execute''' the '''code''' and see the '''output'''.
  
 
|-
 
|-
| 03.26
+
|03:26
| Open the '''terminal '''using '''CTRL+ALT+T''' keys.
+
|Open the '''terminal '''using '''CTRL+ALT+T''' keys.
  
 
|-
 
|-
| 03.34
+
|03:34
| Type: '''chmod space plus x space fdassign dot sh'''
+
|Type: '''chmod space plus x space fdassign dot sh'''
  
 
|-
 
|-
| 03.41
+
|03:41
| Type: '''dot slash fdassign dot sh'''
+
|Type: '''dot slash fdassign dot sh'''
  
 
|-
 
|-
|  03.46
+
|  03:46
|  Let us check the output now by typing '''cat space output dot txt'''
+
|  Let us check the '''output''' now by typing '''cat space output dot txt'''.
  
 
|-
 
|-
|  03.56
+
|  03:56
| We can see that the string '''Welcome to BASH learning''' and the current '''system date''' is displayed.
+
| We can see that the string '''"Welcome to BASH learning"''' and the current '''system date''' is displayed.
  
 
|-
 
|-
| 04.05
+
| 04:05
|  Let us go back to the editor.
+
|  Let us go back to the '''editor'''.
  
 
|-
 
|-
|  04.11
+
|  04:11
 
| Now I will type '''echo '''at the end, after the '''descriptor '''is closed.
 
| Now I will type '''echo '''at the end, after the '''descriptor '''is closed.
  
 
|-
 
|-
|  04.17
+
|  04:17
| Type: '''echo within double quotes Hi after quotes space greater than symbol ampersand sign 3'''
+
| Type: '''echo space''' within double quotes '''Hi''' after quotes '''space''' '''greater than''' symbol '''ampersand''' sign '''3'''
  
 
|-
 
|-
|  04.31
+
|  04:31
 
| Click on '''Save'''.  
 
| Click on '''Save'''.  
  
 
|-
 
|-
|  04.35
+
|  04:35
| Let us execute the script once again and see what happens.
+
| Let us '''execute''' the '''script''' once again and see what happens.
  
 
|-
 
|-
|  04.38
+
|  04:38
|  On the '''terminal''', press the uparrow key twice recall the previous command '''dot slash fdassign dot sh'''
+
|  On the '''terminal''', press the up-arrow key twice, recall the previous command '''dot slash fdassign dot sh'''.
  
 
|-
 
|-
|  04.50
+
|  04:50
 
| press '''Enter.'''
 
| press '''Enter.'''
  
 
|-
 
|-
|  04.52
+
|  04:52
|  We see an error
+
|  We see an error:
  
 
|-
 
|-
|  04.55
+
|  04:55
| '''Bad file descriptor'''
+
| '''"Bad file descriptor"'''.
  
 
|-
 
|-
|  04.58
+
|  04:58
 
|  Let us fix this error.
 
|  Let us fix this error.
  
 
|-
 
|-
|  05.00
+
|  05:00
| Come back to the editor.
+
| Come back to the '''editor'''.
  
 
|-
 
|-
|  05.03
+
|  05:03
| I will cut the last line of code and paste it below the '''date command'''
+
| I will cut the last line of code and paste it below the '''date command'''.
  
 
|-
 
|-
| 05.11
+
| 05:11
 
|  Click on '''Save'''.
 
|  Click on '''Save'''.
  
 
|-
 
|-
|  05.13
+
|  05:13
| Let us execute the code once again. On the '''terminal'''
+
| Let us '''execute''' the '''code''' once again, on the '''terminal'''.
  
 
|-
 
|-
|  05.19
+
|  05:19
| Recall the previous command '''dot slash fdassign.sh'''
+
| Recall the previous command '''dot slash fdassign.sh'''.
  
 
|-
 
|-
|  05.24
+
|  05:24
 
| press '''Enter.'''
 
| press '''Enter.'''
  
 
|-
 
|-
|  05.26
+
|  05:26
 
|  Now let us open the '''output dot txt''' file.
 
|  Now let us open the '''output dot txt''' file.
  
 
|-
 
|-
|  05.29
+
|  05:29
 
| Type: '''cat space output dot txt'''
 
| Type: '''cat space output dot txt'''
  
 
|-
 
|-
| 05.41
+
| 05:41
 
|  We can see the output.
 
|  We can see the output.
  
 
|-
 
|-
|  05.43
+
|  05:43
| The string '''Hi '''is displayed at the end.
+
| The string "Hi" is displayed at the end.
  
 
|-
 
|-
|  05.49
+
|  05:49
|  Now we will assign the '''file descriptor''' to the input file.
+
|  Now we will assign the '''file descriptor''' to the '''input file'''.
  
 
|-
 
|-
|  05.54
+
|  05:54
 
| Let us see an example.
 
| Let us see an example.
  
 
|-
 
|-
|  05.56
+
|  05:56
| I have a file named '''fdread dot sh'''
+
| I have a file named '''fdread dot sh'''.
  
 
|-
 
|-
|  06.03
+
|  06:03
 
| Let us go through it.
 
| Let us go through it.
  
 
|-
 
|-
|  06.07
+
|  06:07
|  This is the '''exec command.'''
+
|  This is the''' 'exec' '''command.
  
 
|-
 
|-
|  06.13
+
|  06:13
| Here we will read the file '''output dot txt'''
+
| Here we will read the file '''output dot txt'''.
  
 
|-
 
|-
|  06.19
+
|  06:19
| The line '''exec 3 greater than symbol output dot txt''' will open the file for reading.
+
| The line '''exec 3 lesser than symbol output dot txt''' will open the file for reading.
  
 
|-
 
|-
|  06.30
+
|  06:30
| '''cat command''' will display the content of the file.
+
| ''' 'cat' '''command will display the content of the file.
  
 
|-
 
|-
|  06.35
+
|  06:35
| And finally we close the '''file descriptor.'''
+
| And finally, we close the '''file descriptor.'''
  
 
|-
 
|-
| 06.39
+
| 06:39
|  Now let us execute this '''shell script'''.
+
|  Now, let us '''execute''' this '''shell script'''.
  
 
|-
 
|-
|  06.42
+
|  06:42
 
| On the '''terminal''', let me clear the '''prompt'''.  
 
| On the '''terminal''', let me clear the '''prompt'''.  
  
 
|-
 
|-
|  06.47
+
|  06:47
 
| Type: '''chmod space plus x space fdread dot sh'''
 
| Type: '''chmod space plus x space fdread dot sh'''
  
 
|-
 
|-
|  06.55
+
|  06:55
 
| Type '''dot slash fdread dot sh'''
 
| Type '''dot slash fdread dot sh'''
  
 
|-
 
|-
|  07.01
+
|  07:01
 
|  We can see the output on the '''terminal'''.
 
|  We can see the output on the '''terminal'''.
  
 
|-
 
|-
|  07.05
+
|  07:05
 
| The content of '''output dot txt''' file is displayed.
 
| The content of '''output dot txt''' file is displayed.
  
 
|-
 
|-
|  07.10
+
|  07:10
 
|  This brings us to the end of this tutorial.
 
|  This brings us to the end of this tutorial.
  
 
|-
 
|-
|  07.13
+
|  07:13
|  Come back to the slides.
+
|  Come back to the '''slides'''.
  
 
|-
 
|-
|  07.16
+
|  07:16
| Let us summarize.
+
| Let us summarize. In this tutorial, we learned to:
  
 
|-
 
|-
|  07.17
+
|  07:19
| In this tutorial we learnt to,
+
|Assign the '''output file descriptor'''
  
 
|-
 
|-
| 07.19
+
|07:22
| * Assign the '''output file descriptor'''  
+
|Assign the '''input file descriptor'''
  
 
|-
 
|-
| 07.22
+
|07:26
| * Assign the '''input file descriptor'''
+
|Close the '''file descriptor'''.
  
 
|-
 
|-
| 07.26
+
|07:28
| * Close the '''file descriptor'''.
+
|As an assignment:
  
 
|-
 
|-
| 07.28
+
|07:30
| As an assignment,
+
| Try to append a few lines to a file '''test dot txt''' using '''file descriptors''';
  
 
|-
 
|-
| 07.30
+
|07:36
| Try to append a few lines to a file '''test dot txt'''using '''file descriptors'''
+
| Display the contents of the file using '''file descriptors'''.
  
 
|-
 
|-
| 07.36
+
|07:41
| Display the content of the file using '''file descriptors'''
+
|Watch the video available at the link shown below.
  
 
|-
 
|-
| 07.41
+
|07:45
| Watch the video available at the link shown below.
+
| It summarizes the Spoken-Tutorial project.
  
 
|-
 
|-
| 07.45
+
|07:48
| It summarises the Spoken Tutorial project.
+
 
+
|-
+
|  07.48
+
 
| 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.
  
 
|-
 
|-
|   07.53
+
|07:53
| The Spoken Tutorial Project Team Conducts workshops using spoken tutorials
+
|The Spoken Tutorial Project team: Conducts workshops using spoken tutorials.
  
 
|-
 
|-
| 07.58
+
|07:58
| Gives certificates to those who pass an online test
+
| Gives certificates to those who pass an online test.
  
 
|-
 
|-
| 08.02
+
|08:02
 
| For more details, please write to '''contact@spoken-tutorial.org'''
 
| For more details, please write to '''contact@spoken-tutorial.org'''
  
 
|-
 
|-
| 08.10
+
|08:10
| 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.
  
 
|-
 
|-
| 08.14
+
|08:14
 
| 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.
  
 
|-
 
|-
| 08.22
+
|08:22
| 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
  
 
|-
 
|-
|   08.28
+
|08:28
| The script has been contributed by FOSSEE and Spoken-Tutorial teams.
+
|The script has been contributed by FOSSEE and Spoken-Tutorial teams.
  
 
|-
 
|-
| 08.33
+
|08:33
| This is Ashwini Patil from IIT Bombay. Signing off
+
|This is Ashwini Patil from IIT Bombay, signing off.
  
 
|-
 
|-
| 08.37
+
|08:37
| Thank you for joining.
+
|Thank you for joining.
  
 
|}
 
|}

Latest revision as of 17:03, 23 March 2017

Time Narration
00:01 Dear friends, welcome to the spoken tutorial on Using File Descriptors.
00:08 In this tutorial, we will learn to:
00:11 Assign an output file descriptor
00:14 Assign an input file descriptor
00:17 Close the file descriptor (fd)
00:19 with the help of some examples.
00:23 To follow this tutorial, you should have knowledge of Shell Scripting in BASH.
00:29 If not, for relevant tutorials, please visit our website which is as shown. http://www.spoken-tutorial.org
00:35 For this tutorial, I am using:
00:38 Ubuntu Linux 12.04 Operating System
00:43 GNU BASH version 4.2
00:46 Please note, GNU Bash version 4 or above is recommended for practice.
00:54 Let us start with an introduction.
00:56 We have already studied about file descriptors in the previous tutorial.
01:02 0, 1 and 2 are the standard file descriptors for stdin, stdout and stderr.
01:15 File descriptors are used for i/o redirection.
01:20 The syntax to assign a file descriptor to an output file is:
01:25 exec [File descriptor] greater than symbol filename
01:31 Let us see an example.
01:33 I have a code file with the name fdassign dot sh.
01:43 The first line is the shebang line.
01:49 The "exec" command replaces the current shell process.
01:56 It will be executed in the place of the current shell without creating a new process.
02:04 We know that 0, 1, and 2 are standard file descriptors.
02:09 For any newly opened file, we have additional file descriptors from 3 to 9.
02:19 Here, 3 is the file descriptor.
02:22 This will write the output to the output dot txt file.
02:30 The string "Welcome to BASH learning" is sent to the file output dot txt.
02:36 This is done via file descriptor 3.
02:42 This is similar to redirecting a string to a file.
02:49 Each new string will be appended to the file.
02:52 For example:
02:54 We will append the current system date to the output dot txt file.
03:00 The syntax is: date SPACE greater-than symbol ampersand sign 3.
03:13 Here, we close the file descriptor.
03:16 After this line, the descriptor cannot write anything to the output dot txt file.
03:23 Let us execute the code and see the output.
03:26 Open the terminal using CTRL+ALT+T keys.
03:34 Type: chmod space plus x space fdassign dot sh
03:41 Type: dot slash fdassign dot sh
03:46 Let us check the output now by typing cat space output dot txt.
03:56 We can see that the string "Welcome to BASH learning" and the current system date is displayed.
04:05 Let us go back to the editor.
04:11 Now I will type echo at the end, after the descriptor is closed.
04:17 Type: echo space within double quotes Hi after quotes space greater than symbol ampersand sign 3
04:31 Click on Save.
04:35 Let us execute the script once again and see what happens.
04:38 On the terminal, press the up-arrow key twice, recall the previous command dot slash fdassign dot sh.
04:50 press Enter.
04:52 We see an error:
04:55 "Bad file descriptor".
04:58 Let us fix this error.
05:00 Come back to the editor.
05:03 I will cut the last line of code and paste it below the date command.
05:11 Click on Save.
05:13 Let us execute the code once again, on the terminal.
05:19 Recall the previous command dot slash fdassign.sh.
05:24 press Enter.
05:26 Now let us open the output dot txt file.
05:29 Type: cat space output dot txt
05:41 We can see the output.
05:43 The string "Hi" is displayed at the end.
05:49 Now we will assign the file descriptor to the input file.
05:54 Let us see an example.
05:56 I have a file named fdread dot sh.
06:03 Let us go through it.
06:07 This is the 'exec' command.
06:13 Here we will read the file output dot txt.
06:19 The line exec 3 lesser than symbol output dot txt will open the file for reading.
06:30 'cat' command will display the content of the file.
06:35 And finally, we close the file descriptor.
06:39 Now, let us execute this shell script.
06:42 On the terminal, let me clear the prompt.
06:47 Type: chmod space plus x space fdread dot sh
06:55 Type dot slash fdread dot sh
07:01 We can see the output on the terminal.
07:05 The content of output dot txt file is displayed.
07:10 This brings us to the end of this tutorial.
07:13 Come back to the slides.
07:16 Let us summarize. In this tutorial, we learned to:
07:19 Assign the output file descriptor
07:22 Assign the input file descriptor
07:26 Close the file descriptor.
07:28 As an assignment:
07:30 Try to append a few lines to a file test dot txt using file descriptors;
07:36 Display the contents of the file using file descriptors.
07:41 Watch the video available at the link shown below.
07:45 It summarizes the Spoken-Tutorial project.
07:48 If you do not have good bandwidth, you can download and watch it.
07:53 The Spoken Tutorial Project team: Conducts workshops using spoken tutorials.
07:58 Gives certificates to those who pass an online test.
08:02 For more details, please write to contact@spoken-tutorial.org
08:10 Spoken Tutorial Project is a part of the Talk to a Teacher project.
08:14 It is supported by the National Mission on Education through ICT, MHRD, Government of India.
08:22 More information on this mission is available at the link shown below http://spoken-tutorial.org/NMEICT-Intro
08:28 The script has been contributed by FOSSEE and Spoken-Tutorial teams.
08:33 This is Ashwini Patil from IIT Bombay, signing off.
08:37 Thank you for joining.

Contributors and Content Editors

Gaurav, PoojaMoolya, Pratik kamble, Sandhya.np14