Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

How to merge variables in a batch file?

- - - - -

  • Please log in to reply
8 replies to this topic

#1
mf_2

mf_2

    Newbie

  • Member
  • 34 posts
  • Joined 02-July 07
Hello,

I have the following batch file:

SET %one% = "test"
SET %two% = "program"

Now I want %three% to contain somethign like this:
SomeWordstestprogram
That means that I want to have a string, attach %one% and then %two% to it and then write it into %three%.
How is that possible?

I tried PHP syntax but that didn't work ;)


How to remove advertisement from MSFN

#2
mormoloc

mormoloc

    Newbie

  • Member
  • 10 posts
  • Joined 03-June 07
SET %three% = "SomeWord" + %one% + %two% ???

#3
mf_2

mf_2

    Newbie

  • Member
  • 34 posts
  • Joined 02-July 07
Hello,

This worked:
SET three = "SomeWord" + %one% + %two%

However, when I want to see whats in %three%, I don't get anything.

echo %three%
gives me
"echo is turned ON"
or something like that (it's a German Windows, so I had to translate it).
What am I doing wrong?

#4
mormoloc

mormoloc

    Newbie

  • Member
  • 10 posts
  • Joined 03-June 07
i found THIS for you

i never worked with batch commands but looking at some examples, i think you should try like this:

SET one = string1
SET two = string2
SET three = "some other string " + one + " " + two
ECHO %three%

#5
[deXter]

[deXter]

    The Lord of the Scripts

  • Member
  • PipPipPip
  • 308 posts
  • Joined 08-May 04
You've got the wrong syntax for SET.

The correct syntax is: SET variable=string

SET one=test
SET two=program
SET three=SomeWord%one%%two%

echo %one%
echo %two%
echo %three%

Edited by [deXter], 04 July 2007 - 06:32 AM.

One Script to rule them all, One Script to find them, One Script to bring them all and in the web bind them

In the Land of The Net where the Hackers lie.


#6
spacesurfer

spacesurfer

    Pharmassist

  • Patrons
  • 1,668 posts
  • Joined 31-July 04
  • OS:Windows 7 x86
  • Country: Country Flag
set three = someword%one%%two%
echo %three%

leave no spaces and exclude "+" between %one% and %two%.

Edit: dexter beat me to it.

Edited by spacesurfer, 04 July 2007 - 06:41 AM.

_____________________________________________________________________
[Modify Office 2007 / 2010 Ribbon UI] [Javascript Guide] [Methods of Typing in Gujarati] [My Math Pages]
[Boot Windows 7 from VHD] [Multi-boot Vista/XP and other OSes with Grub Menu] [Boot XP and Vista Independently]


Gigabyte GA-P35-DS3L, Intel Core 2 Duo E6550 2.33 GHz, ASUS Radeon EAH3450 256 MB, 6 GB Corsair RAM, Maxtor 300 GB + Seagate 400 GB HDDs, Windows 7 Ultimate 64-bit
IBM T42 Intel Pentium M 1.7 GHz, 1.5 GB RAM, Radeon Mobility 7500, 160 GB HDD, Windows 7 Ultimate 32-bit

#7
mf_2

mf_2

    Newbie

  • Member
  • 34 posts
  • Joined 02-July 07
Thanks for the link, this finally worked:
SET THREE = SomeWords%one%%two%
SET THREE

The second line is used instead of the echo command.

#8
NaDer_GenKO

NaDer_GenKO

    Member

  • Member
  • PipPip
  • 180 posts
  • Joined 17-January 07
thank You very very much 'mormoloc' :thumbup

I was looking for a site like this

Edited by NaDer_GenKO, 04 July 2007 - 07:01 AM.


#9
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,578 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Good practice notes:
  • Set your variables local to the running batch session
  • To prevent the inclusion of unwanted whitespace in your variables, enclose them in parentheses (lines 3, 4, 5)
@Echo Off
Setlocal
(Set one=test)
(Set two=program)
(Set three=SomeWords%one%%two%)
Echo/%%three%%=%three%





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users