Re: $@ in function gives error

2024-08-17 Thread alex xmb sw ratchev
On Fri, Aug 16, 2024, 23:29 freek--- via Bug reports for the GNU Bourne Again SHell wrote: > Configuration Information [Automatically generated, do not change]: > Machine: x86_64 > OS: linux-gnu > Compiler: gcc > Compilation CFLAGS: -O2 -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 > -fstack-protec

Re: $@ in function gives error

2024-08-17 Thread Lawrence Velázquez
On Sat, Aug 17, 2024, at 6:41 AM, Freek de Kruijf wrote: > Apparently I have a problem with the concept of $@ Greg has already tried explaining it, so I'll just focus on a few details: > I see it as list of zero or more non-whitespaced elements When used in a context where splitting is performe

Re: $@ in function gives error

2024-08-17 Thread Greg Wooledge
On Sat, Aug 17, 2024 at 12:41:45 +0200, Freek de Kruijf wrote: > Apparently I have a problem with the concept of $@, I see it as list of zero > or more non-whitespaced elements, and quotes around it makes it into a single > element. Like a parameter p with a content of zero or more non-whitespace

Re: $@ in function gives error

2024-08-17 Thread alex xmb sw ratchev
On Sat, Aug 17, 2024, 12:42 Freek de Kruijf wrote: > Op zaterdag 17 augustus 2024 00:29:23 CEST schreef u: > > On Fri, Aug 16, 2024, at 12:59 PM, freek--- via Bug reports for the GNU > > > There is no problem with "$@" or functions here. The "problem" is > > that "$@" expands to multiple fields

Re: $@ in function gives error

2024-08-17 Thread Freek de Kruijf
Op zaterdag 17 augustus 2024 00:29:23 CEST schreef u: > On Fri, Aug 16, 2024, at 12:59 PM, freek--- via Bug reports for the GNU > There is no problem with "$@" or functions here. The "problem" is > that "$@" expands to multiple fields when there are two or more > positional parameters, so (as the

Re: $@ in function gives error

2024-08-16 Thread Greg Wooledge
On Fri, Aug 16, 2024 at 18:59:15 +0200, freek--- via Bug reports for the GNU Bourne Again SHell wrote: > #!/bin/bash > init() { > [ -n "$@" ] && echo $@ > } > init $@ You have multiple errors in this script. The first error is that you used $@ without quotes, twice. If you want to preserve the

Re: $@ in function gives error

2024-08-16 Thread Lawrence Velázquez
On Fri, Aug 16, 2024, at 6:29 PM, Lawrence Velázquez wrote: > There is no problem with "$@" or functions here. The "problem" is > that "$@" expands to multiple fields when there are two or more > positional parameters, so (as the error message says) you end up > running test(1) with too many argum

Re: $@ in function gives error

2024-08-16 Thread Lawrence Velázquez
On Fri, Aug 16, 2024, at 12:59 PM, freek--- via Bug reports for the GNU Bourne Again SHell wrote: > Description: > > Using the following script with a function > > #!/bin/bash > init() { > [ -n "$@" ] && echo $@ > } > init $@ > > and calling the script as follows: > > :~> LC_ALL=C . ./test.sh a b