【问题标题】:Escaping 'echo' in batch files在批处理文件中转义“回声”
【发布时间】:2010-03-09 23:00:44
【问题描述】:
我正在尝试在 Windows 7 DOS shell 中动态创建一个 bash 命令文件:
:: inside the .BAT file ..
:: check we are in the right directory
echo pwd > command.txt
:: get the shell to echo its environment variables
:: !!!! How do I get around this ... ?
echo echo $PWD
我认为在第二个 echo 命令前加上 ^(插入符号)会起作用,但不行。解决办法是什么?
【问题讨论】:
标签:
bash
shell
command
dos
echo
【解决方案1】:
我刚试过
@echo 回声 %TMP%
返回的
回显 C:\Users\Spike\AppData\Local\Temp
我认为问题不在于回声,而在于 $PWD。 %% 是 $ 的 DOS。
【解决方案2】:
这适用于我在 Windows XP 上,
@echo off
:: inside the .BAT file ..
:: check we are in the right directory
echo pwd > command.txt
:: get the shell to echo its environment variables
:: !!!! How do I get around this ... ?
echo echo ^$PWD >>command.txt
输出
C:\test>test.bat
C:\test>more command.txt
pwd
echo $PWD