H:\>set x=1xxx1 H:\>echo %x% 1xxx1 H:\>for /f "tokens=*" %a in (' "echo %x% | find "xxx" " ') do set var=%a H:\>set var=1xxx1 <--- the script output this, because ECHO is on H:\>echo %var% 1xxx1