Board logo

标题: 能否一个echo 多行输出? [打印本页]

作者: junyee     时间: 2007-11-26 10:36    标题: 能否一个echo 多行输出?

echo 1》test.txt
echo 2>> test.txt
echo 3>> test.txt


能否把上面的精简下。。要求只使用一个echo,能办到吗?
怀疑
echo (
1
2
3
)>test.txt
可是不行。。。
作者: fastslz     时间: 2007-11-26 11:13
下面代码另存为echo2.cmd
@echo off
:start_echo
set start_echo=%1
if not defined start_echo goto end
echo %1
shift
goto start_echo
:end
在执行
echo2 abc def ghi
或者echo2 abc def ghi>test.txt
作者: junyee     时间: 2007-11-26 11:27
感谢楼上的热心,可惜不是我想要的结果~

这个也能实现
@echo off
set /p input=
for %%a in (%input%) do echo %%a>>test.txt


我就想问一下,echo是否存在这样的功能,一个命令输出多行
另:好少见shift的应用。。。

[ Last edited by junyee on 2007-11-26 at 11:28 AM ]
作者: fastslz     时间: 2007-11-26 11:35
不依赖echo2.cmd,除了for没有其他办法
echo2.cmd比你这个用起来放便呀
echo2 第1行内容 (空格)第2行内容 (空格)第3行内容.....
作者: lxmxn     时间: 2007-11-26 12:19
E:\Cmd>type xecho.bat
@echo this is the first line for echo^

this is the second line^

the end
E:\Cmd>xecho.bat
this is the first line for echo
this is the second line
the end

E:\Cmd>

作者: ldd600     时间: 2007-11-26 18:58
楼上的厉害啊,
原来行尾加个 ^ ,下面再空一行就可以了。
试过了还不错。
作者: HAT     时间: 2007-11-27 01:23
lxmxn斑竹能否解释下原理?
作者: scriptor     时间: 2007-11-27 01:46
^出现第一次时候表示 转义后面的字符
作者: vkill     时间: 2007-12-22 20:57
下一行也算后面的字符?
作者: wuxj     时间: 2007-12-23 02:34
版主就是版主,的确厉害
作者: zyz0304360     时间: 2008-1-15 13:11
学习
作者: kidzgy     时间: 2008-1-15 18:54
版主,如果多行中间需要用空格空的呢?怎么办?
作者: tempuser     时间: 2008-1-16 17:07    标题: 没有换行呀

echo2 123 456 789
没有实现
123
456
789
显示效果呀!
作者: lxmxn     时间: 2008-1-18 01:22


  Quote:
Originally posted by kidzgy at 2008-1-15 18:54:
版主,如果多行中间需要用空格空的呢?怎么办?

B:\PERL>type xecho.bat
@echo one^

^

^

the end^
    goodbye
B:\PERL>xecho.bat
one


the end    goodbye

B:\PERL>

作者: shi1035     时间: 2008-1-18 09:29

作者: suntb     时间: 2008-1-27 21:21
今天发现这个^加上echo真好用

再学习下新用法
作者: f319     时间: 2009-12-20 13:55
@echo 1^

2^

3^

>test.txt

可以看下这个运行后test.txt里面显示的结果,  用记事本打开和用edit打开看到的不一样, 看来记事本对于换行的处理和其他编辑器的不同.
作者: radem     时间: 2009-12-21 21:35
又一个挖坟者
真有宝啊
作者: keen     时间: 2009-12-22 23:36
test.bat:
@echo 123^

456^

789
在CMD下使用:
test | more >temp.txt