• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

! in DOS command

Hi, what is the meaning of "!" here?
set x =  100000
set x = !x:0,4!

Open in new window

Is there a link?

Thanks.
0
zhshqzyc
Asked:
zhshqzyc
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
When SetLocal EnableDelayedExpansion is on, that acts similar to % as in assigning a variable a value.

See:
http://ss64.com/nt/setlocal.html
0
 
zhshqzycAuthor Commented:
Then what is
x:0,4

Open in new window

0
 
Bill PrewCommented:
To expand a bit further.

set x =  100000

This will set a variable named x with a value of 100000 (as a string).  I should note though that the extra spaces around the = sign will be a problem, and it should be:

set x=100000

Okay, then this line:

set x = !x:0,4!

will get the current value of x (that the right side reference to !x! and also use substring capability in the SET command (see SET /? at a command prompt for more info) to return only the left 4 characters.  The 0 says start at the left most character (it's relative to 0), and the 4 is the number of characters to get.  This is like a Mid() or Substr() in some other languages.

so this command will get the left 4 characters of the current value in x, and assign it to x.  Same isse with spaces around the = sign as above, so it needs to be:

set x=!x:0,4!

~bp
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
zhshqzycAuthor Commented:
Okay. It's a dos substring manipulation. Why I can't found it in microsoft web site?
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Probably because Microsoft is HUGE and has hundreds if not thousands of different programming teams and web hosting teams and other teams... coordinating where everything is a MONSTER task and things get lost and / or buried.  That's in part why Google is your friend.
0
 
zhshqzycAuthor Commented:
Okay. Thank you very much. Points are given. If you find it in offical miscrosoft web, just please post it. :)

0
 
Bill PrewCommented:
Not a Microsoft write up (I couldn't find the substring part of the SET there easily), but a great reference:

http://www.robvanderwoude.com/ntset.php

~bp
0
 
Steve KnightIT ConsultancyCommented:
well you will find this sort of stuff it in the help of

set /?
For /?
Setlocal /?
Etc.

Which are actually quite good.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now