Bash 单个参数中的函数 Space

Bash Function Space in single Argument

我是控制台的新手,正在尝试编写一个函数来创建一个目录,目录名称作为函数参数。到目前为止,这是我的功能:

clidir() {
    mkdir 
}

每当我输入带有 space 的参数时,它都会创建两个目录。我试过:

clidir "New Folder"

clidir New\ Folder

而且他们都创建了多个目录。

欢迎任何帮助。

Double-quote shell

你要避免 word-splitting 的论点
clidir() {
    mkdir ""
}

摘自 man bash 页,

Word Splitting

The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting. The shell treats each character of IFS as a delimiter, and splits the results of the other expansions into words using these characters as field terminators. If IFS is unset, or its value is exactly , the default, then sequences of , , and at the beginning and end of the results of the previous expansions are ignored, and any sequence of IFS characters not at the beginning or end serves to delimit words.