为什么$ 1*$ 2显示目录中所有内容的文件名?

发布于 2025-02-10 11:04:48 字数 468 浏览 3 评论 0原文

当我在代码中犯了一个错误时,这是​​我偶然发现的(忘记$(()) lol),所以我已经解决了我的愚蠢错误,但是为什么$ 1*$ 2 $ 2为您提供脚本所在目录中的文件和文件夹的列表吗?

以下是一个示例

echo $1*$2
$ bash script.sh
random.bmp script.sh some text document.odt test file.txt test folder

脚本

$ echo $1*$2
random.bmp script.sh some text document.odt test file.txt test folder

: 功能上的任何地方都有任何文档吗?我短暂地环顾四周,但没有发现其他人对此感到困惑。

This is something I stumbled on when I made a mistake in my code (forgot $(()) lol), so I've fixed my silly mistake already, but why does $1*$2 give you a list of files and folders in the directory that the script is in?

Here is an example:

script.sh:

echo $1*$2
$ bash script.sh
random.bmp script.sh some text document.odt test file.txt test folder

The same thing happens if the command is just directly issued:

$ echo $1*$2
random.bmp script.sh some text document.odt test file.txt test folder

Does anyone know why it acts like this? Is there any documentation anywhere on the function? I briefly looked around about this but didn't find anyone else confused about it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北斗星光 2025-02-17 11:04:48

Globs

“ glob”是一组匹配或扩展特定类型模式的bash功能的通用名称。某些用于球形的同义词(取决于其出现的上下文)是模式匹配,图案扩展,文件名扩展等。一个球看起来像*。txt,并且在用于匹配文件名时,有时称为“通配符”。

传统的壳球使用非常简单的语法,它的表现不如 regularexpression 。地球上的大多数字符都受到字面的处理,但是*匹配0或更多字符,恰好匹配一个字符,[...] 匹配指定集中的任何单个字符(请参见范围下面)。所有地球都隐含地锚定在开始和结尾。


- glob -greg的Wiki


官方文档: fileName扩展(bash参考手册)

Globs

"Glob" is the common name for a set of Bash features that match or expand specific types of patterns. Some synonyms for globbing (depending on the context in which it appears) are pattern matching, pattern expansion, filename expansion, and so on. A glob may look like *.txt and, when used to match filenames, is sometimes called a "wildcard".

Traditional shell globs use a very simple syntax, which is less expressive than a RegularExpression. Most characters in a glob are treated literally, but a * matches 0 or more characters, a ? matches precisely one character, and [...] matches any single character in a specified set (see Ranges below). All globs are implicitly anchored at both start and end.

-- glob - Greg's Wiki


Official documentation: Filename Expansion (Bash Reference Manual)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文