Difference between $# and ${#@} Difference between $# and ${#@} bash bash

Difference between $# and ${#@}


Per manual page (3.5.3 Shell Parameter Expansion):

${#parameter}

Parameter length. The length in characters of the value of parameter is substituted. If parameter is * or @, the value substituted is the number of positional parameters. If parameter is an array name subscripted by * or @, the value substituted is the number of elements in the array.

So ${#@} is just a special case since $# is the usual way to express the number of positional parameters.


./foo executed foo if it's marked as executable and has a proper shebang line (or is an ELF binary). It will be executed in a new process.

. ./foo or . foo loads the script in the current shell. It is equal to source foo

With your example code you need to use the second way if you want the exported variables to be available in your shell.


With the dot alone, bash is "sourcing" the specified file. It is equivalent to the source builtin and attempts to include and execute the script within the same shell process.

The ./ starts a new process, and the current shell process waits for it to terminate.