简体   繁体   English

Bash - 简单问号 (?) 的含义

[英]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:所以我的两个问题是:

  1. What is the meaning of a simple question mark in bash (I know for example about the '$?' special parameter and regex usage)? bash 中一个简单的问号是什么意思(例如,我知道“$?”特殊参数和正则表达式的用法)?
  2. I suppose that is is a bash environment variable or some king of variable.我想那是一个 bash 环境变量或某个变量之王。 How can I inspect a variable?如何检查变量? For example a command can be inspected with type keyword, ie type cd例如,可以使用type关键字检查命令,即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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM