命令行中的文件名或目录名若包含"#"号,别忘了添加转义

1
2
3
4
5
$ mkdir c#
zsh: no matches found: c#

$ cd ./c#
zsh: no matches found: ./c#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$ mkdir c#
zsh: no matches found: c#

# ganzhixiong @ ganzhixiongdeMacBook-Pro-3 in ~/temp [16:34:21] C:1
$ mkdir c\#

# ganzhixiong @ ganzhixiongdeMacBook-Pro-3 in ~/temp [16:34:42]
$ l
total 472
drwxr-xr-x 10 ganzhixiong staff 320B Oct 15 16:34 .
drwxr-xr-x+ 178 ganzhixiong staff 5.6K Oct 15 16:34 ..
-rw-r--r--@ 1 ganzhixiong staff 54K Sep 11 00:47 1.log
-rw-r--r-- 1 ganzhixiong staff 545B Sep 16 11:16 2.log
-rw-r--r-- 1 ganzhixiong staff 54K Sep 16 11:18 3.log
-rw-r--r-- 1 ganzhixiong staff 54K Sep 16 11:21 4.log
-rw-r--r-- 1 ganzhixiong staff 30B Sep 17 15:53 a.log
drwxr-xr-x 2 ganzhixiong staff 64B Oct 15 16:34 c#
-rw-r--r-- 1 ganzhixiong staff 54K Sep 11 00:47 hs_err_pid1391.log
-rw-r--r-- 1 ganzhixiong staff 17B Sep 16 12:08 苹果.log

# ganzhixiong @ ganzhixiongdeMacBook-Pro-3 in ~/temp [16:34:45]
$ cd c#
zsh: no matches found: c#

# ganzhixiong @ ganzhixiongdeMacBook-Pro-3 in ~/temp [16:36:38] C:1
$ cd c\#/

# ganzhixiong @ ganzhixiongdeMacBook-Pro-3 in ~/temp/c# [16:36:42]
$ echo "hello" # Linux 命令行或 Shell 中 # 号表示为注释,因此这样写不会报错
hello

命令行中的文件名或目录名若包含"#"号,别忘了添加转义

https://ganzhixiong.com/p/e77371fa/

Author

干志雄

Posted on

2021-10-15

Updated on

2021-10-15

Licensed under

Comments