![]() |
|
[Shell] Escape characters in input? - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Shell] Escape characters in input? (/showthread.php?tid=4876810) |
Escape characters in input? - Advertisement - Jun 22, 2015 This could come useful in some of my scripts, on phone so ignore typos etc So take this code as example Code @echo offSay if you typed, &goto LA&ipconfig | findstr Connection So on, how do you automatically add like a ^| etc? * - Hackoo - Jun 22, 2015 Hi 🤝 Try something like that : Code @echo offOr more simple like this :You can take a look at setlocal EnableDelayedExpansion Code @echo offHope that what do you expecting for and of course this may be improved by other members here ! Good Luck for you ✌ * - annikk.exe - Jun 23, 2015 Hackoo is correct :> To further explain, we use string substitution to escape any reserved characters. Consider this simple example. Code set "var=Cats are best"Code Cats are bestOn the first line, we set a variable to contain the text Cats are best. On the second line, we echo that variable. On the third line, we echo the variable, but we replace any instances of "best" with "fluffy". So what actually comes out is "Cats are fluffy". So it's %var:A=B% Where A is the thing to be replaced, and B is the thing to replace it with. :> In this case, we use this technique to replace any instances of | with ^| :> |