help-bash
[Top][All Lists]
Advanced

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

Bash Shell Parameter Expansion


From: tolugboji
Subject: Bash Shell Parameter Expansion
Date: Sat, 09 Oct 2021 14:45:20 +0000

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Saturday, October 9th, 2021 at 2:05 PM, Dennis Williamson 
<dennistwilliamson@gmail.com> wrote:

> 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.

Thanks, I am testing the behaviour of bash shell parameter expansion first.
And experienced the problem I mentioned.



reply via email to

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