On Sun, Jul 29, 2012 at 03:04:21PM -0400, Chris F.A. Johnson wrote:
On Sun, 29 Jul 2012, Jason Vas Dias wrote:
function count_args {v=($@); echo ${#v[@]}; }
Always quote $@. Without quotes, it's the same as $*
function count_args {v=( $@ );
On Sun, Jul 29, 2012 at 10:23 AM, Jason Vas Dias
jason.vas.d...@gmail.com wrote:
function count_colons { IFS=':' ;v=($@); echo ${#v[@]}; }
count_colons() { local n=${*//[!:]}; printf '%s\n' ${#n}; }
On Sunday, July 29, 2012 03:23:29 PM Jason Vas Dias wrote:
echo $(count_args 1 2 3\ 4)
I should also have mentioned that I couldn't reproduce this case. You should
be getting 4 here in your example, not 3. I have the same Bash version. Are
you sure you were echoing `${#v[@]} ' and not `${#@}',
On Sun, 29 Jul 2012, Jason Vas Dias wrote:
Good day Chet, list -
I'm concerned about the difference in output of these functions with
the example input
given on the '$' prefixed line below (with 4.2.29(2)-release
(x86_64-unknown-linux-gnu)):
function count_args {v=($@);
non-standard $IFS members be treated so differently ?
Jason Vas Dias
3:23 PM (4 hours ago)
Good day Chet, list -
I'm concerned about the difference in output of these functions with
the example input
given on the '$' prefixed line below (with 4.2.29(2)-release
(x86_64-unknown-linux-gnu
Jason Vas Dias jason.vas.d...@gmail.com writes:
Thanks Dan -
The plot thickens - Yes, you're right, I had $IFS mistakenly set to ':' in
the
shell in which I ran 'count_args' . Without this IFS setting, I get
a count of 4:
$ env -i PATH=/bin:/usr/bin HOME=${HOME} /bin/bash --norc
$
Thanks Andreas -
I guess your answer mostly explains my issue - except for one thing:
And shouldn't '3\ 4' be a single string in any case, regardless of IFS ?
It is. But if field splitting is applied to it it will be split in two
words when $IFS contains a space.
This was really the point