Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a variable equal to the contents of another variable?

In the following (simplified example) batch file I am having difficulty correctly setting Y:

@Echo off
setlocalenabledelayed Expansion
set EqS=Nope
set X=Eq
set Y=%X%S 
echo Y

How can I get the output of this script to be Nope instead of EqS?

like image 653
Exe_Arco Avatar asked Dec 02 '11 21:12

Exe_Arco


People also ask

How do you make a variable equal another variable in Python?

The second method of creating references in Python is by assigning a variable to another variable: var1 = var2 , where both var1 and var2 are two distinct variables. For example, let the variable var2 contain the value 2 .

How do you assign a variable to another variable in C#?

type variableName = value; Where type is a C# type (such as int or string ), and variableName is the name of the variable (such as x or name). The equal sign is used to assign values to the variable.

How do you pass value from one variable to another in JavaScript?

Here is some code: window. onload = function show(){ var x = 3; } function trig(){ alert(x); } trig();

How can I assign a value from one variable to another in PHP?

PHP variables: Assigning by Reference PHP (from PHP4) offers another way to assign values to variables: assign by reference. This means that the new variable simply points the original variable. Changes to the new variable affect the original, and vice a verse.


1 Answers

As Karl ask, there could be different meanings of your question.
I try to give an answer for each possibility

@echo off
setlocal EnableDelayedExpansion
set EqS=Nope
set X=Eq

REM set Y1 to "EqS" 
set Y1=%X%S 

REM set Y2 to "Nope" (content of EqS)
set Y2=!%X%S!

REM set Y3 to "!EqS!"
set Y3=^^!%X%S^^!

echo %Y1%
echo %Y2%
echo %Y3%
set EqS=Something
echo(
echo Text %Y1%
echo Content %Y2%
echo Pointer %Y3%
like image 191
jeb Avatar answered Oct 15 '22 16:10

jeb