help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Chain/cascade assignment


From: Dennis Williamson
Subject: Re: [Help-bash] Chain/cascade assignment
Date: Mon, 22 Feb 2016 13:18:14 -0600

On Sun, Feb 21, 2016 at 2:35 PM, Илюшкин Никита <address@hidden> wrote:

> Hello,
>
> search results and simple test in CLI show, that there is no chain
> assignment in bash like var=var=val. I wonder why and want to propose this
> as a feature (as far this assign construction seems common in other
> languages).
>
> --
> Nikita Ilyushkin
>
>
This is hackish, probably has some gotchas and requires a recent version of
Bash for the -g global option of declare. So use at your own risk.

assign () { val=$1; shift; for var; do declare -g $var=$val; done; }

$ assign 42 a b c d[4] e[{3..8}]

$ declare -p a b c d e
declare -- a="42"
declare -- b="42"
declare -- c="42"
declare -a d='([4]="42")'
declare -a e='([3]="42" [4]="42" [5]="42" [6]="42" [7]="42" [8]="42")'

-- 
Visit serverfault.com to get your system administration questions answered.


reply via email to

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