批处理之家's Archiver

netdzb 发表于 2019-7-30 10:33

这个shell脚本在干什么

$ ls *.txt -1 | sed -e s/.exe/\&\!/g
                -1                            ~~~
这两个地方没看懂,谢谢。

Batcher 发表于 2019-7-30 14:40

ls 默认每行显示多个文件,ls -1 表示每行只显示一个文件:

# ls *.txt
1.exe.2.exe.txt  1.exe.txt  1.txt

# ls *.txt -1
1.exe.2.exe.txt
1.exe.txt
1.txt

后面的 sed 替换是在exe后面加了个感叹号:
# ls *.txt -1 | sed -e s/.exe/\&\!/g
1.exe!.2.exe!.txt
1.exe!.txt
1.txt

对于ls后面跟着管道的情况,-1参数是多余的,有没有无所谓。

netdzb 发表于 2019-7-30 16:18

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=222326&ptid=53488]2#[/url] [i]Batcher[/i] [/b]

后面加了个感叹号:
\&\!

前面的符号表示增加的意思吗?

Batcher 发表于 2019-7-30 19:53

[b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=222333&ptid=53488]3#[/url] [i]netdzb[/i] [/b]


[url]http://www.gnu.org/software/sed/manual/sed.html#The-_0022s_0022-Command[/url]
The replacement can contain \n (n being a number from 1 to 9, inclusive) references, which refer to the portion of the match which is contained between the nth \( and its matching \). [color=Red]Also, the replacement can contain unescaped & characters which reference the whole matched portion of the pattern space.[/color]

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.