Question about ^ and !
Moderator: DosItHelp
Question about ^ and !
Hi All;
I want to ask about the ^ and the ! used in batch file coding:
i need to understand their usage in general,but the below are just examples:
Exmples:
1-
FOR /F "tokens=* delims==" %%A IN ('SET "" ˆ| FINDSTR.EXE /B "="') DO @ECHO.%%A
2-
set str=15 Trailing Spaces to truncate &rem
echo."%str%"
for /l %%a in (1,1,31) do if "!str:~-1!"==" " set str=!str:~0,-1!
echo."%str%"
3-
set LF=^
and what is the difference when we use %var:~x,y% and using !var:~x! ?
I didn't use them (^ ,!) before.
Thank you.
I want to ask about the ^ and the ! used in batch file coding:
i need to understand their usage in general,but the below are just examples:
Exmples:
1-
FOR /F "tokens=* delims==" %%A IN ('SET "" ˆ| FINDSTR.EXE /B "="') DO @ECHO.%%A
2-
set str=15 Trailing Spaces to truncate &rem
echo."%str%"
for /l %%a in (1,1,31) do if "!str:~-1!"==" " set str=!str:~0,-1!
echo."%str%"
3-
set LF=^
and what is the difference when we use %var:~x,y% and using !var:~x! ?
I didn't use them (^ ,!) before.
Thank you.
Re: Question about ^ and !
Many questions, well here we go then:
line continuation:
This is just one of many things you can do with ^, you really need to learn it if you want to do some serious programming.
http://www.dostips.com/forum/viewtopic.php?f=3&t=1855&p=7966&hilit=linefeed#p7966
http://www.dostips.com/forum/viewtopic.php?f=3&t=1842&p=7503&hilit=linefeed#p7503
for the set questions: enter this inside terminal
set /?
Try this it will make you an intermediate in notime, you'll then be able to solve most problems yourself.
MS-DOS/MSDOS Batch Files: Batch File Tutorial and Reference
www.^
allenware.com/icsw/icswidx.htm
And also www.^
dostips.com
Looks funny, yes we can only place 2 links per post.
line continuation:
Code: Select all
echo.hel^
lo
pause
exit /b
This is just one of many things you can do with ^, you really need to learn it if you want to do some serious programming.
http://www.dostips.com/forum/viewtopic.php?f=3&t=1855&p=7966&hilit=linefeed#p7966
http://www.dostips.com/forum/viewtopic.php?f=3&t=1842&p=7503&hilit=linefeed#p7503
for the set questions: enter this inside terminal
set /?
Try this it will make you an intermediate in notime, you'll then be able to solve most problems yourself.
MS-DOS/MSDOS Batch Files: Batch File Tutorial and Reference
www.^
allenware.com/icsw/icswidx.htm
And also www.^
dostips.com
Looks funny, yes we can only place 2 links per post.
Last edited by Ed Dyreen on 06 Jun 2011 01:05, edited 11 times in total.
Re: Question about ^ and !
I think by "!"'s are you talking about, what are they called, like delayed expanding variables or something?
Basically, just write
at the top and then instead of
you now have
They work a little differently, I don't really get exactly but basically if one variable doesn't define correctly you use this kind.
Such as when I tried
The variable wasn't working correctly so I changed it to the other one:
If you want to know what that script does, go here.
Basically, just write
Code: Select all
setlocal enableDelayedExpansion
at the top and then instead of
Code: Select all
%variable%
you now have
Code: Select all
!variable!
They work a little differently, I don't really get exactly but basically if one variable doesn't define correctly you use this kind.
Such as when I tried
Code: Select all
@echo off
for /f %%a in (total.txt) do (
set text=%%a
set /a total+=%text:~6,10%
)
echo %total%
pause
The variable wasn't working correctly so I changed it to the other one:
Code: Select all
@echo off
setlocal enableDelayedExpansion
for /f %%a in (total.txt) do (
set text=%%a
set /a total+=!text:~6,10!
)
echo %total%
pause
If you want to know what that script does, go here.
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Re: Question about ^ and !
Cleptography wrote:http://ss64.com/nt/setlocal.html
Well nobody likes to read all that.
If the did then they'd just use set /?.
:D
-
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
- Contact:
Re: Question about ^ and !
I know nitt just stating the obvious, I just don't understand why people don't dig a little before asking questions especially very easy to find answers, I don't understand, there is a difference between I searched for hours and hours now I will consult and expert and then just laziness.
I mean come on you have an entire internet at your finger tips you can find anything it is there just look or at least learn how to properly use your search engine, google is your friend.
intext:"Some Shit I am looking to Find in the Text"
inurl:"Find My words in the url"
intitle:"Find what I need In the Title of the search"
intext:"Find this is the text minus these files out" -php -htm -mp3 -mp4
I mean come on you have an entire internet at your finger tips you can find anything it is there just look or at least learn how to properly use your search engine, google is your friend.
intext:"Some Shit I am looking to Find in the Text"
inurl:"Find My words in the url"
intitle:"Find what I need In the Title of the search"
intext:"Find this is the text minus these files out" -php -htm -mp3 -mp4
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Question about ^ and !
Short description of !: works like you would expect variables to work.
It's the %% form that's odd. It expands during interpretation and not execution, so it makes the variable's contents static (which is what causes static behaviour within parentheses, as it's pre-expanded within a process that changes it's contents dynamically). It's really not that hard to understand.
It's the %% form that's odd. It expands during interpretation and not execution, so it makes the variable's contents static (which is what causes static behaviour within parentheses, as it's pre-expanded within a process that changes it's contents dynamically). It's really not that hard to understand.
Re: Question about ^ and !
orange_batch wrote:Short description of !: works like you would expect variables to work.
It's the %% form that's odd. It expands during interpretation and not execution, so it makes the variable's contents static (which is what causes static behaviour within parentheses, as it's pre-expanded within a process that changes it's contents dynamically). It's really not that hard to understand.
Oh. Well I've never used these until I came here and that was only that one time. :/