Solved

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

Posted on 2008-06-11
5
299 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
ID: 21763656
it moves %2 to %1,  %3 to %2,  %4 to %3,  etc
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 21763670
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
ID: 21763687
... 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
ID: 21763701
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
ID: 31466321
Tah very much!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I do this in Pyhton? 12 126
Scripted configuration of TightVNC with Start on boot 7 60
Run command in each subfolder using batch file 7 62
Import filename in batch 2 35
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

809 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