Richard Parmiter

Virtualisation blog and Knowledge Base

  • You are here: 
  • Home
  • Script variable trimming

Script variable trimming

Posted on May 8th, 2009

Suppose you are trying to run some scripts based on a command line variable, but the variable being passed to it is surrounded by quote marks.

i.e. “device_name” when all i want is device_name

There is an easy way to trim this. In the script need to set this passed variable to a seperate variable, and then trim it byt doing the following:

SET tempvariable=%1                 (need to set %%1 if its run as a script file)

echo %1                                      (will show “device_name”)

echo %tempvariable%                 (will show “device_name”)

echo %tempvariable:~1,-1%       (will show device_name)

The trimmed variable can then be used for another task, i.e. to start a service on a remote server

sc \\%tempvariable:~1,-1% start “ServiceName”

Happy trimming!

  • Digg
  • StumbleUpon
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Add to favorites
  • FriendFeed
  • Google Buzz
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • RSS

Tags: , , , , , , , , , , ,
Filed under Scripts/Reg |

One Response to “Script variable trimming”

  1. protect downloads Says:
    August 22nd, 2009 at 9:44 pm

    Hi, would you mind teaching me more through PM?

Leave a Reply