[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
$@ in function gives error
From: |
freek |
Subject: |
$@ in function gives error |
Date: |
Fri, 16 Aug 2024 18:59:15 +0200 (CEST) |
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 $@
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
- $@ in function gives error,
freek <=