“$ @”在bash脚本中做了什么?

我遇到了这个脚本 :

#!/bin/sh qemu-system-x86_64 -enable-kvm \ -m 2G \ -device virtio-vga,virgl=on \ -drive file=/home/empty/qemubl/lab.img,format=raw,if=virtio \ -cpu host \ -smp 4 \ -soundhw sb16,es1370 \ "$@" 

$@的作用是什么?

我搜索man bash$@Pattern not found

您的搜索可能没有产生任何结果,因为(如钢铁驱动器评论 )您没有逃避$ ,尝试搜索\$@并且您将在man bash下找到以下内容 – 参数 – 特殊参数:

 @ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" ... If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters, "$@" and $@ expand to nothing (ie, they are removed). 

未加引号它扩大到$1 $2 $3 … ${N} ,引用"$1" "$2" "$3" … "${N}" ,这在大多数情况下都是你想要的。 在bash-hackers wiki中解释了这个和$*的差异。

它是一个内部变量,用于将传递给脚本的所有参数转发给脚本调用的命令,在本例中为qemu-system-x86_64