Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: default values



On Mar 30,  8:12pm, Emanuel Berg wrote:
}
} Is there a C-like "... ? ... : ... ;" syntax or
} otherwise standard or conventional way to assign
} default values to sometimes-not-submitted parameters?

In math context you can actually use ternary syntax:

    $(( x ? y : z ))

But I think you're actually looking for this:

${NAME-WORD}
${NAME:-WORD}
     If NAME is set, or in the second form is non-null, then substitute
     its value; otherwise substitute WORD.  In the second form NAME may
     be omitted, in which case WORD is always substituted.

So e.g.

    local num_files=${1:-10}
    local where=${2:-./}



Messages sorted by: Reverse Date, Date, Thread, Author