Solved

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

Posted on 2008-06-11
5
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

627 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