Board logo

标题: [文本处理] [已解决]批处理变量能不能保存多行文本? [打印本页]

作者: newswan    时间: 2020-7-16 11:49     标题: [已解决]批处理变量能不能保存多行文本?

本帖最后由 newswan 于 2020-7-17 00:14 编辑

请问,能不能让一个变量存储多行,或者把一个文件,里面有多行,保存到一个变量里
比如,这样输出多行
  1. (echo a & echo b & echo c) | more
复制代码
或者用sed命令
  1. (set _str_=a ,b ,c ,d)
  2. (echo %_str_%) | sed -r -e "s|,|\n|g"
复制代码
但windows里通常没有sed
作者: Batcher    时间: 2020-7-16 13:12

回复 1# newswan
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set CrLf=^
  4. set "str=bbs!CrLf!bathome!CrLf!net"
  5. echo,!str!
  6. pause
复制代码

作者: newswan    时间: 2020-7-16 15:14

echo hello & echo,world

set CrLf=^&echo,
set "str=hello%crlf%world"
echo %str%




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2