Parenthesis concatentation problem...

  • Thread starter mathewsdw@sbcglobal.net
  • Start date
Status
Not open for further replies.
M

mathewsdw@sbcglobal.net

Guest
I apologize if this question has already been answered sometime in the past, but I tried a couple of searches with no results. (I don't quite know how to search for parenthesis other than using the word "parenthesis", and that came up with no matches.) I am writing a batch file to do some simple manipulations on file names that may contain parenthesis, and this batch file is failing (dramatically in some cases) if the file name happens to contain parenthesis. Basic question can be illustrated by showing a very simple batch file (following) and its output; the same results occur if the commands in the batch file are typed in manually (but the documentation isn't nearly so good! ; > )

Batch file contents: (It's not really as long as it at first looks since most of the lines are comments...)

@Echo Off
Rem First variable that is an open parenthesis...
Set Wrk1=(
Rem Second Variable that can be pretty much anything...
Set Wrk2=Test
Rem Concatenation with only one "%"...
Rem (I know from lots of experience that this doesn't work...)
Echo 1: %Wrk1%Wrk2
Rem Concatenation with two "%"...
Rem (This has always worked up to now...)
Echo 2: %Wrk1%%Wrk2
Rem A desperate attempt that doesn't work either...
Echo 3: %Wrk1%%%Wrk2
Rem This works, but it's _not_ what I want...
Echo 4: %Wrk2%%Wrk1
Rem Same problem with built-in functions...
Echo 5: %Wrk1%@Right[-1,Wrk2]
Echo 6: %Wrk1%%@Right[-1,Wrk2]
Echo 7: %Wrk1%%%@Right[-1,Wrk2]

Output from batch file:

1: (Wrk2
2: (%Wrk2
3: (%%Wrk2
4: Test(
5: (@Right[-1,Wrk2]
6: (%@Right[-1,Wrk2]
7: (%%@Right[-1,Wrk2]

As you can see, if a variable follows another variable that contains only an open parenthesis, the second variable does not evaluate. This is also true if the second "variable" is a built-in function. Is there a "solution" to this problem? (If not I'll have to write a C++ program to do what I want; I really don't want to go to all that trouble; that's why I write .bat files in the first place!)

- Dan Mathews
 
May 20, 2008
3,515
4
Elkridge, MD, USA
mathewsdw@sbcglobal.net wrote:
| I apologize if this question has already been answered sometime in
| the past, but I tried a couple of searches with no results. (I
| don't quite know how to search for parenthesis other than using the
| word "parenthesis", and that came up with no matches.) I am writing
| a batch file to do some simple manipulations on file names that
| *may* contain parenthesis, and this batch file is failing
| (*dramatically* in some cases) if the file name happens to contain
| parenthesis. Basic question can be illustrated by showing a very
| simple batch file (following) and its output; the same results occur
| if the commands in the batch file are typed in manually (but the
| documentation isn't nearly so good! ; > )
...

Did you try the /X option of the SETDOS command? I'd try setdos /x-45678. If
that does not work for you, AND you use TCC 10 (you did not specify which
version of the command processor you use), I would look into using the new
binary functions, @balloc/@bread/@bwrite etc.
--
HTH, Steve
 

samintz

Scott Mintz
May 20, 2008
1,501
16
Solon, OH, USA
I don't know why (perhaps Rex will explain) but you need to specify the
SETDOS /X-4 command to disable nested variable expansion.

Set Wrk1=(
Set Wrk2=Test
setdos /x-4
Echo 1: %[Wrk1]%[Wrk2]
Echo 2: %Wrk1%%Wrk2
Echo 3: %Wrk2%%Wrk1

-Scott


"mathewsdw@sbcglobal.net" <> wrote on 06/16/2009
03:06:51 AM:


> I apologize if this question has already been answered sometime in
> the past, but I tried a couple of searches with no results. (I
> don't quite know how to search for parenthesis other than using the
> word "parenthesis", and that came up with no matches.) I am writing
> a batch file to do some simple manipulations on file names that
> *may* contain parenthesis, and this batch file is failing
> (*dramatically* in some cases) if the file name happens to contain
> parenthesis. Basic question can be illustrated by showing a very
> simple batch file (following) and its output; the same results occur
> if the commands in the batch file are typed in manually (but the
> documentation isn't nearly so good! ; > )
>
> Batch file contents: (It's not really as long as it at first looks
> since most of the lines are comments...)
>
> @Echo Off
> Rem First variable that is an open parenthesis...
> Set Wrk1=(
> Rem Second Variable that can be pretty much anything...
> Set Wrk2=Test
> Rem Concatenation with only one "%"...
> Rem (I know from lots of experience that this doesn't work...)
> Echo 1: %Wrk1%Wrk2
> Rem Concatenation with two "%"...
> Rem (This has always worked up to now...)
> Echo 2: %Wrk1%%Wrk2
> Rem A desperate attempt that doesn't work either...
> Echo 3: %Wrk1%%%Wrk2
> Rem This works, but it's _not_ what I want...
> Echo 4: %Wrk2%%Wrk1
> Rem Same problem with built-in functions...
> Echo 5: %Wrk1%@Right[-1,Wrk2]
> Echo 6: %Wrk1%%@Right[-1,Wrk2]
> Echo 7: %Wrk1%%%@Right[-1,Wrk2]
>
> Output from batch file:
>
> 1: (Wrk2
> 2: (%Wrk2
> 3: (%%Wrk2
> 4: Test(
> 5: (@Right[-1,Wrk2]
> 6: (%@Right[-1,Wrk2]
> 7: (%%@Right[-1,Wrk2]
>
> As you can see, if a variable follows another variable that contains
> only an open parenthesis, the second variable does not evaluate.
> This is also true if the second "variable" is a built-in function.
> Is there a "solution" to this problem? (If not I'll have to write a
> C++ program to do what I want; I really don't want to go to all that
> trouble; that's why I write .bat files in the first place!)
>
> - Dan Mathews
>
>
>
>
 
M

mathewsdw@sbcglobal.net

Guest
Thanks, Scott and Steve. The SETDOS command did the trick! (Phew! The files come from an external web site, I don't really have any control whatsoever about whether they contain parenthesis or not, and I really DID NOT WANT to write a C++ program! (I'm basically lazy...))

- Dan

P.S. By the way, I would have never in a million years looked into the "SETDOS" command (I wouldn't have even suspected that that was a configurable parameter), so THANKS AGAIN!!!

I apologize if this question has already been answered sometime in the past, but I tried a couple of searches with no results. (I don't quite know how to search for parenthesis other than using the word "parenthesis", and that came up with no matches.) I am writing a batch file to do some simple manipulations on file names that may contain parenthesis, and this batch file is failing (dramatically in some cases) if the file name happens to contain parenthesis. Basic question can be illustrated by showing a very simple batch file (following) and its output; the same results occur if the commands in the batch file are typed in manually (but the documentation isn't nearly so good! ; > )

Batch file contents: (It's not really as long as it at first looks since most of the lines are comments...)

@Echo Off
Rem First variable that is an open parenthesis...
Set Wrk1=(
Rem Second Variable that can be pretty much anything...
Set Wrk2=Test
Rem Concatenation with only one "%"...
Rem (I know from lots of experience that this doesn't work...)
Echo 1: %Wrk1%Wrk2
Rem Concatenation with two "%"...
Rem (This has always worked up to now...)
Echo 2: %Wrk1%%Wrk2
Rem A desperate attempt that doesn't work either...
Echo 3: %Wrk1%%%Wrk2
Rem This works, but it's _not_ what I want...
Echo 4: %Wrk2%%Wrk1
Rem Same problem with built-in functions...
Echo 5: %Wrk1%@Right[-1,Wrk2]
Echo 6: %Wrk1%%@Right[-1,Wrk2]
Echo 7: %Wrk1%%%@Right[-1,Wrk2]

Output from batch file:

1: (Wrk2
2: (%Wrk2
3: (%%Wrk2
4: Test(
5: (@Right[-1,Wrk2]
6: (%@Right[-1,Wrk2]
7: (%%@Right[-1,Wrk2]

As you can see, if a variable follows another variable that contains only an open parenthesis, the second variable does not evaluate. This is also true if the second "variable" is a built-in function. Is there a "solution" to this problem? (If not I'll have to write a C++ program to do what I want; I really don't want to go to all that trouble; that's why I write .bat files in the first place!)

- Dan Mathews
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
vefatica Command line DO with no closing parenthesis? Support 9
nikbackm Command line evaluation question - variable inside parenthesis Support 7
Dick Johnson Weird Color Problem Support 8
fishman@panix.com Problem with 27.15 Support 2
M Problem with VSDevCmd.bat in VS 16.7.3 Support 0
R Problem with @INT[ value] in V26 Support 9
M Selecting test "off by one" problem in Take command Support 4
Alpengreis UTF-8 problem in TCC related to Python Support 7
K_Meinhard Small problem in german IDE 26 Support 3
B Problem with color in nested shells Support 1
Joe Caverly Problem creating and switching to a DESKTOP Support 9
vefatica Another popup problem Support 10
Alpengreis ffind dialog (/W) problem Support 4
Alpengreis [TCMD v25.00.24] Small space problem with the DE translation in Prefs-GUI Support 1
Alpengreis [TCMD v25.00.24] Problem with copy and paste and the # char via mouse in TCC Support 6
A Problem with functions @int @decimal and identifying Powershell as a shell. Support 12
B IF command problem in tcexit.btm Support 9
fishman@panix.com Problem at Startup of TCC Support 3
P Problem with SFTP copies Support 7
P Problem with FTP copies Support 10
Jay Sage Problem with Context Menu Copy+Paste+Run Key Assignment Support 7
R Problem with %_do_loop in nested do loops Support 2
fishman@panix.com New Problem with later Windows 10 Support 10
Peter Murschall A little problem with LEAVE and COMMENT Support 5
M Handling of %~I problem Support 4
WinLanEm FOR problem Support 18
K Problem With SCRPUT /u Support 3
vefatica What's TCMD's problem with ^e[0m? Support 13
Peter Murschall IDE: RTL with non-English resources-problem is back in Build 28 Support 4
rps Regex problem: \xnn not recognized as a hex character Support 0
rps PRIORITY LOW problem Support 1
old coot Regex problem: \xnn not recognized as a hex character Support 12
vefatica Another problem with build 22. Support 3
Alpengreis [23.x] Download-Problem Support 2
S Problem with " Support 3
C Problem navigating forums Support 11
x13 Problem listing repository files using DIR http(s)://... Support 8
Joe Caverly Problem with TEE in v22 Support 2
Alpengreis Problem with thousands delimiter and colors Support 17
M Take Command 18, migrating to another machine, license problem. Support 1
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2
rps How to? @search problem Support 2
WinLanEm @SELECT problem Support 6
T Fixed Problem with use of Batch parameters in the IDE Support 1
Oz Solomon Problem with "list" Support 14
S V21.24 theme problem Support 2
Alpengreis Problem if command prompt is not legacy Support 4
Alpengreis TCMD.INI: The "super hidden" problem ... Support 6
G Odd problem - screen brightness Support 4
rps V20 In-process pipes problem Support 8

Similar threads