BASH/C3/More-on-functions/Gujarati

From Script | Spoken-Tutorial
Revision as of 15:29, 5 February 2015 by Jyotisolanki (Talk | contribs)

Jump to: navigation, search
Time Narration
00:01 More on functions પરનાં સ્પોકન ટ્યુટોરીયલમાં સ્વાગત છે.
00:06 આ ટ્યુટોરીયલમાં, આપણે શીખીશું
00:09 ફંક્શનમાં આર્ગ્યુંમેંટ પસ કરતા.
00:11 ફંક્શનમાં local variable વ્યાખ્યિત કરતા.
00:16 ફંક્શનમાં global variable વ્યાખ્યિત કરતા.
00:19 ઉદાહરણ સાથે સમજીએ.
00:23 આ ટ્યુટોરીયલનાં અનુસરણ માટે તમને બેશમાંનાં Shell Scripting નું જ્ઞાન હોવું અનિવાર્ય છે.
00:28 જો નથી, તો સંદર્ભિત ટ્યુટોરીયલો માટે કૃપા કરી દર્શાવેલ અમારી વેબસાઈટનો સંદર્ભ લો, (http://www.spoken-tutorial.org)
00:35 આ ટ્યુટોરીયલ માટે હું વાપરી રહી છું.
00:37 ઉબુન્ટુ લીનક્સ 12.04 ઓપરેટીંગ સીસ્ટમ
00:42 GNU BASH આવૃત્તિ 4.2
00:45 પા કરી નોંધ લો, આ ટ્યુટોરીયલનાં અભ્યાસ માટે GNU Bash આવૃત્તિ 4 કે તેથી વધુ આગ્રહ કરીએ છીએ.
00:52 ચાલો ફંક્શન માં આર્ગ્યુંમેંટ કેવી રીતે પાસ કરવું અને કેવી રીતે વાપરવું તે શીખીએ.
00:59 ચાલો હું 'function_(underscore) parameters.sh' ફાઈલ ખોલું.
01:05 shebang line. છે.
01:08 say_(underscore)welcome આ આપણા ફંક્શન નું નામ છે.
01:13 Open curly bracket opens the function definition.
01:18 $(Dollar)1 is the first positional parameter
01:22 $(Dollar)2 is the second postional parameter
01:26 Close curly bracket closes the function definition.
01:30 Here, the function 'say_welcome' is called with arguments.
01:35 The syntax is, function name i.e. say welcome ...followed by the arguments within double quotes, i.e. Bash and learning.
01:49 In a similar manner, I will call the same function with a different set of arguments. So, I havesay_welcome space within double quote functions in space and within double quote Bash.
02:05 Save the file and go to the terminal.
02:08 Type chmod space plus x space function underscore parameters dot sh
02:17 Press Enter.
02:19 Type dot slash function underscore parameters dot sh
02:26 Press Enter.
02:28 We see that the positional parameters were substituted by the arguments passed to a function.
02:36 Dollar 1($1) was substituted by the string Bash and Dollar 2($2) with learning.
02:45 Then again, Dollar 1($1) was substituted by functions in and Dollar 2($2) with Bash.
02:55 In Bash, variables can be declared as local variables and global variables.
03:01 Local variable:
03:03 It's value will be valid within the function in which it is defined.
03:10 Local variables are declared using keyword local
03:15 Global variable
03:17 The value of a global variable can be accessed throughout a Bash script.
03:24 Let us learn these 2 ways to declare a variable within a function.
03:29 Let me open a file named function_(undescore)local.sh'
03:35 This is the shebang line.
03:39 Function name is say_(underscore) hello
03:43 Here, variable first_name is declared with keyword local.
03:49 Which means, its value will be valid within the function say_hello only.
03:55 A variable declared without any keyword,is treated as a global variable.
04:01 So, the variable last_name can be accessed throughout the script.
04:08 In this echo line, we will display the value of variables
04:12 first_name,
04:14 middle_name
04:15 And last_name
04:17 After this, we close the function.
04:21 Now, here the variable middle_name is declared without keyword. So, its value will be global throughout the script.
04:30 Once again, we will call the function here.
04:34 We pass two arguments to this function call, namely, “Pratik” and “Patil”.
04:41 These echo statements will display the value of variables
04:45 $first_name,
04:46 $middle_name and $last_name
04:51 Please keep in mind that variable first_name is a local variable.
04:57 Save the file and go to the terminal.
05:00 Type chmod space plus x space function underscore local dot sh
05:09 Press Enter.
05:11 Type dot slash function underscore local dot sh
05:16 Press Enter.
05:18 The first line of output displays the message Hello Pratik K Patil.
05:25 Here, the variable first_name that contains value Pratik is local.
05:31 Which means the value is limited to the function.
05:35 Now, let us see how the local variable behaves outside the function.
05:41 Here, nothing is displayed in first_name.
05:44 This is because the value of first_name is local to the function. And it is not available outside the function.
05:53 middle_name and last_name are printed as they are global variables.
05:59 Hope the difference is clear to you.
06:02 Let us now summarise.
06:04 In this tutorial, we learnt
06:07 To pass arguments to a function .To declare Local variable in a function
06:14 To declare Global variable in a function. with the help of a few examples
06:20 As an assignment.
06:22 Write a program,
06:23 Where the function accepts two arguments. The function should multiply the two arguments.
06:31 Make 3 function calls with arguments (1, 2), (2, 3) and (3, 4)
06:39 Watch the video available at the link shown below.
06:43 It summarises the Spoken Tutorial project.If you do not have good bandwidth, you can download and watch it.
06:51 The Spoken Tutorial Project Team.Conducts workshops using spoken tutorials. Gives certificates to those who pass an online test
07:00 For more details, please write to contact@spoken-tutorial.org
07:07 Spoken Tutorial Project is a part of the Talk to a Teacher project.
07:11 It is supported by the National Mission on Education through ICT, MHRD, Government of India.More information on this Mission is available at http://spoken-tutorial.org\NMEICT-Intro
07:26 The script has been contributed by FOSSEE and Spoken-Tutorial teams.
07:31 This is Ashwini Patil from IIT Bombay signing off.Thank you for joining.

Contributors and Content Editors

Jyotisolanki, PoojaMoolya