"Angel Tsankov" <fn42...@fmi.uni-sofia.bg> wrote: > How do you know that $# is always set? And what about $...@? To what values > are these parameters set outside any function?
$# gives the number of positional parameters. If there aren't any positional parameters, then it's set to 0. In the man page, under PARAMETERS, Special Parameters, you'll find: # Expands to the number of positional parameters in decimal. Note that it doesn't say "while a function is being executed" or "when some positional parameters are set". That variable is always set, as are the others listed under Special Parameters. Positional parameters can be used outside of functions: set foo bar; echo $# $@ bash -c 'echo $0; echo $# $@' arg-zero foo bar > A more appropriate parameter to use could be $? which, by pure logic, seems > to be at least as often set as is $#. They're both always set; pick whichever one you like. paul