SlideShare a Scribd company logo
1 of 50
C-shell Scripting
made by B Chari K working in semiconductors domain
Shell Scripts
The basic concept of a shell script is a list of
commands, which are listed in the order of
execution.
There are conditional tests, loops, variables
and files to read and store data.
A script can include functions also.
Steps to create Shell script
 Specify shell to execute program
 Script must begin with #! (pronounced “shebang”)
lto identify shell to be executed
Examples:
#! /bin/sh
#! /bin/bash
#! /bin/csh
#! /usr/bin/tcsh
 Make the shell program executable
 Use the “chmod” command to make the program/script file
executable
3
Example Script
Variables
 Local variables – a variable present with in
the current instance in the shell
 Environment variables – a variable
available to any child process of the shell.Usually
a shell script defines only those environment
variables that are needed by the programs that it
runs.
 Shell variables - A shell variable is a special
variable that is set by the shell and is required by
the shell in order to function correctly
Shell Logic Structures
 Basic logic structures needed for program
development:
 Sequential logic
 User input
 Decision logic
 Looping logic
 Case logic
Input to a shell script
 Reading user input
 Providing input as command line arguments
 Accessing contents of files
Reading User Input
 There is a special C shell variable:
$<
 Reads a line from terminal (stdin)
up to, but not including the new line
#! /bin/csh
echo "What is your name?"
set name = $<
echo Greetings to you, $name
echo "See you soon"
Reading User Input
Command Line arguments
 Use arguments to modify script behavior
 command line arguments become
positional parameters to C shell script
 positional parameters are numbered variables:
$1, $2, $3 …
Command line arguments
Meaning
$0 -- name of the script
$1, $2 -- first and second parameter
${10} -- 10th parameter
 { } prevents “$1” misunderstanding
$* -- all positional parameters
$#argv -- the number of arguments
Command Line arguments : Example
Decision Logic
 if Statement: simplest forms
if ( expression ) command
if ( expression ) then
command(s)
endif
 if-then-else Statement
if ( expression ) then
command(s)
else
command(s)
endif
Decision Logic
Decision Logic
 If-then-else if Statement
if ( expression ) then
command(s)
else if ( expression ) then
command(s)
else
command(s)
endif
Basic Operators in expressions
Meaning
( ) grouping
! Logical “not”
> >= < <=greater than, less than
== != equal to, not equal
|| Logical “or”
&& Logical “and”
Example
#! /bin/csh
if ( $#argv == 0 ) then
echo -n "Enter time in minutes: "
@ min = $<
else
@ min = $1
endif
@ sec = $min * 60
echo “$min minutes is $sec seconds”
Example
File Testing Operators
opr Meaning
r Read access
w Write access
x Execute access
e Existence
z Zero length
f Ordinary file
d directory
 Syntax: if ( -opre filename )
Example
if ( -e $1 ) then
echo $1 exists
if ( -f $1 ) then
echo $1 is an ordinary
file
else
echo $1 is NOT ordinary
file
endif
else
echo $1 does NOT exist
endif
Example : if-else
Looping constructs
predetermined iterations
- repeat
- foreach
condition-based iterations
- while
Fixed Number Iterations
Syntax: repeat
repeat number command
lexecutes “command” “number” times
Examples:
repeat 5 ls
repeat 2 echo “go home”
The Foreach Statement
foreach name ( wordlist )
commands
end
 wordlist is:
list of words, or
multi-valued variable
each time through,
foreach assigns the next item in
wordlist to the variable $name
Example : Foreach
foreach word ( one two three )
echo $word
end
lor
set list = ( one two three )
foreach word ( $list )
echo $word
end
Loops with Foreach
Example:
#! /bin/csh
@ sum = 0
foreach file (`ls`)
set size = `cat $file | wc -c`
echo "Counting: $file ($size)"
@ sum = $sum + $size
end
echo Sum: $sum
Example : Foreach
While Statement
while ( expression )
commands
end
use when the number of iterations is not
known in advance
execute ‘commands’ when the expression is
true
terminates when the expression becomes
false
Example : While
#! /bin/csh
@ var = 5
while ( $var > 0 )
echo $var
@ var = $var – 1
end
Loop Control
lbreak
ends loop, i.e. breaks out of current loop
lcontinue
ends current iteration of loop, continues with
next iteration
Example : Loop Control
#! /bin/csh
while (1)
echo -n "want more? "
set answer = $<
if ($answer == "y") echo "fine"
if ($answer == "n") break
if ($answer == "c") continue
echo "now we are at the end"
end
Example : Loop Control Example
The Switch Statement
lUse when a variable can take
different values
lUse switch statement to
process different cases (case
statement)
lCan replace a long sequence
of
if-then-else
statements
lUse when a variable can take
different values
lUse switch statement to
process different cases (case
statement)
lCan replace a long sequence
of
if-then-else
statements
Example:
switch (string)
case pattern1:
command(s)
breaksw
case pattern2:
command(s)
breaksw
default:
command(s)
breaksw
endsw
Example : Switch
switch ($var)
case one:
echo it is 1
breaksw
case two:
echo it is 2
breaksw
default:
echo it is $var
breaksw
endsw
Example : Switch
#! /bin/csh
# Usage: greeting name
# examines time of day for greeting
set hour=`date`
switch ($hour[4])
case 0*:
case 1[01]*:
set greeting=morning ; breaksw
case 1[2-7]*:
set greeting=afternoon ; breaksw
default:
set greeting=evening
endsw
echo Good $greeting $1
Example : Switch
Quoting Mechanism
 mechanism for marking a section of a
command for special processing:
 command substitution: `...`
 double quotes: “…“
 single quotes: ‘…‘
 backslash:
Double Quotes
 Prevents breakup of string into words
 Turn off the special meaning of most wildcard
characters and the single quote
 $ character keeps its meaning
 ! history references keeps its meaning
Examples:
echo "* isn't a wildcard inside quotes"
echo "my path is $PATH"
Single Quotes
lwildcards, variables and command substitutions are
all treated as ordinary text
lhistory references are recognized
Examples:
echo '*'
echo '$cwd'
echo '`echo hello`'
echo 'hi there !'
Back Slash
lbackslash character 
treats following character literally
Examples:
echo $ is a dollar sign
echo  is a backslash
Wild cards
 A wild card that can stand for all member s
of same class of characters
 The * wild card
ls list*
This will list all files starting with list
ls *list
This will list all files ending with list
The ? Wild card
ls ?ouse
This will match files like house, mouse, grouse
Regular Expressions
 Search for specific lines of text containing a
particular pattern
 Usually using for pattern matching
 A shell meta characters must be quoted when
passed as an expression to the shell
Anchor Characters : ^ and $
Regular Expression Matches
^A A at the begining of line
A$ A at the end of the line
^^ “^” at the beginning of line
$$ “$” at the end of the line
^.$ Matches any character with “.”
Example:
Grep '^from:' /home/shastra/Desktop/file2
Searches all the lines starting with pattern ‘from’
Matching words with [ and ]
Regular expression matches
[ ] The characters “[]”
[0-9] Any number
[^0-9] Any character other than a
number
[-0-9] Any number or a “-”
[]0-9] Any number or “]”
[0-9]] Any number followed by “]”
^[0-9] A line starting with any
number
[0-9]$ A line ending with any
number
Matching a specific number of sets with
{ and }
Regular expression matches
^AA*B Any line starts with one or
more A s followed by B
^{4,8}B Any line starting with 4,5,6,7 or
8 A s followed by B
^A{4,}B Any line starting with 4 or more
"A"'s
{4,8} Any line with "{4,8}"
A{4,8} Any line with "A{4,8}"
Matching exact words
Regular expression matches
<the> Matching individual word “the”
only
<[tT]he> Matches for both t and T followed
by he
Example : Regex
 grep "^abb" file1
 It matches the line that contains “abb” at the very
beginning of line
 grep "and$" file1
 It matches the line that contains “and” at the end
of the line
 grep “t[wo]o” file1
 It matches the line that contains “two” or “too”
Example : C shell Script
 #!/bin/csh
 echo This script would find
out the prime numbers from
given numbers
 echo Enter the numbers:
 set n = ($<)
 foreach num ($n)
 set i = 2
 set prime = 1
 while ( $i <= `expr $num / 2`
)
 if (`expr $num % $i` == 0)
 set prime = 0
 break
 endif
 @ i = $i + 1
 end
 if ($prime == 1) then
 echo $num is a prime numb
 else
 echo $num is not a prime
 endif
 end
Example : C shell Scirpt
 #!/bin/csh
 echo This script would 'find' the .txt files and
change their permissions
 set ar = `find / -name "*.txt"`
 set arr = ($ar[*])
 foreach a ($arr)
 chmod 777 $a
 ls -l $a
 end
T h a n k Y o u
made by B Chari K working in semiconductors domain

More Related Content

What's hot

UVM Driver sequencer handshaking
UVM Driver sequencer handshakingUVM Driver sequencer handshaking
UVM Driver sequencer handshakingHARINATH REDDY
 
The Verification Methodology Landscape
The Verification Methodology LandscapeThe Verification Methodology Landscape
The Verification Methodology LandscapeDVClub
 
Session 8 assertion_based_verification_and_interfaces
Session 8 assertion_based_verification_and_interfacesSession 8 assertion_based_verification_and_interfaces
Session 8 assertion_based_verification_and_interfacesNirav Desai
 
Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Kamal Acharya
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File SystemAdrian Huang
 
System verilog assertions (sva) ( pdf drive )
System verilog assertions (sva) ( pdf drive )System verilog assertions (sva) ( pdf drive )
System verilog assertions (sva) ( pdf drive )sivasubramanian manickam
 
APB protocol v1.0
APB protocol v1.0APB protocol v1.0
APB protocol v1.0Azad Mishra
 
Associative memory 14208
Associative memory 14208Associative memory 14208
Associative memory 14208Ameer Mehmood
 
Basic synthesis flow and commands in digital VLSI
Basic synthesis flow and commands in digital VLSIBasic synthesis flow and commands in digital VLSI
Basic synthesis flow and commands in digital VLSISurya Raj
 
Interfacing With High Level Programming Language
Interfacing With High Level Programming Language Interfacing With High Level Programming Language
Interfacing With High Level Programming Language .AIR UNIVERSITY ISLAMABAD
 
UVM Methodology Tutorial
UVM Methodology TutorialUVM Methodology Tutorial
UVM Methodology TutorialArrow Devices
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategiesDr. Loganathan R
 

What's hot (20)

UVM Driver sequencer handshaking
UVM Driver sequencer handshakingUVM Driver sequencer handshaking
UVM Driver sequencer handshaking
 
The Verification Methodology Landscape
The Verification Methodology LandscapeThe Verification Methodology Landscape
The Verification Methodology Landscape
 
axi protocol
axi protocolaxi protocol
axi protocol
 
Session 8 assertion_based_verification_and_interfaces
Session 8 assertion_based_verification_and_interfacesSession 8 assertion_based_verification_and_interfaces
Session 8 assertion_based_verification_and_interfaces
 
Cache memory
Cache memoryCache memory
Cache memory
 
Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
 
System verilog assertions (sva) ( pdf drive )
System verilog assertions (sva) ( pdf drive )System verilog assertions (sva) ( pdf drive )
System verilog assertions (sva) ( pdf drive )
 
Synthesis
SynthesisSynthesis
Synthesis
 
APB protocol v1.0
APB protocol v1.0APB protocol v1.0
APB protocol v1.0
 
cache memory
 cache memory cache memory
cache memory
 
Associative memory 14208
Associative memory 14208Associative memory 14208
Associative memory 14208
 
Basic synthesis flow and commands in digital VLSI
Basic synthesis flow and commands in digital VLSIBasic synthesis flow and commands in digital VLSI
Basic synthesis flow and commands in digital VLSI
 
Interfacing With High Level Programming Language
Interfacing With High Level Programming Language Interfacing With High Level Programming Language
Interfacing With High Level Programming Language
 
UVM Methodology Tutorial
UVM Methodology TutorialUVM Methodology Tutorial
UVM Methodology Tutorial
 
VLIW Processors
VLIW ProcessorsVLIW Processors
VLIW Processors
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
 
Cache memory
Cache  memoryCache  memory
Cache memory
 
Back end[1] debdeep
Back end[1]  debdeepBack end[1]  debdeep
Back end[1] debdeep
 
Interrupts and types of interrupts
Interrupts and types of interruptsInterrupts and types of interrupts
Interrupts and types of interrupts
 

Similar to First steps in C-Shell

Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell ScriptDr.Ravi
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1Dr.Ravi
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.pptmugeshmsd5
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Andrea Telatin
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell ScriptingRaghu nath
 
Shell Scripts
Shell ScriptsShell Scripts
Shell ScriptsDr.Ravi
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scriptingerbipulkumar
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP StringsAhmed Swilam
 
34-shell-programming.ppt
34-shell-programming.ppt34-shell-programming.ppt
34-shell-programming.pptKiranMantri
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on LinuxTushar B Kute
 
Unit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptUnit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptroot_fibo
 
What is the general format for a Try-Catch block Assume that amt l .docx
 What is the general format for a Try-Catch block  Assume that amt l .docx What is the general format for a Try-Catch block  Assume that amt l .docx
What is the general format for a Try-Catch block Assume that amt l .docxajoy21
 
Case, Loop & Command line args un Unix
Case, Loop & Command line args un UnixCase, Loop & Command line args un Unix
Case, Loop & Command line args un UnixVpmv
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 

Similar to First steps in C-Shell (20)

Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1
 
Shell programming
Shell programmingShell programming
Shell programming
 
390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Bash shell
Bash shellBash shell
Bash shell
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scripting
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
34-shell-programming.ppt
34-shell-programming.ppt34-shell-programming.ppt
34-shell-programming.ppt
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
 
Unit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptUnit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell script
 
What is the general format for a Try-Catch block Assume that amt l .docx
 What is the general format for a Try-Catch block  Assume that amt l .docx What is the general format for a Try-Catch block  Assume that amt l .docx
What is the general format for a Try-Catch block Assume that amt l .docx
 
First steps in PERL
First steps in PERLFirst steps in PERL
First steps in PERL
 
Unix
UnixUnix
Unix
 
Case, Loop & Command line args un Unix
Case, Loop & Command line args un UnixCase, Loop & Command line args un Unix
Case, Loop & Command line args un Unix
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Perl Basics with Examples
Perl Basics with ExamplesPerl Basics with Examples
Perl Basics with Examples
 

Recently uploaded

➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men 🔝Vijayawada🔝 E...
➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men  🔝Vijayawada🔝   E...➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men  🔝Vijayawada🔝   E...
➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men 🔝Vijayawada🔝 E...amitlee9823
 
Top Rated Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Call Girls in Nagpur High Profile
 
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证wpkuukw
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)amitlee9823
 
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...motiram463
 
➥🔝 7737669865 🔝▻ Deoghar Call-girls in Women Seeking Men 🔝Deoghar🔝 Escorts...
➥🔝 7737669865 🔝▻ Deoghar Call-girls in Women Seeking Men  🔝Deoghar🔝   Escorts...➥🔝 7737669865 🔝▻ Deoghar Call-girls in Women Seeking Men  🔝Deoghar🔝   Escorts...
➥🔝 7737669865 🔝▻ Deoghar Call-girls in Women Seeking Men 🔝Deoghar🔝 Escorts...amitlee9823
 
Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Pooja Nehwal
 
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...amitlee9823
 
Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...
Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...
Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...MOHANI PANDEY
 
Escorts Service Daryaganj - 9899900591 College Girls & Models 24/7
Escorts Service Daryaganj - 9899900591 College Girls & Models 24/7Escorts Service Daryaganj - 9899900591 College Girls & Models 24/7
Escorts Service Daryaganj - 9899900591 College Girls & Models 24/7shivanni mehta
 
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Naicy mandal
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In Yusuf Sarai ≼🔝 Delhi door step delevry≼🔝
Call Now ≽ 9953056974 ≼🔝 Call Girls In Yusuf Sarai ≼🔝 Delhi door step delevry≼🔝Call Now ≽ 9953056974 ≼🔝 Call Girls In Yusuf Sarai ≼🔝 Delhi door step delevry≼🔝
Call Now ≽ 9953056974 ≼🔝 Call Girls In Yusuf Sarai ≼🔝 Delhi door step delevry≼🔝9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证wpkuukw
 
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...amitlee9823
 
SM-N975F esquematico completo - reparación.pdf
SM-N975F esquematico completo - reparación.pdfSM-N975F esquematico completo - reparación.pdf
SM-N975F esquematico completo - reparación.pdfStefanoBiamonte1
 
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...drmarathore
 

Recently uploaded (20)

➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men 🔝Vijayawada🔝 E...
➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men  🔝Vijayawada🔝   E...➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men  🔝Vijayawada🔝   E...
➥🔝 7737669865 🔝▻ Vijayawada Call-girls in Women Seeking Men 🔝Vijayawada🔝 E...
 
Top Rated Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
(👉Ridhima)👉VIP Model Call Girls Mulund ( Mumbai) Call ON 9967824496 Starting ...
 
➥🔝 7737669865 🔝▻ Deoghar Call-girls in Women Seeking Men 🔝Deoghar🔝 Escorts...
➥🔝 7737669865 🔝▻ Deoghar Call-girls in Women Seeking Men  🔝Deoghar🔝   Escorts...➥🔝 7737669865 🔝▻ Deoghar Call-girls in Women Seeking Men  🔝Deoghar🔝   Escorts...
➥🔝 7737669865 🔝▻ Deoghar Call-girls in Women Seeking Men 🔝Deoghar🔝 Escorts...
 
Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006
 
CHEAP Call Girls in Mayapuri (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Mayapuri  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Mayapuri  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Mayapuri (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...
 
Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...
Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...
Get Premium Pimple Saudagar Call Girls (8005736733) 24x7 Rate 15999 with A/c ...
 
Escorts Service Daryaganj - 9899900591 College Girls & Models 24/7
Escorts Service Daryaganj - 9899900591 College Girls & Models 24/7Escorts Service Daryaganj - 9899900591 College Girls & Models 24/7
Escorts Service Daryaganj - 9899900591 College Girls & Models 24/7
 
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
Makarba ( Call Girls ) Ahmedabad ✔ 6297143586 ✔ Hot Model With Sexy Bhabi Rea...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In Yusuf Sarai ≼🔝 Delhi door step delevry≼🔝
Call Now ≽ 9953056974 ≼🔝 Call Girls In Yusuf Sarai ≼🔝 Delhi door step delevry≼🔝Call Now ≽ 9953056974 ≼🔝 Call Girls In Yusuf Sarai ≼🔝 Delhi door step delevry≼🔝
Call Now ≽ 9953056974 ≼🔝 Call Girls In Yusuf Sarai ≼🔝 Delhi door step delevry≼🔝
 
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
 
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
 
(INDIRA) Call Girl Napur Call Now 8617697112 Napur Escorts 24x7
(INDIRA) Call Girl Napur Call Now 8617697112 Napur Escorts 24x7(INDIRA) Call Girl Napur Call Now 8617697112 Napur Escorts 24x7
(INDIRA) Call Girl Napur Call Now 8617697112 Napur Escorts 24x7
 
SM-N975F esquematico completo - reparación.pdf
SM-N975F esquematico completo - reparación.pdfSM-N975F esquematico completo - reparación.pdf
SM-N975F esquematico completo - reparación.pdf
 
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
Abort pregnancy in research centre+966_505195917 abortion pills in Kuwait cyt...
 

First steps in C-Shell

  • 1. C-shell Scripting made by B Chari K working in semiconductors domain
  • 2. Shell Scripts The basic concept of a shell script is a list of commands, which are listed in the order of execution. There are conditional tests, loops, variables and files to read and store data. A script can include functions also.
  • 3. Steps to create Shell script  Specify shell to execute program  Script must begin with #! (pronounced “shebang”) lto identify shell to be executed Examples: #! /bin/sh #! /bin/bash #! /bin/csh #! /usr/bin/tcsh  Make the shell program executable  Use the “chmod” command to make the program/script file executable 3
  • 5. Variables  Local variables – a variable present with in the current instance in the shell  Environment variables – a variable available to any child process of the shell.Usually a shell script defines only those environment variables that are needed by the programs that it runs.  Shell variables - A shell variable is a special variable that is set by the shell and is required by the shell in order to function correctly
  • 6. Shell Logic Structures  Basic logic structures needed for program development:  Sequential logic  User input  Decision logic  Looping logic  Case logic
  • 7. Input to a shell script  Reading user input  Providing input as command line arguments  Accessing contents of files
  • 8. Reading User Input  There is a special C shell variable: $<  Reads a line from terminal (stdin) up to, but not including the new line #! /bin/csh echo "What is your name?" set name = $< echo Greetings to you, $name echo "See you soon"
  • 10. Command Line arguments  Use arguments to modify script behavior  command line arguments become positional parameters to C shell script  positional parameters are numbered variables: $1, $2, $3 …
  • 11. Command line arguments Meaning $0 -- name of the script $1, $2 -- first and second parameter ${10} -- 10th parameter  { } prevents “$1” misunderstanding $* -- all positional parameters $#argv -- the number of arguments
  • 13. Decision Logic  if Statement: simplest forms if ( expression ) command if ( expression ) then command(s) endif
  • 14.  if-then-else Statement if ( expression ) then command(s) else command(s) endif Decision Logic
  • 15. Decision Logic  If-then-else if Statement if ( expression ) then command(s) else if ( expression ) then command(s) else command(s) endif
  • 16. Basic Operators in expressions Meaning ( ) grouping ! Logical “not” > >= < <=greater than, less than == != equal to, not equal || Logical “or” && Logical “and”
  • 17. Example #! /bin/csh if ( $#argv == 0 ) then echo -n "Enter time in minutes: " @ min = $< else @ min = $1 endif @ sec = $min * 60 echo “$min minutes is $sec seconds”
  • 19. File Testing Operators opr Meaning r Read access w Write access x Execute access e Existence z Zero length f Ordinary file d directory  Syntax: if ( -opre filename )
  • 20. Example if ( -e $1 ) then echo $1 exists if ( -f $1 ) then echo $1 is an ordinary file else echo $1 is NOT ordinary file endif else echo $1 does NOT exist endif
  • 22. Looping constructs predetermined iterations - repeat - foreach condition-based iterations - while
  • 23. Fixed Number Iterations Syntax: repeat repeat number command lexecutes “command” “number” times Examples: repeat 5 ls repeat 2 echo “go home”
  • 24. The Foreach Statement foreach name ( wordlist ) commands end  wordlist is: list of words, or multi-valued variable each time through, foreach assigns the next item in wordlist to the variable $name
  • 25. Example : Foreach foreach word ( one two three ) echo $word end lor set list = ( one two three ) foreach word ( $list ) echo $word end
  • 26. Loops with Foreach Example: #! /bin/csh @ sum = 0 foreach file (`ls`) set size = `cat $file | wc -c` echo "Counting: $file ($size)" @ sum = $sum + $size end echo Sum: $sum
  • 28. While Statement while ( expression ) commands end use when the number of iterations is not known in advance execute ‘commands’ when the expression is true terminates when the expression becomes false
  • 29. Example : While #! /bin/csh @ var = 5 while ( $var > 0 ) echo $var @ var = $var – 1 end
  • 30. Loop Control lbreak ends loop, i.e. breaks out of current loop lcontinue ends current iteration of loop, continues with next iteration
  • 31. Example : Loop Control #! /bin/csh while (1) echo -n "want more? " set answer = $< if ($answer == "y") echo "fine" if ($answer == "n") break if ($answer == "c") continue echo "now we are at the end" end
  • 32. Example : Loop Control Example
  • 33. The Switch Statement lUse when a variable can take different values lUse switch statement to process different cases (case statement) lCan replace a long sequence of if-then-else statements lUse when a variable can take different values lUse switch statement to process different cases (case statement) lCan replace a long sequence of if-then-else statements Example: switch (string) case pattern1: command(s) breaksw case pattern2: command(s) breaksw default: command(s) breaksw endsw
  • 34. Example : Switch switch ($var) case one: echo it is 1 breaksw case two: echo it is 2 breaksw default: echo it is $var breaksw endsw
  • 35. Example : Switch #! /bin/csh # Usage: greeting name # examines time of day for greeting set hour=`date` switch ($hour[4]) case 0*: case 1[01]*: set greeting=morning ; breaksw case 1[2-7]*: set greeting=afternoon ; breaksw default: set greeting=evening endsw echo Good $greeting $1
  • 37. Quoting Mechanism  mechanism for marking a section of a command for special processing:  command substitution: `...`  double quotes: “…“  single quotes: ‘…‘  backslash:
  • 38. Double Quotes  Prevents breakup of string into words  Turn off the special meaning of most wildcard characters and the single quote  $ character keeps its meaning  ! history references keeps its meaning Examples: echo "* isn't a wildcard inside quotes" echo "my path is $PATH"
  • 39. Single Quotes lwildcards, variables and command substitutions are all treated as ordinary text lhistory references are recognized Examples: echo '*' echo '$cwd' echo '`echo hello`' echo 'hi there !'
  • 40. Back Slash lbackslash character treats following character literally Examples: echo $ is a dollar sign echo is a backslash
  • 41. Wild cards  A wild card that can stand for all member s of same class of characters  The * wild card ls list* This will list all files starting with list ls *list This will list all files ending with list The ? Wild card ls ?ouse This will match files like house, mouse, grouse
  • 42. Regular Expressions  Search for specific lines of text containing a particular pattern  Usually using for pattern matching  A shell meta characters must be quoted when passed as an expression to the shell
  • 43. Anchor Characters : ^ and $ Regular Expression Matches ^A A at the begining of line A$ A at the end of the line ^^ “^” at the beginning of line $$ “$” at the end of the line ^.$ Matches any character with “.” Example: Grep '^from:' /home/shastra/Desktop/file2 Searches all the lines starting with pattern ‘from’
  • 44. Matching words with [ and ] Regular expression matches [ ] The characters “[]” [0-9] Any number [^0-9] Any character other than a number [-0-9] Any number or a “-” []0-9] Any number or “]” [0-9]] Any number followed by “]” ^[0-9] A line starting with any number [0-9]$ A line ending with any number
  • 45. Matching a specific number of sets with { and } Regular expression matches ^AA*B Any line starts with one or more A s followed by B ^{4,8}B Any line starting with 4,5,6,7 or 8 A s followed by B ^A{4,}B Any line starting with 4 or more "A"'s {4,8} Any line with "{4,8}" A{4,8} Any line with "A{4,8}"
  • 46. Matching exact words Regular expression matches <the> Matching individual word “the” only <[tT]he> Matches for both t and T followed by he
  • 47. Example : Regex  grep "^abb" file1  It matches the line that contains “abb” at the very beginning of line  grep "and$" file1  It matches the line that contains “and” at the end of the line  grep “t[wo]o” file1  It matches the line that contains “two” or “too”
  • 48. Example : C shell Script  #!/bin/csh  echo This script would find out the prime numbers from given numbers  echo Enter the numbers:  set n = ($<)  foreach num ($n)  set i = 2  set prime = 1  while ( $i <= `expr $num / 2` )  if (`expr $num % $i` == 0)  set prime = 0  break  endif  @ i = $i + 1  end  if ($prime == 1) then  echo $num is a prime numb  else  echo $num is not a prime  endif  end
  • 49. Example : C shell Scirpt  #!/bin/csh  echo This script would 'find' the .txt files and change their permissions  set ar = `find / -name "*.txt"`  set arr = ($ar[*])  foreach a ($arr)  chmod 777 $a  ls -l $a  end
  • 50. T h a n k Y o u made by B Chari K working in semiconductors domain