Shell and perl scripting classes in mumbai
best Shell and perl scripting classes in mumbai with job assistance.
our features are:
expert guidance by it industry professionals
lowest fees of 5000
practical exposure to handle projects
well equiped lab
after course resume writing guidance
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
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
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
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
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.
When you use environment variable, you must have variable name with $ and brace
The string is broken up into a list of words and assigned to the variable , name.
C shell supports integer arithmetic only.
The C shell evaluates the expression, resulting in either a zero or nonzero numeric value.