Solved

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

Posted on 2008-06-11
5
302 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Logon script fails 23 71
Powershell Exchange mailboxsizes 3 58
Editing a .bat file to point to a different directory 5 56
Powershell - Setting GPO 8 50
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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 look for a specific file type in a local or remote server directory using PHP.

710 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