[英]Bash - meaning of a simple question mark (?)
I was playing around with some bash features and as I tried echo-ing some output, I noticed, that我正在玩一些 bash 功能,当我尝试回显一些 output 时,我注意到,
echo what about in some more complex example ?
results in结果是
what about in some more complex example \
在一些更复杂的例子中呢\
I know that escaping the question mark or the whole line with quotes resolves the problem, but I am curious of why is it happening.我知道 escaping 问号或带引号的整行可以解决问题,但我很好奇为什么会这样。
So my 2 questions are:所以我的两个问题是:
type cd
type cd
In that context it functions as a glob pattern.在这种情况下,它作为一个全局模式起作用。 If there are files with one-character names in the current working directory, the shell expands an unquoted question mark to their names.
如果当前工作目录中有单字符名称的文件,shell 会将不带引号的问号扩展为它们的名称。
$ echo ? \? '?' "?"
? ? ? ?
$ touch a b c
$ echo ? \? '?' "?"
a b c ? ? ?
Similarly, ??
同样,
??
is expanded to two-character filenames, ??*
to filenames longer than one character, and ??[ab]
to three-character filenames ending with an a or a b , etc.扩展为两个字符的文件名,
??*
扩展为超过一个字符的文件名, ??[ab]
扩展为以a或 a b结尾的三个字符的文件名,等等。
See Filename Expansion for further information.有关详细信息,请参阅文件名扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.