Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-06-11
5
Medium Priority
?
305 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 2000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …
Suggested Courses

885 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