如果我这样做:
touch {1,2,3}.txt
Run Code Online (Sandbox Code Playgroud)
我明白了
1.txt 2.txt 3.txt
Run Code Online (Sandbox Code Playgroud)
但如果我这样做
touch {"File 1", "File 2"}.txt
Run Code Online (Sandbox Code Playgroud)
我没有得到预期'File 1.txt' 'File 2.txt'
。在这种情况下,正确的方法是什么?
后面的空格会,
导致 shell 将表达式解析为两个单独的标记,而不是作为大括号扩展:
$ printf '%s\n' {"File 1", "File 2"}.txt
{File 1,
File 2}.txt
Run Code Online (Sandbox Code Playgroud)
您只需要删除空格:
$ printf '%s\n' {"File 1","File 2"}.txt
File 1.txt
File 2.txt
Run Code Online (Sandbox Code Playgroud)
所以
$ touch {"File 1","File 2"}.txt
$ ls
'File 1.txt' 'File 2.txt'
Run Code Online (Sandbox Code Playgroud)
更紧凑的是,您还可以使用touch "File "{1,2}.txt
或touch File\ {1,2}.txt
归档时间: |
|
查看次数: |
473 次 |
最近记录: |