BASH/C2/Conditional-execution/Gujarati

From Script | Spoken-Tutorial
Revision as of 12:41, 30 December 2014 by Jyotisolanki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Title of script: Conditional Execution in BASH

Author: Jyoti Solanki

Keywords: video tutorial, Bash shell, Simple if, else-if.

Time Narration
00:01 નમસ્તે મિત્રો, બેશમાં Conditional execution પરનાં આ સ્પોકન ટ્યુટોરીયલમાં સ્વાગત છે.
00:08 આ ટ્યુટોરીયલમાં, આપણે આપેલ વિશે શીખીશું,
00:10 * test કમાંડ નો ઉપયોગ.
00:13 અને Conditional સ્ટેટમેંટ
00:15 આપણે અમુક ઉદાહરણના મદદથી કરીશું.
00:19 આ ટ્યુટોરીયલનાં અનુસરણ માટે તમે
00:21 GNU/Linux Operating System. થી પરિચિત હોવા જોઈએ
00:26 જો નથી, તો સંબંધિત ટ્યુટોરિયલ્સ માટે આપેલ અમારી વેબસાઈટની મુલાકાત લો.
00:32 આ ટ્યુટોરીયલ માટે, હું વાપરી રહ્યી છું,
00:35 * ઉબ્નટુ લીનક્સ 12.04 OS
00:39 અને * GNU Bash આવૃત્તિ 4.1.10
00:43 પ્રેક્ટીસ માટે GNU Bash આવૃત્તિ 4 અથવા તેથી વધુનો આગ્રહ કરીએ છીએ.
00:49 ચાલો test. ના પરિચય સાથે શરૂઆત કરીએ.
00:52 * test એક built-in કમાંડ છે , જે exit status. પાછુ આપે છે.
00:57 તે ટ્રૂ માટે 0 અને ફોલ્સ માટે 1 પાછુ આપે છે.
01:02 * રીટર્ન વેલ્યુ એક્સપ્રેશનના મૂલ્યાંકન પર આધારિત છે.
01:07 * return સ્ટેટસ આપેલ ટાઈપ કરીને કરી શ્કાવાય છે.Dollar અને question mark ચિન્હ ($?)
01:14 * એક્સપ્રેશનને બે રીતે ઇવેલ્યૂટ કરી શક્વાય છે-
01:18 # પહેલું છે test કીવર્ડનો ઉપયોગ.
01:21 અને અન્ય છે ચોરસ કૌંસમાં એક્સપ્રેશનને મુકીને.
01:27 એક સાથે Ctrl+Alt અને T કી દાબીને ટર્મિનલ વિન્ડો ખોલો.
01:35 ટાઈપ કરો : test space 4 space hyphen eq space 4 semicolon space echo space dollar ચિન્હ અને question mark. એન્ટર દબાઓ.
01:53 આનાથી zero પાછુ મળે છે.જેનો અર્થ true છે.
01:57 4 બરાબર 4 છે
02:00 આગળ ટાઈપ કરો:
02:02 ખુલ્લો ચોરસ કૌંસ space 4 space hyphen eq space 4 space બંદ ચોરસ કૌંસ semicolon space echo space dollar ચિન્હ અને question mark. એન્ટર દબાઓ.
02:22 આનાથી zero પાછુ મળેછે જેનો અર્થ true છે.
02:25 એટલેકે .4 બરાબર 4.
02:28 ચાલો બીજું એક એક્સપ્રેશન લઈએ. ટાઈપ કરો:

test space 4 space hyphen eq space 5 semicolon space echo space dollar ચિન્હ question mark .

એન્ટર દબાઓ.
02:48 આનાથી એક પાછુ મળે છે જેનો અર્થ ફોલ્સ છે.
02:52 એટલેકે .4 બરાબર 5. નથી.
02:56 હવે ચાલો સમાન એક્સપ્રેશનને ચોરસ કૌંસમાં લખીએ.ટાઈપ કરો :
03:01 ખુલ્લો ચોરસ કૌંસ space 4 space hyphen eq space 5 space બંદ ચોરસ કૌંસ semicolon space echo space dollar ચિન્હ question mark એન્ટર દબાઓ.
03:21 It also returns one which means false આપણ એક પાછુ આપે છે જેનો અર્થ ફોલ્સ છે .
03:25 એટલેકે .4 બરાબર 5. નથી.
03:29 અને બીજા પ્રકારની ચકાસણી માટે વિસ્તારિત કરી શકાય છે.
03:33 ટાઈપ કરો man space test અને તેના ઉપયોગ નું અન્વેષણ કરો.
03:40 ચાલો આપણી સ્લાઈડ પર પાછા જાઓ.
03:43 હવે આપણે if સ્ટેટમેંટનું સિન્ટેક્સ જોશું-
03:48 if space ખુલ્લો ચોરસ કૌંસ space expression space બંદ ચોરસ કૌંસ semicolon space then
03:59 આગળની લાઈન પર ટાઈપ કરો commands અથવા statements જે તમે એક્ઝીક્યુટ કરવા ઈચ્છો છો.
04:05 છેલ્લે, if loop નો અંત fi. થી કરો .
04:11 કન્ડીશનના સમાન્ય નિયમો આ પ્રમાણે છે:
04:14 કૌંસ અને એક્સપ્રેશન વચ્ચે હમેશા સ્પેસ રાખો.
04:19 then” કીવર્ડ પહેલા હમેશા લાઈનોને અર્ધવિરામ દ્વારા ટરમીનેટ કરો.
04:25 સ્ટેટમેંટ અથવા એક્સપ્રેશનને ટરમીનેટ કરવા માટે અર્ધવિરામનો ઉપયોગ થાય છે.
04:31 જો તમે સ્ટ્રીંગ વેરીએબલોને કન્ડીશનો માં વાપરી રહ્યા હોય,તો તેને અવતરણમાં મુકવાનું આગ્રહ કરીએ છીએ.
04:38 કન્ડીશન બ્લોકને “fi”. વડે બંદ કરવાનું ભૂલશો નહી.
04:43 ચાલો if . સ્ટેટમેંટ પર ઉદાહરણ જોઈએ.
04:46 ટર્મિનલ પર પાછા આવીએ.
04:49 હું simpleif.sh નામની પહેલાથી ઉપલબ્ધ સ્ક્રીપ્ટ ફાઈલને ખોલીશ.
04:58 આ બેશ સ્ક્રીપ્ટ “count is 100” આ મેસેજ દર્શાવે છે,જયારે ગણતરી 100 ની બરાબર થાય છે.
05:06 બેશ શેલ સ્ક્રીપ્ટની આ પ્રથમ લાઈન છે.જેને shebang line. તરીકે ઓળખાવાય છે .
05:12 variable count.' ને ઇનટીજર 100 અસાઇન કરાયું છે.
05:17 નોંધ લો કે count, = અને 100. વચ્ચે કોઈ પણ સ્પેસ હોવી ના જોઈએ.
05:24 counthundred. ની બરાબર છે કે નહી તે આ સમીકરણ તપાસ કરે છે.
05:30 અહી -eq comparison operator છે.
05:35 If the condition is true, it will display the message count is 100
05:41 fi is to end if block.
05:45 Save the file by pressing “Ctrl + s”
05:49 Go back to the Terminal.
05:51 To make the file executable, type: chmod space plus x space simpleif.sh and Press Enter.
06:04 Let me clear the prompt.
06:06 Now type dot slash simpleif.sh Press Enter.
06:14 Here it is displayed:
06:16 Count is 100.
06:18 Try changing the value of variable count and execute the script.
06:24 Switch back to slides.
06:26 We will see if-else condition.
06:30 The general syntax is: if space opening square bracket space condition space closing square bracket space semicolon space then
06:44 On the next line, type commands
06:47 On the next line, there is else statement
06:51 And again type some other commands.
06:55 on the next line, type fi to end i block.
07:00 Let us study the usage of if-else with an interesting password program.
07:06 Come back to the terminal.
07:09 I will open the file ifelse.sh
07:14 This is the shebang line
07:17 Here,abc123 is stored in the variable PASS
07:23 As abc123 is a string, it should be written within double-quotes.
07:29 The read command reads one line of data from the standard input.
07:35 In this case, standard input is our keyboard.
07:39 Hyphen s is for silent mode.
07:43 Which means the entered password will not be displayed as we type.
07:48 We don't want others to see our password.
07:52 Hyphen p is for prompt.
07:55 It will display a string “'Enter password: ” before it takes input from user.
08:01 mypassword is a variable.
08:04 It stores the string, in this case the password entered by the user.
08:10 This checks that the entered password matches the value of the variable PASS.
08:17 It is stored in a variable mypassword
08:21 If the password matches, it will display the message
08:25 “Password accepted”
08:27 else it will display “Access denied”
08:31 fi is the end of if-else loop
08:34 Now save the file by pressing “Ctrl s” .
08:38 Come back to our terminal, make the file executable type:

chmod space plus x space ifelse.sh .Press Enter.

08:52 Type dot slash ifelse.sh . Press Enter.


08:57 Here it is displayed :
08:59 Enter password:
09:00 I will type abc press Enter
09:05 As the password entered is wrong, it displays the message as “Access denied”
09:11 Let's execute again, but this time we will enter password as abc123
09:21 It is displayed as: Password accepted
09:25 This bring us to the end of this tutorial.
09:28 Come back to our slides and summarize.
09:31 In this tutorial we have covered Usage of test command , Simple if statement & if else statement .
09:41 As an assignment
09:43 # Write a script , take your name as an input.
09:46 # It should check this name with your system's username.
09:51 If the username matches, it should greet you by displaying “Hello
09:56 # Else, it should display “Try again
10:00 HINT: Your system's username is stored in a variable $USER
10:06 Watch the video available at the link shown below
10:09 It summarizes the Spoken Tutorial project
10:11 If you do not have good bandwidth, you can download and watch it
10:16 The Spoken Tutorial Project Team
10:18 Conducts workshops using spoken tutorials
10:22 Gives certificates to those who pass an online test
10:26 For more details, please write to contact@spoken-tutorial.org
10:33 Spoken Tutorial Project is a part of the Talk to a Teacher project
10:37 It is supported by the National Mission on Education through ICT, MHRD, Government of India
10:45 More information on this Mission is available at the link shown below.
10:51 The script has been contributed by FOSSEE and spoken-tutorial team.
10:56 This is Ashwini from IIT Bombay signning off.
11:01 Thank you for joining.

Contributors and Content Editors

Jyotisolanki, PoojaMoolya, Pratik kamble, Sakinashaikh