windows – 带双引号的批处理文件多行命令
发布时间:2020-12-14 01:44:13 所属栏目:Windows 来源:网络整理
导读:使用^符号输入带有参数的多行命令时使用双引号来使用带空格的字符串^符号也会被传递,有人可以解释这是什么方式吗? working.cmd @echo off call openfiles.cmd ^C:dirfilename.txt ^C:another_diranother_file.txt notworking.cmd @echo off call openfi
使用^符号输入带有参数的多行命令时使用双引号来使用带空格的字符串^符号也会被传递,有人可以解释这是什么方式吗?
working.cmd @echo off call openfiles.cmd ^ C:dirfilename.txt ^ C:another_diranother_file.txt notworking.cmd @echo off call openfiles.cmd ^ "C:dir with spacesfile with spaces.txt" ^ "C:another dir with spacesanother file with spaces.txt" openfiles.cmd看起来像 @echo off for %%x in (%*) do ( IF EXIST %%x ( call "c:Program FilesNotepad++notepad++.exe" %%x ) ELSE ( call echo Not found %%x ) ) pause 我得到的错误 C:&;call openfiles.cmd "C:dir with spacesfile with spaces.txt" ^ ELSE was unexpected at this time.
问题是,第二行开头的引号将被多行插入符号转义.
因此,行中的最后一个引号开始引用而不是停止引用,因此第二行中的插入符号作为普通字符处理. call openfiles.cmd ^"C:dir with spacesfile with spaces.txt" ^ **This is a seperate line** "C:another dir with spacesanother file with spaces.txt" 插入符号规则: 插入符号逃脱了下一个角色,因此角色会失去所有特效. 通过这个简单的规则,你可以解释像 echo #1 Cat^&Dog echo #2 Cat^ &Dog echo #3 Redirect to > Cat^ Dog setlocal EnableDelayedExpansion set linefeed=^ echo #4 line1!linefeed!line2 #3创建了一个名为“Cat Dog”的文件,因为空间已被转义,不再作为分隔符. 但它仍有可能打破这个规则! echo #5 Line1< nul ^ & echo Line2 所以你也可以使用它来构建你的多线命令 call openfiles.cmd < nul ^ "C:dir with spacesfile with spaces.txt" < nul ^ "C:another dir with spacesanother file with spaces.txt" 或者使用宏 set "n=< nul ^" call openfiles.cmd %n% "C:dir with spacesfile with spaces.txt" %n% "C:another dir with spacesanother file with spaces.txt" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读