Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to prevent variable substitution in SET command  (Read 6266 times)

0 Members and 1 Guest are viewing this topic.

John_L.

    Topic Starter


    Rookie

    Thanked: 2
    • Experience: Experienced
    • OS: Windows XP
    How to prevent variable substitution in SET command
    « on: September 04, 2012, 02:20:51 PM »
    I am trying to do the following:

    Code: [Select]
    SET I=http://www.someURL.com/My%20Webpage%28Version%20B%29.html
    in a batch file. However, the second parameter to the file (%2) is being substituted in the above.

    How do I prevent variable substitution in the above example?

    Thanks in advance for your help,

    John L.

    Lemonilla



      Apprentice

    • "Too sweet"
    • Thanked: 70
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: How to prevent variable substitution in SET command
    « Reply #1 on: September 04, 2012, 03:11:43 PM »
    SET I=http://www.someURL.com/My%%%20Webpage%%%28Version%%%20B%%%29.html

    you have to use the escape the %, otherwise it thinks you are referring to a veritable

    for most charictors (>, |, &) you need to use ^ but with % you must use another % or surround it with %'s
    Quote from: patio
    God Bless the DOS Helpers...
    Quote
    If it compiles, send the files.

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: How to prevent variable substitution in SET command
    « Reply #2 on: September 04, 2012, 09:39:26 PM »
    you have to use the escape the %, otherwise it thinks you are referring to a veritable

    for most charictors (>, |, &) you need to use ^ but with % you must use another %

    That's correct.


    Quote from:
    or surround it with %'s

    That bit is wrong.   Just double the percent signs.


    Code: [Select]
    SET I=http://www.someURL.com/My%%20Webpage%%28Version%%20B%%29.html

    Lemonilla



      Apprentice

    • "Too sweet"
    • Thanked: 70
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: How to prevent variable substitution in SET command
    « Reply #3 on: September 05, 2012, 02:32:04 PM »
    interesting, triple % has always worked for me, but maybe only in certain instances.
    Quote from: patio
    God Bless the DOS Helpers...
    Quote
    If it compiles, send the files.

    Salmon Trout

    • Guest
    Re: How to prevent variable substitution in SET command
    « Reply #4 on: September 06, 2012, 01:43:23 PM »
    interesting, triple % has always worked for me, but maybe only in certain instances.

    What circumstances?


    Lemonilla



      Apprentice

    • "Too sweet"
    • Thanked: 70
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: How to prevent variable substitution in SET command
    « Reply #5 on: September 07, 2012, 01:51:18 PM »
    What circumstances?


    Everything I've ever written, would you like me to post some examples? I'll have to go digging.
    Quote from: patio
    God Bless the DOS Helpers...
    Quote
    If it compiles, send the files.

    Salmon Trout

    • Guest
    Re: How to prevent variable substitution in SET command
    « Reply #6 on: September 07, 2012, 02:13:10 PM »
    would you like me to post some examples?

    Yes please.

    Salmon Trout

    • Guest
    Re: How to prevent variable substitution in SET command
    « Reply #7 on: September 08, 2012, 02:19:14 AM »
    Here, I'll do it for you.

    Code: [Select]
    @echo off
    echo Passed parameters:
    echo Parameter 1 %1
    echo Parameter 2 %2
    echo.
    echo Attempting to escape percent signs in string:
    echo.
    echo 1. No escaping
    SET I=http://www.someURL.com/My%20Webpage%28Version%20B%29.html
    echo %I%
    echo.
    echo 2. Replace one percent sign with two
    SET I=http://www.someURL.com/My%%20Webpage%%28Version%%20B%%29.html
    echo %I%
    echo.
    echo 3. Replace one percent sign with three
    SET I=http://www.someURL.com/My%%%20Webpage%%%28Version%%%20B%%%29.html
    echo %I%
    echo.
    echo 4. Replace one percent sign with four
    SET I=http://www.someURL.com/My%%%%20Webpage%%%%28Version%%%%20B%%%%29.html
    echo %I%
    echo.

    1. With parameters passed

    Code: [Select]
    Passed parameters:
    Parameter 1 cat
    Parameter 2 dog

    Attempting to escape percent signs in string:

    1. No escaping
    http://www.someURL.com/Mydog0Webpagedog8Versiondog0Bdog9.html

    2. Replace one percent sign with two
    http://www.someURL.com/My%20Webpage%28Version%20B%29.html

    3. Replace one percent sign with three
    http://www.someURL.com/My%dog0Webpage%dog8Version%dog0B%dog9.html

    4. Replace one percent sign with four
    http://www.someURL.com/My%%20Webpage%%28Version%%20B%%29.html

    With no parameters passed

    Code: [Select]
    Passed parameters:
    Parameter 1
    Parameter 2

    Attempting to escape percent signs in string:

    1. No escaping
    http://www.someURL.com/My0Webpage8Version0B9.html

    2. Replace one percent sign with two
    http://www.someURL.com/My%20Webpage%28Version%20B%29.html

    3. Replace one percent sign with three
    http://www.someURL.com/My%0Webpage%8Version%0B%9.html

    4. Replace one percent sign with four
    http://www.someURL.com/My%%20Webpage%%28Version%%20B%%29.html

    If you study the above you will see that to get ONE percent sign in the URL string using SET, you need exactly TWO percent signs in the code.




    Salmon Trout

    • Guest
    Re: How to prevent variable substitution in SET command
    « Reply #8 on: September 08, 2012, 04:06:11 AM »
    Put simply, 2N percents in the code are replaced by N percents in the displayed result, and 2N+1 percents are replaced by N+1 percents.