integer variables

14
Integer variables #!/bin/csh # sum of numbers from $argv[1] to $argv[2] set low = $argv[1] set high = $argv[2] set sum = 0 set current = $low while ( $current <= $high) @ sum += $current @ current++ end echo The sum of the numbers from $low to $high is $sum.

Upload: ahmed-odom

Post on 01-Jan-2016

9 views

Category:

Documents


0 download

DESCRIPTION

Integer variables. #!/bin/csh # sum of numbers from $argv[1] to $argv[2] set low = $argv[1] set high = $argv[2] set sum = 0 set current = $low while ( $current

TRANSCRIPT

Page 1: Integer variables

Integer variables#!/bin/csh

# sum of numbers from $argv[1] to $argv[2]

set low = $argv[1]set high = $argv[2]set sum = 0set current = $lowwhile ( $current <= $high) @ sum += $current @ current++endecho The sum of the numbers from $low to $high is $sum.

Page 2: Integer variables

Searching the File Tree: Find Command

General form

find filename…expression…

find ~ -name \*.awk –print

Searches the subtree rooted at home directory visiting each file and printing each file that ends in .awk

Page 3: Integer variables

Some important primary expressions

• -atime n

• -name filename

• -exec cmd (end of command must be punctuated by a space then \;)

• -newer file

• -print

(see pages 149-151 of text for more details)

Page 4: Integer variables

The different shells

Name # of internal Size of Complexity

of shell commands man pages

sh 32 44,000 1.0

csh 52 77,000 1.73

bash 50 127,000 2.86

zsh 73 133,000 3.00

ksh 43 141,000 3.18

tcsh 56 199,800 4.99

Page 5: Integer variables

The if Statement – Bourne Shell

if [ condition ]

then

commands

else

commands

fi

Page 6: Integer variables

Test condition operators – Bourne shell

String = stringString != stringValue –eq valueValue –ne valueValue –gt valueValue –ge valueValue –lt valueValue –le value

Page 7: Integer variables

Referencing arguments – Bourne shell

$0, $1, $2, … (same as csh)

$* (list of all the variable)

$# (number of variables)

Page 8: Integer variables

Bourne shell script#!/bin/sh

# lookup a person's phone number in the phone book

if [ $# -ne 1 ]then echo "\nusage:$0 name\n"else grep "$1" phone_bookfi

Page 9: Integer variables

The while Statement – Bourne Shell

while [ condition ]

do

commands

done

Page 10: Integer variables

Infinite Loop

while true

while :

Page 11: Integer variables

The for Statement – Bourne Shell

for variable in list

do

commands

done

Page 12: Integer variables

#!/bin/sh

for index in 1 2 3 4 5

do

echo $index

done

Page 14: Integer variables

File Types

1. Ordinary file – contains text, programs, or other data

2. Directory – contains names and addresses of other files

3. Special file – represents an I/O device4. Link – pointer to another file5. Socket – used for interprocess

communication