help-bash
[Top][All Lists]
Advanced

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

Re: Bash Shell Parameter Expansion


From: Dennis Williamson
Subject: Re: Bash Shell Parameter Expansion
Date: Sat, 9 Oct 2021 09:05:19 -0500

On Sat, Oct 9, 2021, 8:44 AM tolugboji via <help-bash@gnu.org> wrote:

> What is wrong with tho following bash function?
>
> parade-parexpan ()
> {
> ${param:="Hilbert Transform"}
> echo "$param"
> }
>
> I keep getting
>
> Hilbert: command not found
> Hilbert Transform


Your assignment is being executed as a command. Why don't you simply do

param="Hilbert Transform"

If param might somehow previously been assigned a value but maybe it hasn't
and now's your opportunity but you don't want to clobber an existing value
if it's there

: ${param:="Hilbert Transform"}

Note the colon. You probably really want to do something else. Here's one
example that comes in handy:

myfunc () {

    param=${$1:-"Hilbert Transform"}
    echo "$param"
}

Note the hyphen instead of the equal  That assigns a default value if
there's no argument supplied when the function is called.


reply via email to

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