I recently saw a script in which below find command was used:
find "$@" -type f -name "*.iso"
What does "$@"
mean here?
I recently saw a script in which below find command was used:
find "$@" -type f -name "*.iso"
What does "$@"
mean here?
"$@"
expands to all arguments passed to the shell. It has nothing to do with find
specifically.
https://linux.die.net/man/1/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 (i.e., they are removed).
A more succinct practical+relevant example below.
$ 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
$
find
to be directories to search, and not files.
– Scott - Слава Україні
Jul 01 '19 at 06:18