SlideShare une entreprise Scribd logo
1  sur  21
Computer Science Lab 1
2 
SShheellll SSccrriippttiinngg ((CC sshheellll)) 
by
3 
CCoonntteennttss 
C shell 
– First Script 
– Getting User Input 
– Command Line Arguments 
– Conditionals and File Testing 
– Switch & Loops 
Programming with C Shell 
– mailingList 
Summary & Resources
4 
CC SShheellll 
#! /bin/csh 
 set name = hello -> echo $name 
$array = ( element1 elemsnt2 ) 
$array[1] , $array[2]
5 
CC SShheellll –– FFiirrsstt SSccrriipptt 
 ${LOGNAME} 
– Print user’s name 
 `unix command` 
– Enclosed in back quotes 
– Performed command substitution 
– Ex) `date` 
 uname –n 
– Display the machine name 
 ps –ef | grep “^ *$LOGNAME” 
– User’s processes are printed 
 chmond –u+x greetme
6 
CC sshheellll GGeettttiinngg UUsseerr IInnppuutt 
$< 
– user input (std) without newline 
$array = ($name) 
– An array is created 
Arithmetic ( operators ): @ integer 
+ , - , / , * , % , << , >> 
+= , -=, *=, /=, ++, -- 
• Ex) @ sum = 4+6 
– Space is required after @
7 
CCsshheellll DDeebbuuggggiinngg ssccrriippttss 
Echo (-x) and Verbose (-v) 
– csh –x scriptname (command ) 
• Display each line after variable substitution and 
before execution 
– set echo , unset ( in the file )
8 
c Cshell coommmmaanndd lliinnee aarrgguummeenntt 
$0 - The name of the script 
$1, $2, $3,..${10} 
– Parameters are referenced by number 
$* - All positional parameters 
$argv[1], $argv[2] 
– The first argument , second … 
$argv[*] or $argv – all arguments 
$#argv – The number of arguments (size) 
$argv[$#argv] – The last argument
9 
Cshell Conditional ccoonnssttrruuccttss 
 == , != , <, > , >= , <= , ! 
 =~ , !~ 
– String matches ex) $ans =~ [Yy]* 
|| , && 
– Logical operator
10 
CCsshheellll iiff eexxaammpplleess 
IIff(( eexxpprreessssiioonn )) tthheenn 
CCoommmmaanndd 
eellssee 
CCoommmmaanndd 
eennddiiff 
Ex) if ( $#argv != 1) then 
echo “$0 requires an argument” 
exit 1 
endif
11 
CCsshheellll iiff eexxpprreessssiioonn 
 set name = $< 
If( “$name” != “” ) then 
grep “$name” data file 
endif 
 If( $answer =~ [Yy]* ) then 
mail bob < message 
else 
mail jon < datafile 
endif 
 set x = 1 , y = 2, z = 3 
If( (“$x” && “$y”) || ! “$z”) then 
echo TRUE 
 If( $#argv == 0 ) exit 1
12 
CCsshheellll iiff ccoommmmaanndd 
 If { (command) } then 
command 
endif 
 If { ( who | grep $1 >& /dev/null ) } then 
echo $1 is logged on 
endif 
 startover: 
set grade = $< 
if( “$grade” < 0 || “$grade” > 100 ) then 
echo “Illegal grade” 
goto startover 
endif
13 
CCsshheellll iiff ffiillee tteessttiinngg 
 if( ! –e $file ) : file exists 
 if( -d $file ) : a direcotry file 
 if( -f $file ) : a plain file 
 if( ! –z $file ) : zero length 
 if( -r $file && -w $file): readable and writable 
 if( -x $file ): executable
14 
CCsshheellll SSwwiittcchh 
set color = $< 
sswwiittcchh ((“$color”)) 
ccaassee bl*:: 
echo I feel $color 
bbrreeaakkssww 
ddeeffaauulltt:: 
echo $color not one of them 
bbrreeaakkssww 
eennddssww
15 
CCsshheellll ffoorr 
ffoorreeaacchh vvaarriiaabbllee ((wwoorrddlliisstt)) 
ccoommmmaannddss 
eenndd 
– foreach person ( bob sam sue fred) 
mail $person < letter 
end 
– foreach person (`cat maillist`) 
mail $person <<EOF 
Hi $person 
EOF 
end
16 
CCsshheellll wwhhiillee 
 set num = 0 
wwhhiillee ($num < 10 ) 
echo $num 
@ num++ 
eenndd 
 rreeppeeaattee takes two argument( number, command) 
– Ex) %repeate 3 echo hello 
hello 
hello 
hello
17 
CCsshheellll WWhhiillee 
sshhiifftt command 
– Shifts the argv array by one word 
• Ex) While( $#argv) 
echo $argv 
shift 
end 
%loop a b c 
a b c 
b c 
c
18 
CCsshheellll WWhhiillee 
break && continue command 
set answer = $< 
while( “$answer” !~ [Mm]* ) 
echo “Wrong! Try again.” 
set answer = $< 
if( “$answer” =~ [Mm]*) break; 
end
19 
PPrrooggrraammmmiinngg wwiitthh CC sshheellll 
mailingList 
– data 
• Hello XXX, 
– friends ( emails )
20 
RReessoouurrcceess 
Our sites 
 http://vibranttechnologies.co.in/ 
 http://vibrantgroupmumbai.blogspot.in/
Computer Science Lab 21

Contenu connexe

Tendances

Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbSmartTools
 
Cis 216 – shell scripting
Cis 216 – shell scriptingCis 216 – shell scripting
Cis 216 – shell scriptingDan Morrill
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingDan Morrill
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giantsIan Barber
 
Frege is a Haskell for the JVM
Frege is a Haskell for the JVMFrege is a Haskell for the JVM
Frege is a Haskell for the JVMjwausle
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionIan Barber
 
File-I/O -- ist doch ganz einfach, oder?
File-I/O -- ist doch ganz einfach, oder?File-I/O -- ist doch ganz einfach, oder?
File-I/O -- ist doch ganz einfach, oder?Christian Kauhaus
 
The hidden and new parts of JS
The hidden and new parts of JSThe hidden and new parts of JS
The hidden and new parts of JSRitesh Kumar
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesOXUS 20
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesAbdul Rahman Sherzad
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleIan Barber
 
Python and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunPython and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunJIHUN KIM
 

Tendances (20)

Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonbСтажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
 
Cis 216 – shell scripting
Cis 216 – shell scriptingCis 216 – shell scripting
Cis 216 – shell scripting
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scripting
 
Basics
BasicsBasics
Basics
 
Bash Scripting Workshop
Bash Scripting WorkshopBash Scripting Workshop
Bash Scripting Workshop
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
Frege is a Haskell for the JVM
Frege is a Haskell for the JVMFrege is a Haskell for the JVM
Frege is a Haskell for the JVM
 
TDDBC お題
TDDBC お題TDDBC お題
TDDBC お題
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
 
PubNative Tracker
PubNative TrackerPubNative Tracker
PubNative Tracker
 
File-I/O -- ist doch ganz einfach, oder?
File-I/O -- ist doch ganz einfach, oder?File-I/O -- ist doch ganz einfach, oder?
File-I/O -- ist doch ganz einfach, oder?
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
The hidden and new parts of JS
The hidden and new parts of JSThe hidden and new parts of JS
The hidden and new parts of JS
 
Unix 5 en
Unix 5 enUnix 5 en
Unix 5 en
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI Examples
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
C99
C99C99
C99
 
Python and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunPython and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihun
 

Similaire à Shell and perl scripting classes in mumbai

findextensions(2).py#!usrlocalbinpython3import sysim.docx
findextensions(2).py#!usrlocalbinpython3import sysim.docxfindextensions(2).py#!usrlocalbinpython3import sysim.docx
findextensions(2).py#!usrlocalbinpython3import sysim.docxAKHIL969626
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)GroovyPuzzlers
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaewout2
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Bash cheat sheet
Bash cheat sheetBash cheat sheet
Bash cheat sheetJogesh Rao
 
Some Examples in R- [Data Visualization--R graphics]
 Some Examples in R- [Data Visualization--R graphics] Some Examples in R- [Data Visualization--R graphics]
Some Examples in R- [Data Visualization--R graphics]Dr. Volkan OBAN
 
The Magnificent Seven
The Magnificent SevenThe Magnificent Seven
The Magnificent SevenMike Fogus
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingMuthu Vinayagam
 
Workshop on command line tools - day 1
Workshop on command line tools - day 1Workshop on command line tools - day 1
Workshop on command line tools - day 1Leandro Lima
 

Similaire à Shell and perl scripting classes in mumbai (20)

findextensions(2).py#!usrlocalbinpython3import sysim.docx
findextensions(2).py#!usrlocalbinpython3import sysim.docxfindextensions(2).py#!usrlocalbinpython3import sysim.docx
findextensions(2).py#!usrlocalbinpython3import sysim.docx
 
Perl6 one-liners
Perl6 one-linersPerl6 one-liners
Perl6 one-liners
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
Advanced Shell Scripting
Advanced Shell ScriptingAdvanced Shell Scripting
Advanced Shell Scripting
 
The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Linux cheat sheet
Linux cheat sheetLinux cheat sheet
Linux cheat sheet
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Bash cheat sheet
Bash cheat sheetBash cheat sheet
Bash cheat sheet
 
Bash cheat sheet
Bash cheat sheetBash cheat sheet
Bash cheat sheet
 
Some Examples in R- [Data Visualization--R graphics]
 Some Examples in R- [Data Visualization--R graphics] Some Examples in R- [Data Visualization--R graphics]
Some Examples in R- [Data Visualization--R graphics]
 
The Magnificent Seven
The Magnificent SevenThe Magnificent Seven
The Magnificent Seven
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Php functions
Php functionsPhp functions
Php functions
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
Pop3ck sh
Pop3ck shPop3ck sh
Pop3ck sh
 
Workshop on command line tools - day 1
Workshop on command line tools - day 1Workshop on command line tools - day 1
Workshop on command line tools - day 1
 

Plus de Vibrant Technologies & Computers

Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Vibrant Technologies & Computers
 

Plus de Vibrant Technologies & Computers (20)

Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
SQL- Introduction to SQL database
SQL- Introduction to SQL database SQL- Introduction to SQL database
SQL- Introduction to SQL database
 
ITIL - introduction to ITIL
ITIL - introduction to ITILITIL - introduction to ITIL
ITIL - introduction to ITIL
 
Salesforce - Introduction to Security & Access
Salesforce -  Introduction to Security & Access Salesforce -  Introduction to Security & Access
Salesforce - Introduction to Security & Access
 
Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
 
Data ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housingData ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housing
 
Salesforce - classification of cloud computing
Salesforce - classification of cloud computingSalesforce - classification of cloud computing
Salesforce - classification of cloud computing
 
Salesforce - cloud computing fundamental
Salesforce - cloud computing fundamentalSalesforce - cloud computing fundamental
Salesforce - cloud computing fundamental
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
 
SQL- Introduction to advanced sql concepts
SQL- Introduction to  advanced sql conceptsSQL- Introduction to  advanced sql concepts
SQL- Introduction to advanced sql concepts
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
SQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set OperationsSQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set Operations
 
Sas - Introduction to designing the data mart
Sas - Introduction to designing the data martSas - Introduction to designing the data mart
Sas - Introduction to designing the data mart
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
 
Teradata - Architecture of Teradata
Teradata - Architecture of TeradataTeradata - Architecture of Teradata
Teradata - Architecture of Teradata
 
Teradata - Restoring Data
Teradata - Restoring Data Teradata - Restoring Data
Teradata - Restoring Data
 

Dernier

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Dernier (20)

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Shell and perl scripting classes in mumbai

  • 2. 2 SShheellll SSccrriippttiinngg ((CC sshheellll)) by
  • 3. 3 CCoonntteennttss C shell – First Script – Getting User Input – Command Line Arguments – Conditionals and File Testing – Switch & Loops Programming with C Shell – mailingList Summary & Resources
  • 4. 4 CC SShheellll #! /bin/csh  set name = hello -> echo $name $array = ( element1 elemsnt2 ) $array[1] , $array[2]
  • 5. 5 CC SShheellll –– FFiirrsstt SSccrriipptt  ${LOGNAME} – Print user’s name  `unix command` – Enclosed in back quotes – Performed command substitution – Ex) `date`  uname –n – Display the machine name  ps –ef | grep “^ *$LOGNAME” – User’s processes are printed  chmond –u+x greetme
  • 6. 6 CC sshheellll GGeettttiinngg UUsseerr IInnppuutt $< – user input (std) without newline $array = ($name) – An array is created Arithmetic ( operators ): @ integer + , - , / , * , % , << , >> += , -=, *=, /=, ++, -- • Ex) @ sum = 4+6 – Space is required after @
  • 7. 7 CCsshheellll DDeebbuuggggiinngg ssccrriippttss Echo (-x) and Verbose (-v) – csh –x scriptname (command ) • Display each line after variable substitution and before execution – set echo , unset ( in the file )
  • 8. 8 c Cshell coommmmaanndd lliinnee aarrgguummeenntt $0 - The name of the script $1, $2, $3,..${10} – Parameters are referenced by number $* - All positional parameters $argv[1], $argv[2] – The first argument , second … $argv[*] or $argv – all arguments $#argv – The number of arguments (size) $argv[$#argv] – The last argument
  • 9. 9 Cshell Conditional ccoonnssttrruuccttss  == , != , <, > , >= , <= , !  =~ , !~ – String matches ex) $ans =~ [Yy]* || , && – Logical operator
  • 10. 10 CCsshheellll iiff eexxaammpplleess IIff(( eexxpprreessssiioonn )) tthheenn CCoommmmaanndd eellssee CCoommmmaanndd eennddiiff Ex) if ( $#argv != 1) then echo “$0 requires an argument” exit 1 endif
  • 11. 11 CCsshheellll iiff eexxpprreessssiioonn  set name = $< If( “$name” != “” ) then grep “$name” data file endif  If( $answer =~ [Yy]* ) then mail bob < message else mail jon < datafile endif  set x = 1 , y = 2, z = 3 If( (“$x” && “$y”) || ! “$z”) then echo TRUE  If( $#argv == 0 ) exit 1
  • 12. 12 CCsshheellll iiff ccoommmmaanndd  If { (command) } then command endif  If { ( who | grep $1 >& /dev/null ) } then echo $1 is logged on endif  startover: set grade = $< if( “$grade” < 0 || “$grade” > 100 ) then echo “Illegal grade” goto startover endif
  • 13. 13 CCsshheellll iiff ffiillee tteessttiinngg  if( ! –e $file ) : file exists  if( -d $file ) : a direcotry file  if( -f $file ) : a plain file  if( ! –z $file ) : zero length  if( -r $file && -w $file): readable and writable  if( -x $file ): executable
  • 14. 14 CCsshheellll SSwwiittcchh set color = $< sswwiittcchh ((“$color”)) ccaassee bl*:: echo I feel $color bbrreeaakkssww ddeeffaauulltt:: echo $color not one of them bbrreeaakkssww eennddssww
  • 15. 15 CCsshheellll ffoorr ffoorreeaacchh vvaarriiaabbllee ((wwoorrddlliisstt)) ccoommmmaannddss eenndd – foreach person ( bob sam sue fred) mail $person < letter end – foreach person (`cat maillist`) mail $person <<EOF Hi $person EOF end
  • 16. 16 CCsshheellll wwhhiillee  set num = 0 wwhhiillee ($num < 10 ) echo $num @ num++ eenndd  rreeppeeaattee takes two argument( number, command) – Ex) %repeate 3 echo hello hello hello hello
  • 17. 17 CCsshheellll WWhhiillee sshhiifftt command – Shifts the argv array by one word • Ex) While( $#argv) echo $argv shift end %loop a b c a b c b c c
  • 18. 18 CCsshheellll WWhhiillee break && continue command set answer = $< while( “$answer” !~ [Mm]* ) echo “Wrong! Try again.” set answer = $< if( “$answer” =~ [Mm]*) break; end
  • 19. 19 PPrrooggrraammmmiinngg wwiitthh CC sshheellll mailingList – data • Hello XXX, – friends ( emails )
  • 20. 20 RReessoouurrcceess Our sites  http://vibranttechnologies.co.in/  http://vibrantgroupmumbai.blogspot.in/

Notes de l'éditeur

  1. After the csh program starts, it is programmed to execute two files in the user’s directory: These files allow users to initialize their own environments.
  2. When you use environment variable, you must have variable name with $ and brace
  3. The string is broken up into a list of words and assigned to the variable , name. C shell supports integer arithmetic only.
  4. The C shell evaluates the expression, resulting in either a zero or nonzero numeric value.