在shell脚本中,美元符号后跟at符号(@)意味着什么?

例如:

umbrella_corp_options $@

推荐答案

$@$*几乎相同,都表示"所有命令行参数".它们通常用于简单地将所有参数传递给另一个程序(从而在另一个程序周围形成一个包装器).

当你有一个带空格的论点(例如)并用双引号加$@时,这两种语法之间的差异就会显现出来:

wrappedProgram "$@"
# ^^^ this is correct and will hand over all arguments in the way
#     we received them, i. e. as several arguments, each of them
#     containing all the spaces and other uglinesses they have.
wrappedProgram "$*"
# ^^^ this will hand over exactly one argument, containing all
#     original arguments, separated by single spaces.
wrappedProgram $*
# ^^^ this will join all arguments by single spaces as well and
#     will then split the string as the shell does on the command
#     line, thus it will split an argument containing spaces into
#     several arguments.

例如:打电话

wrapper "one two    three" four five "six seven"

将导致:

"$@": wrappedProgram "one two    three" four five "six seven"
"$*": wrappedProgram "one two    three four five six seven"
                             ^^^^ These spaces are part of the first
                                  argument and are not changed.
$*:   wrappedProgram one two three four five six seven

Linux相关问答推荐

如何确定Linux上的最大静态TLS(线程本地存储)块大小?

Linux-如何区分目录中名称相同但扩展名不同的所有文件

在正在运行的进程的输出周围添加自定义字符串

从 MariaDB 连接到 Oracle 时出现错误消息libsqora.so.11.1:找不到文件

无法放弃所有权限,但可以放弃 CAP_SETUID 权限.

如何在 gcc 搜索路径上防止多个版本的 Boost?

根据文件名对目录中的文件进行 chgrp

如何使用 gcc 编译为程序集

具体来说,fork() 如何处理 Linux 中 malloc() 动态分配的内存?

在 Python 上模拟鼠标点击

将参数传递给 awk 脚本文件

使用 ssh 判断远程主机上是否存在文件

zsh/bash 上不区分大小写的 Glob

docker compose:加载共享库时出错:libz.so.1:无法从共享对象映射段:不允许操作

如何链接到 GCC 中特定版本的共享库

crt1.o:在函数_start中:-Linux 中未定义对main的引用

如何从 Linux 终端找到特定文件?

Android - 找不到命令

如何从 Linux 内核模块的 init_module 代码创建设备 node ?

查找和基本名称不能很好地播放