CST8177 - Linux II Shell programming, set and shift Todd Kelley kelleyt@algonquincollege.com CST8207 - Todd Kelley 1 .review scripting tools so far .set .shift 2 Today's Topics . * ^ $ [] [^] posix character classes regular expressions CST8177 - Todd Kelley 3 .exit status .test program .positional parameters .if statements .while loops scripting CST8177 - Todd Kelley 4 .building complex tests from simple tests .test1 -a test2 .both test1 and test2 must be true .test1 -o test2 .at least one must be true .! test1 .test1 must be false .(test1) .true if test1 is true combining tests together CST8177 - Todd Kelley 5 .set with arguments but no options sets the positional parameters to the arguments .$# is the number of arguments .$1 is the first arg .$2 is the second arg .$3 is the third arg .etc .$@ and $* are all args set CST8177 - Todd Kelley 6 .shift .moves all the arguments to the left .shift n moves all the arguments to the left by n .shift .$# is decreased by 1 .the pre-shift $1 is lost .$1 becomes what was in $2 .$2 becomes what was in $3 .$3 becomes what was in $4 .etc shift CST8177 - Todd Kelley 7 .Suppose you might qualify for a scholarship: .Those who qualify are: .eight feet tall, and ?? .born on the moon, and ?? .algonquin student and ?? .or in other words .eight feet tall && ?? .born on the moon && ?? .algonquin student && ?? .In which case do we need to find out what ?? is? && means "and" CST8177 - Todd Kelley 8 .As soon as we encounter "true", we can stop .You qualify for a $1000 rebate under the following conditions: .born on the moon, or ?? .algonquin student, or ?? .In the first case, we need to know what the exit status of the ?? is, we need to run the ?? command .In the second case, we can stop before running the ?? command || means "or", opposite of && CST8177 - Todd Kelley 9 .&& and || are used with commands that tend to get things done .to graduate, you .complete first year && complete second year .complete first year is a "command" that gets things done: you learn the first-year material .-a and -o are used in test, and don't do things, just affect the exit status of test .you are a rich canadian if .you are canadian -a you are rich .checking whether or not you're canadian doesn't get things done - but it does establish a truth value && and || versus -a and -o CST8177 - Todd Kelley 10