bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Query regarding ${parameter:-word} usage


From: Mike Frysinger
Subject: Re: Query regarding ${parameter:-word} usage
Date: Wed, 23 Dec 2009 20:27:17 -0500
User-agent: KMail/1.12.4 (Linux/2.6.31.4; KDE/4.3.4; x86_64; ; )

On Wednesday 23 December 2009 19:51:02 Mun wrote:
> I am moving from ksh93 to bash and have a question regarding the usage
> of ${parameter:-word} parameter expansion.
> 
> In ksh, I use ${*:-.} as an argument to commands.  For example:
> 
>    function ll
>    {
>       ls --color -Flv ${*:-.}
>    }
> 
> This technique passes '.' as an arg to 'ls' if I didn't pass any args on
> the command line (as I'm sure you all already know).  But this does not
> work with bash; nor have I been able to come up with a technique that
> accomplishes the same thing.  My only workaround so far is to put an
> 'if' loop around the 'ls' that tests $# and takes the appropriate branch
> depending on the number of args (i.e., 0 or non-zero).

your code works fine for me

$ ll() { ls --color -Flv "$@:-.}" ; }
$ ls() { echo "$@" ; }
$ ll
--color -Flv .
$ ll moo
--color -Flv moo

-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]