[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Query regarding ${parameter:-word} usage
From: |
Mun |
Subject: |
Re: Query regarding ${parameter:-word} usage |
Date: |
Wed, 23 Dec 2009 21:12:40 -0800 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
Hi,
Thanks for your replies.
Please see my comments below.
On Wed, Dec 23, 2009 at 05:30 PM PST, Matthew wrote:
MW>
MW>
MW> Mun wrote:
MW> > I am moving from ksh93 to bash and have a question regarding the usage
MW> > of ${parameter:-word} parameter expansion.
MW> >
MW> > In ksh, I use ${*:-.} as an argument to commands. For example:
MW> >
MW> > function ll
MW> > {
MW> > ls --color -Flv ${*:-.}
MW> > }
MW> >
MW> > This technique passes '.' as an arg to 'ls' if I didn't pass any args on
MW> > the command line (as I'm sure you all already know). But this does not
MW> > work with bash; nor have I been able to come up with a technique that
MW> > accomplishes the same thing. My only workaround so far is to put an
MW> > 'if' loop around the 'ls' that tests $# and takes the appropriate branch
MW> > depending on the number of args (i.e., 0 or non-zero).
MW> >
MW> > Any suggestions would be welcomed. Thanks in advance.
MW>
MW> Not sure why the above doesn't work, though you probably mean to use
MW> "$@" and not $* (presence/absence of ""s is intentional). This seems to
MW> work for me:
MW>
MW> function ll
MW> {
MW> ls --color -Flv "${@:-.}"
MW> }
I tried the above and got the following error:
bash: $@: unbound variable
Note that I am running the following version:
GNU bash, version 4.0.0(1)-release (x86_64-unknown-linux-gnu)
and my options are set as shown below.
Keep in mind that I'm porting my ksh environment to bash, so perhaps I
have something messed up in my environment. If the above is supposed to
work, then I'll try some additional experiments after the holidays and
see if I can narrow down the issue.
allexport on
braceexpand on
emacs off
errexit off
errtrace off
functrace off
hashall on
histexpand on
history on
ignoreeof on
interactive-comments on
keyword off
monitor on
noclobber on
noexec off
noglob off
nolog off
notify off
nounset on
onecmd off
physical off
pipefail off
posix off
privileged off
verbose off
vi on
xtrace off
Happy Holidays,
--
Mun