Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
batnoob
- Posts: 56
- Joined: 19 Apr 2017 12:23
#1
Post
by batnoob » 25 Mar 2018 02:18
is it possible to do something like:
Code: Select all
set x=4
set equation="%x%*2"
set /a x=!equation!
echo x= %x%
and output
More simply, how would one go about letting the user input the operations to be performed on a variable?
(or is that possible?)
Thanks,
::BatNoob
'BatNoob
//BatNoob
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 25 Mar 2018 03:54
No need to expand a variable in a SET /A statement. The cmd.exe will do that internally.
Code: Select all
@echo off &setlocal
set /p "x=x: "
set /p "formula=formula: "
set /a "y=%formula%"
echo y=%y%
pause
Input
2 if you're prompted for x and
x*2 if you're prompted for the formula.
Steffen
-
Aacini
- Expert
- Posts: 1914
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#3
Post
by Aacini » 25 Mar 2018 10:29
@batnoob, perhaps you could be interested in
this thread...
Antonio
-
batnoob
- Posts: 56
- Joined: 19 Apr 2017 12:23
#4
Post
by batnoob » 25 Mar 2018 22:01
Thank you both, I thought it was simple, but I couldn't remember how to do it to save my life.