Undesired quotes when echoing variable input to hosts file
2 posts · Closed
The following statement
%PsExec_VAR -h \\%0 cmd /c echo 10.0.64.185 some_name.com >> \\%0\c$\Windows\System32\drivers\etc\hosts
posts the results in hosts file
10.0.64.185 some_name.com
%PsExec_VAR -h \\%0 cmd /c echo {Enter ip host info:10.0.64.185 some_name.com} >> \\%0\c$\Windows\System32\drivers\etc\hosts
causes undesired output quotes:
"10.0.64.185 some_name.com"
Any idea how to avoid those quotes? (Dequote - Remove Quotes from a string)
The quotes are added because there is a space, meaning the string has to be enquoted into a single parameter.
In your case there may be an easy workaround:
- Open Notepad and hit Tab. Then copy that tab character.
- Insert the copied tab between the strings like this:
... cmd /c echo 10.0.64.185[color=#FF0000]tab[/color]some_name.com >> ...
- The tab-separated string should be echoed unquoted and written to the file.
By the way, I don't quite understand why you are using psexec to execute the command remotely and then pass the same IP address in path. It looks like either of the following will also work:
cmd /c echo {Enter ip host info:10.0.64.185[color=#FF0000]tab[/color]some_name.com} >> \\%0\c$\Windows\System32\drivers\etc\hosts
or
%PsExec_VAR -h \\%0 cmd /c echo {Enter ip host info:10.0.64.185[color=#FF0000]tab[/color]some_name.com} >> C:\Windows\System32\drivers\etc\hosts