-4

I have a little problem in my code,
if I

set ghot=1    

and

set fo1=text  

and try echoing

echo %fo%ghot%%    

like this, it comes like

%fo1%    

instead of text

VincenzoC
  • 30,117
  • 12
  • 90
  • 112
hars
  • 1
  • 2
  • 2
    FYI people are generally more willing to help if you format your post correctly and write like a grown up. – jonrsharpe Dec 31 '16 at 12:42
  • 2
    `echo !fo%ghot%!`with Delayed Expansion enabled. The "standard way" to write this _array element_ is `set fo[1]=text` and `echo !fo[%ghot%]!`. See [this post](http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) – Aacini Dec 31 '16 at 16:28

2 Answers2

2

I misunderstood what you were asking at first. Adding call to the line will give you the behavior you want.

call echo %%fo%ghot%%%

Edited to add the extra enclosing %'s It works without them from the command line, but not from within a batch file.

Protium
  • 213
  • 3
  • 13
2

An alternative method using delayed expansion:

@Echo Off
SetLocal EnableDelayedExpansion
Set "ghot=1"
Set "fo1=text"
Echo=!fo%ghot%!
Timeout -1
Compo
  • 36,585
  • 5
  • 27
  • 39