Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was expecting

excludes="${excludes:-( ${default_excludes[@]} )}"

to be an array if $excludes is empty. Unfortunately the stuff after :- is taken to be a string. Did I miss some syntax contortion, or do I have to use the clunky

if [ -z "${excludes:-}" ]
    excludes=( "${default_excludes[@]}" )


share|improve this question
Maybe they didn't like the :-(... – l0b0 May 9 '11 at 14:02
up vote 4 down vote accepted

You can construct an array from another array with this syntax:

arr1=( "${arr2[@]}" )

That can be translated into this default-value syntax:


I've tested some edge cases, like array members with spaces or newlines in them and it seems to handle them correctly.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.