Solved

what does the keyword 'shift' mean when used in a batch script

Posted on 2008-06-11
5
297 Views
Last Modified: 2010-04-21
as the title suggests - what does the keyword 'shift' mean when used in a batch script
eg  if "%1" == "/i"         (set Install=1)   & shift & goto LParseArgs

(from install.bat)
0
Comment
Question by:millerthegorilla
  • 4
5 Comments
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
it moves %2 to %1,  %3 to %2,  %4 to %3,  etc
0
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
for example, save this script as test.bat and run it like this:  test.bat  abc  123  xyz  456   pdq   789


@echo off
  echo param1: %1,  param2: %2,  param3: %3,  param4: %4,  param5: %5,  param6: %6
  shift
  echo param1: %1,  param2: %2,  param3: %3,  param4: %4,  param5: %5,  param6: %6
  shift
  echo param1: %1,  param2: %2,  param3: %3,  param4: %4,  param5: %5,  param6: %6
  shift
  echo param1: %1,  param2: %2,  param3: %3,  param4: %4,  param5: %5,  param6: %6
  shift
  echo param1: %1,  param2: %2,  param3: %3,  param4: %4,  param5: %5,  param6: %6
  shift
  echo param1: %1,  param2: %2,  param3: %3,  param4: %4,  param5: %5,  param6: %6
  shift

0
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
... this allows you to have more than 9 parameters to the batch file and still work with them using %1-%9.
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
Comment Utility
From your example:

  eg  if "%1" == "/i"         (set Install=1)   & shift & goto LParseArgs

if the first parameter is /i then set a variable called Install to 1, then shift the batch parameters, then goto the LParseArgs label in the batch file.
0
 

Author Closing Comment

by:millerthegorilla
Comment Utility
Tah very much!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now