[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] The difference between $* and "$*"?
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] The difference between $* and "$*"? |
Date: |
Mon, 3 Feb 2014 08:16:50 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Sat, Feb 01, 2014 at 01:52:02PM -0700, Bob Proulx wrote:
> If IFS is unset, the parameters are separated by spaces.
>
> So if "unset IFS" then "$*" expands to "$1 $2 $3".
>
> If IFS is null, the parameters are joined without intervening
> separators.
>
> So if "unset IFS" then "$*" expands to "$1$2$3".
That last sentence is wrong. You meant to say, if IFS="" then "$*"
expands to "$1$2$3".
On a separate note, I prefer examples for this kind of answer:
imadev:~$ set -- one "one and a half" two
imadev:~$ args $*
6 args: <one> <one> <and> <a> <half> <two>
imadev:~$ args "$*"
1 args: <one one and a half two>
imadev:~$ ( IFS=""; args "$*" )
1 args: <oneone and a halftwo>
imadev:~$ args "$@"
3 args: <one> <one and a half> <two>
Where args is:
imadev:~$ cat bin/args
#! /bin/sh
printf "%d args:" "$#"
printf " <%s>" "$@"
echo
You almost always want "$@" unless you're joining array elements into
a single string.
- [Help-bash] The difference between $* and "$*"?, Peng Yu, 2014/02/01
- Re: [Help-bash] The difference between $* and "$*"?, Seth David Schoen, 2014/02/01
- Re: [Help-bash] The difference between $* and "$*"?, Chet Ramey, 2014/02/02
- Re: [Help-bash] The difference between $* and "$*"?, Peng Yu, 2014/02/02
- Re: [Help-bash] The difference between $* and "$*"?, Eric Blake, 2014/02/03
- Re: [Help-bash] The difference between $* and "$*"?, Eric Blake, 2014/02/03
- Re: [Help-bash] The difference between $* and "$*"?, Chet Ramey, 2014/02/03
Re: [Help-bash] The difference between $* and "$*"?, Bob Proulx, 2014/02/01
- Re: [Help-bash] The difference between $* and "$*"?,
Greg Wooledge <=