[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: $@ in function gives error
From: |
alex xmb sw ratchev |
Subject: |
Re: $@ in function gives error |
Date: |
Sat, 17 Aug 2024 23:06:31 +0200 |
On Fri, Aug 16, 2024, 23:29 freek--- via Bug reports for the GNU Bourne
Again SHell <bug-bash@gnu.org> 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-protector-strong -funwind-tables -fasynchronous-unwind-tables
> -fstack-clash-protection -Werror=return-type -flto=auto -g -D_GNU_SOURCE
> -DRECYCLES_PIDS -Wall -g -Wuninitialized -Wextra -Wno-switch-enum
> -Wno-unused-variable -Wno-unused-parameter -Wno-parentheses
> -ftree-loop-linear -pipe -DBNC382214=0 -DIMPORT_FUNCTIONS_DEF=0
> -DDEFAULT_LOADABLE_BUILTINS_PATH='/usr/lib64/bash'
> uname output: Linux eiktum 6.10.3-1-default #1 SMP PREEMPT_DYNAMIC Sun
> Aug 4 06:37:13 UTC 2024 (ba01e0e) x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-suse-linux-gnu
>
> Bash Version: 5.2
> Patch Level: 26
> Release Status: release
>
> Description:
>
> Using the following script with a function
>
> #!/bin/bash
> init() {
> [ -n "$@" ] && echo $@
> }
> init $@
>
[[ $@ ]]
that u see ' null or more non whitespace '
when u dont "$@" quote it it goes prolly on wordsplitting away
and calling the script as follows:
>
> :~> LC_ALL=C . ./test.sh a b c d
>
> gives the following error:
>
> bash: [: too many arguments
>
> Fix:
>
> When assigning $@ to a parameter p and using that parameter as "$p"
> instead of "$@"
> it works OK.
>
> fr.gr.
>
> Freek de Kruijf
>
>