bug-bash
[Top][All Lists]
Advanced

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

Re: parameter expansion with `:` does not work


From: Lawrence Velázquez
Subject: Re: parameter expansion with `:` does not work
Date: Wed, 7 Jul 2021 23:23:48 -0400

> On Jul 7, 2021, at 10:38 PM, lisa-asket@perso.be wrote:
> 
> Correct.  How do others customarily use `${fdir:=$PWD}` ?

The common idiom is

    : "${fdir:=$PWD}"

The ':' utility is used because it does nothing, but its arguments
are expanded as usual.

> I'd rather understand what's going on, rather than simply never use it.

Think about what is happening here:

    fdir=${fdir:=$PWD}

This is conceptually equivalent to

    if [[ -z "$fdir" ]]; then
        fdir="$PWD"
    fi
    fdir="$fdir"

I hope you can see why this is a pointless thing to do.

-- 
vq



reply via email to

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