L12-The shift command

L12-The shift command - there are no more parameters to...

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

View Full Document Right Arrow Icon
Looping Lab – 50 points: The shift command The shift command is used to shift positional parameters from right to left so as to scroll through all the positional parameters that have been entered. Example: Result: After each time the shift command is executed the value that was associated with positional parameter %2 gets shifted to %1 . This shifting process allows us to process as many positional parameters as needed. Even though the shell can only recognize %0 through %9, by executing multiple shift commands we can continue to process past that limit indefinitely. @echo off rem ******************************************* rem * rem * testShift parm1 parm2 parm3 rem * set number=%1 echo The value of number is %number% shift set number=%1 echo The value of number is %number% shift set number=%1 echo The value of number is %number% echo on
Background image of page 1

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

View Full DocumentRight Arrow Icon
Looping Lab – 50 points: The shift command Using IF DEFINED When processing multiple positional parameters we need a technique to determine when
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: there are no more parameters to process. To do that we use the if defined or if not defined conditional command. Consider the following script: @echo off rem ********************************************************* rem * rem * testDefinedLoop pos1 pos2 . ... posn rem * rem ********************************************************* set /a count = 0 :testLoop set value=%1 if defined value ( set /a count += 1 & echo value = %value% ) else ( goto end ) shift goto testLoop :end echo There were %count% values entered echo on Looping Lab 50 points: The shift command Write a script called calcSum that will calculate the sum of an unlimited number of integers on the command line and upload it to the calcSum dropbox. Hint: You will have to use the shift command in conjunction with a goto loop . For example: The user might enter something like the following on the command line: calcSum 45 123 88 12 90 Your output would be: Result is 358...
View Full Document

Page1 / 3

L12-The shift command - there are no more parameters to...

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

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