Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

1 Answer 1

up vote 3 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.