In a batch file, is there any way to get the raw arguments or command? For example, given the following batch file:
echo "%1"
And then running:
my-file.bat ^1.1
I would like it to output ^1.1, but ^ is a special character—escape character—so it is evaluated and %1 contains 1.1.
It is possible to fix this by escaping the caret when inputting the command (ex. my-file.bat ^^1.1), but this is not desired in my situation as I'm building a cross platform tool that also has a shell implementation (where providing ^1.1 works).
So I am wondering either:
- Is there a way to get the raw unevaluated argument text of "^1.1"?
- Or is there a way to get the raw command string or perhaps the last executed command text? I could then take this and do my own parsing.
Thanks!
%1? Also I doubt very much that you intention is to reallyechoit, so what are you doing with that input argument?echo "%1"is in the batch file as an example. It's calling it in cmd likemy-file.bat ^1.1. I want to get^1.1with the caret in the batch file somehow, but%1contains1.1instead of^1.1. I realize that's because^is an escape character.cmd.exewindow open, with the directory ofmy-file.batas your current directory, and you're physically typingmy-file.bat ^1.1and pressing the[ENTER]key? Also I asked what you're intending to do with the input argument. I ask because you've just typed it, so should already know what you typed. You must be performing some other task with it!my-file.batis a file in the current directory of acmd.exewindow that contains the textecho "%1". I am typingmy-file.bat ^1.1and pressing enter. The output is1.1, but my desired output is^1.1. Yes, I've just reduced the problem to a very simple example for the sake of this question. I'd like the input of^1.1stored in a variable in batch somehow then I will do other stuff with it.echo, the best way to attack this would be as part of that, not by just sticking a non requiredechoin there and hoping to get an answer which fulfills the true aim of your script.