Assign the same string to multiple variables

SebMa

I want to assign the string contained in $value to multiple variables.

Actually the example I gave before (var1=var2=...=$value) was not reflecting exactly what I wanted. So far, I found this but it only works if $value is an integer:

$ let varT=varz=var3=$value

How can I do that?

laenkeio

In my opinion you're better of just doing the more readable:

var1="$value" var2="$value" var3="$value" var4="$value" var5="$value" var6="$value" var7="$value" var8="$value" var9="$value" var10="$value"

But if you want a very short way of accomplishing this then try:

declare var{1..10}="$value"

Edited: using brace expansions instead of printf and declare instead of eval, which could be dangerous depending on what's in $value.

Cf. EDIT1: You could still use brace expansions in the new case:

declare var{T,z,3}="$value"

It's safer than the printf approach in the comments because it can handle spaces in $value.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

assign multiple variables to the same value in Javascript

From Dev

Assign integer to multiple characters in a string

From Dev

Assign multiple keys to same value in array

From Dev

Assign a value to all variables that start with certain string

From Dev

Is there a way to assign multiple variables a same value or attribute?

From Dev

Assign multiple variables at once

From Dev

"use strict": Assign Value to Multiple Variables

From Dev

javascript: Assign method and string to the same property name

From Dev

Bash: How to split a string and assign multiple variables

From Dev

Simultaneously assign same value to multiple places?

From Dev

String formula with variables in same sheet

From Dev

How to assign multiple variables at once in JavaScript?

From Dev

Parse string and assign to the same variable?

From Dev

Most elegant way to assign multiple variables to the same value?

From Dev

Separate multiple variables in same column

From Dev

assign empty pointer to multiple variables

From Dev

Jquery assign fucntion to multiple same class selector

From Dev

Multiple Javascript variables with the same value

From Dev

how to assign multiple localstorage variables inside a loop?

From Dev

Assign a value to all variables that start with certain string

From Dev

python urlencode multiple same variables

From Dev

assign string components into variables

From Dev

How to assign -INFINITY amongst others to multiple variables?

From Dev

awk assign to multiple variables at once

From Dev

Java: Assign Scanner input to multiple variables?

From Dev

Jquery multiple function with same variables

From Dev

How to assign multiple variables from LINQ statements

From Dev

Assign multiple variables with Scrapy Items at once

From Dev

javascript array assign to multiple variables

Related Related

  1. 1

    assign multiple variables to the same value in Javascript

  2. 2

    Assign integer to multiple characters in a string

  3. 3

    Assign multiple keys to same value in array

  4. 4

    Assign a value to all variables that start with certain string

  5. 5

    Is there a way to assign multiple variables a same value or attribute?

  6. 6

    Assign multiple variables at once

  7. 7

    "use strict": Assign Value to Multiple Variables

  8. 8

    javascript: Assign method and string to the same property name

  9. 9

    Bash: How to split a string and assign multiple variables

  10. 10

    Simultaneously assign same value to multiple places?

  11. 11

    String formula with variables in same sheet

  12. 12

    How to assign multiple variables at once in JavaScript?

  13. 13

    Parse string and assign to the same variable?

  14. 14

    Most elegant way to assign multiple variables to the same value?

  15. 15

    Separate multiple variables in same column

  16. 16

    assign empty pointer to multiple variables

  17. 17

    Jquery assign fucntion to multiple same class selector

  18. 18

    Multiple Javascript variables with the same value

  19. 19

    how to assign multiple localstorage variables inside a loop?

  20. 20

    Assign a value to all variables that start with certain string

  21. 21

    python urlencode multiple same variables

  22. 22

    assign string components into variables

  23. 23

    How to assign -INFINITY amongst others to multiple variables?

  24. 24

    awk assign to multiple variables at once

  25. 25

    Java: Assign Scanner input to multiple variables?

  26. 26

    Jquery multiple function with same variables

  27. 27

    How to assign multiple variables from LINQ statements

  28. 28

    Assign multiple variables with Scrapy Items at once

  29. 29

    javascript array assign to multiple variables

HotTag

Archive