Lecture7

Lecture7 - Lecture 7 Shell Programming Control Constructs...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 7 Shell Programming – Control Constructs COP 3344 Introduction to UNIX 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Command Line Arguments Cont. • $# contains the number of command line arguments. • $@ will be replaced by a string containing the command line arguments • Example script echo.sh #!/bin/sh echo “The” $# “arguments entered:” $@ •U s a g e : echo.sh alpha beta gamma • Output: The 3 arguments entered: alpha beta gamma 2
Background image of page 2
Testing Conditions • There are two ways to test for conditions. The o general forms are: two general forms are: test <condition> or [ <condition> ] • The latter method is easier to read. Remember to l d b f d f t t h b k t include a space before and after the bracket • A condition can be reversed with a ! before the ndition (this is the same as not condition) condition (this is the same as not condition) [ !<condition> ] • A ‘:’ command in place of condition always 3 returns true
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Testing File Attributes • To test if a file is readable - prog.txt ] [ r prog.txt ] [ -r $1.c ] • To test if a file is writeable [ -w specialfile.txt ] • To test if a file is executable [ -x prog4.sh ] • To test if a file exists [ -f temp.text ] • Testing for the negation - use ! (eg. not writeable) 4 [ ! -w nochange.txt ]
Background image of page 4
Numeric Tests • The following operators can be used for numeric sts: tests: { -eq, -ne, -gt, -ge, -lt, -le } xamples • Examples [ $1 –lt $2 ] $1 t 0 ] [ $1 gt 0 ] [ $# -eq 2 ] [ $# -lt 3 ] 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

Lecture7 - Lecture 7 Shell Programming Control Constructs...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online