我最近看到了一个脚本,其中使用了以下find命令:
find "$@" -type f -name "*.iso"
这"$@"
是什么意思?
"$@"
扩展为传递给shell的所有参数。它与find
具体无关。
https://linux.die.net/man/1/bash
@
扩展到位置参数(从1开始)。当在双引号内进行扩展时,每个参数都会扩展为一个单独的单词。也就是说,“ $ @”等效于“ $ 1”“ $ 2” ...如果在单词中出现双引号扩展名,则第一个参数的扩展名将与原始单词的开头部分连接在一起,并且扩展名最后一个参数中的表示与原始单词的最后一部分结合在一起。当没有位置参数时,“ $ @”和$ @扩展为空(即,它们被删除)。
下面是一个更简洁的实用+相关示例。
$ cat a.sh
#!/bin/bash -x
find "$@" -ls
$ ./a.sh foo bar blah
+ find foo bar blah -ls
15481123719088698 4 -rw-rw-rw- 1 steve steve 4 Jun 30 19:29 foo
17451448556173323 0 -rw-rw-rw- 1 steve steve 0 Jun 30 19:29 bar
find: ‘blah’: No such file or directory
$
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句