From: Greg Wooledge <greg@wooledge.org>
To: dash@vger.kernel.org, busybox@busybox.net, bug-bash@gnu.org,
Steffen Nurpmeso <steffen@sdaoden.eu>
Subject: Re: Question on $IFS related differences (Was: Question on $@ vs $@$@)
Date: Wed, 18 Sep 2024 07:21:30 -0400 [thread overview]
Message-ID: <Zuq3umfwkcx3TAtM@wooledge.org> (raw)
In-Reply-To: <CAH7i3Lq9xQnnkAO7cd5XZEsV4jY+Va6uWqjw3yaMi=A3mdh83g@mail.gmail.com>
On Wed, Sep 18, 2024 at 08:05:10 +0300, Oğuz wrote:
> On Wed, Sep 18, 2024 at 4:19 AM Steffen Nurpmeso <steffen@sdaoden.eu> wrote:
> >
>
> It boils down to this:
>
> f(){ echo $#;}; set "" "" ""; IFS=x; f $*
>
> bash, NetBSD and FreeBSD sh, and ksh88 all agree and print 2. pdksh
> prints 3 but mksh and oksh print 1. dash, ksh93, yash, and zsh print
> 0.
At the risk of sounding like a broken record, using an unquoted $* or $@
in a context where word splitting occurs is just *begging* for trouble.
Please don't do this in your scripts. All of these implementation
differences and possible bugs will just stop mattering, if you stop
using questionable shell features.
If you want to pass along your positional parameters to a function,
use "$@" with quotes. This will pass each parameter as a separate
argument to the function, with no modifications. It should work in
every post-Bourne shell (if it doesn't, that's a bug). This is almost
always what you want.
If you want to join all of your positional parameters together into
a single string, use "$*" with quotes. The first character of IFS
will be inserted between each pair of parameters. This is sometimes
useful when writing messages to log files, or to produce a simple
row of delimited fields (not a full-blown CSV file, though).
next prev parent reply other threads:[~2024-09-18 11:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-18 1:14 Question on $IFS related differences (Was: Question on $@ vs $@$@) Steffen Nurpmeso
2024-09-18 5:05 ` Oğuz
2024-09-18 11:21 ` Greg Wooledge [this message]
2024-09-18 14:48 ` Chet Ramey
2024-09-18 21:37 ` Steffen Nurpmeso
2024-09-18 21:05 ` Steffen Nurpmeso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zuq3umfwkcx3TAtM@wooledge.org \
--to=greg@wooledge.org \
--cc=bug-bash@gnu.org \
--cc=busybox@busybox.net \
--cc=dash@vger.kernel.org \
--cc=steffen@sdaoden.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.