Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Escaping `/' when using "SET"

0 views
Skip to first unread message

Richard Bonner

unread,
Jan 26, 2009, 11:09:04 AM1/26/09
to
Hello, All.

In the course of playing with FreeDOS on a Toshiba laptop, I ran into a
problem that also happens with 4DOS, so I thought I would post it here,
too.

I have numerous batch files with lines such as:

SET /S=PARAMETER

The 4DOS "SET" command will not set the variable but instead issues:

Invalid parameter

How can I get the forward slash character to be accepted as part of
the variable name?

Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

ras...@highfiber.com

unread,
Jan 26, 2009, 11:40:18 AM1/26/09
to
On Jan 26, 9:09 am, ak...@chebucto.ns.ca (Richard Bonner) wrote:

>    In the course of playing with FreeDOS on a Toshiba laptop, I ran into a
> problem that also happens with 4DOS, so I thought I would post it here,
> too.
>
>    I have numerous batch files with lines such as:
>
> SET /S=PARAMETER
>
>    The 4DOS "SET" command will not set the variable but instead issues:
>
>                         Invalid parameter
>
>    How can I get the forward slash character to be accepted as part of
> the variable name?

Best practice in 4DOS is to use only alphanumerics, underscores and
dollar signs for variable names. If for some reason you really need a
variable with such a name (some external program requires it?), you
could e.g.

setdos /w-
set /s=parameter
setdos -w/

echo %[/s]

But I think it would be easier all around just to do a search-and-
replace on the variable name. Something like $S or OPT_S would be
easier to set, to reference, and to read.

--
Charles Dye ras...@highfiber.com

ras...@highfiber.com

unread,
Jan 26, 2009, 12:13:53 PM1/26/09
to
On Jan 26, 9:40 am, ras...@highfiber.com wrote:

>    setdos /w-
>    set /s=parameter
>    setdos -w/

On a closer look, this stunt may require either a very recent version
of 4DOS, or else a version of DOS with switchar support. FreeDOS
might or might not support that API; it's been a while since I messed
with FreeDOS, and switchar has always been a fairly obscure feature.

--
Charles Dye ras...@highfiber.com

Luchezar Georgiev

unread,
Jan 26, 2009, 1:33:26 PM1/26/09
to
ras...@highfiber.com пишет:

>> setdos /w-
>> set /s=parameter
>> setdos -w/
>
> On a closer look, this stunt may require either a very recent version
> of 4DOS, or else a version of DOS with switchar support. FreeDOS
> might or might not support that API; it's been a while since I messed
> with FreeDOS, and switchar has always been a fairly obscure feature.

Do not worry - FreeDOS does support this API, and with 4DOS 7.72 or newer,
only ROM-DOS of all well-known DOS variants wouldn't support SETDOS /W :-)

Regards,
Lucho

Richard Bonner

unread,
Jan 26, 2009, 2:18:13 PM1/26/09
to
ras...@highfiber.com wrote:

> On Jan 26, 9:09=A0am, ak...@chebucto.ns.ca (Richard Bonner) wrote:
> > =A0 =A0I have numerous batch files with lines such as:
> >
> > SET /S=3DPARAMETER
> >
> > =A0 =A0The 4DOS "SET" command will not set the variable but instead issue=
> s:
> >
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Invalid parameter
> >
> > =A0 =A0How can I get the forward slash character to be accepted as part o=
> f
> > the variable name?

> Best practice in 4DOS is to use only alphanumerics, underscores and
> dollar signs for variable names. If for some reason you really need a
> variable with such a name (some external program requires it?), you
> could e.g.

> setdos /w-
> set /s=3Dparameter
> setdos -w/

> echo %[/s]

> But I think it would be easier all around just to do a search-and-
> replace on the variable name. Something like $S or OPT_S would be
> easier to set, to reference, and to read.
> --
> Charles Dye

*** Unfortunately, I have several hundred batch files that look at
command-line switches and then make decisions, so I need a way to make
this work. It's no problem under DR-DOS; its SET command only has two
switches (/? /H|) and it allows any other slash-characters to be set
without complaint.

Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

ras...@highfiber.com

unread,
Jan 26, 2009, 2:40:43 PM1/26/09
to
On Jan 26, 12:18 pm, ak...@chebucto.ns.ca (Richard Bonner) wrote:

> ***   Unfortunately, I have several hundred batch files that look at
> command-line switches and then make decisions, so I need a way to make
> this work.

Fixing that many batch files by hand would be an undertaking, wouldn't
it? So perhaps your next project is a batch file to search all your
existing batches, identify the ones with problematic syntax, and
automatically do a search-and-replace on just those. Knowing you,
I'll bet you already have DOS ports of grep and sed available.... ;-)

--
Charles Dye ras...@highfiber.com

Richard Bonner

unread,
Jan 27, 2009, 12:03:45 PM1/27/09
to
ras...@highfiber.com wrote:

> On Jan 26, 12:18=A0pm, ak...@chebucto.ns.ca (Richard Bonner) wrote:
> > *** =A0 Unfortunately, I have several hundred batch files that look at


> > command-line switches and then make decisions, so I need a way to make
> > this work.

> Fixing that many batch files by hand would be an undertaking, wouldn't
> it? So perhaps your next project is a batch file to search all your
> existing batches, identify the ones with problematic syntax, and
> automatically do a search-and-replace on just those. Knowing you,
> I'll bet you already have DOS ports of grep and sed available.... ;-)
> --
> Charles Dye

*** Indeed I do, Charles. I also have MiniTrue, to which I am partial.

Before I undertake to make the changes, I would want to test to be sure
that the new coding would work on the popular DOS versions. So, I will
play with this for a while before making such changes permanent.

I would still favour a simple way to pass the slash character as
opposed to rewriting the entire test method for command-line switches in
all those batch files. That could more easily be substituted using `grep',
`sed' or `MiniTrue' because the methods are not exactly the same for every
batch file. That means a blanket substitution for complicated code would
not likely be suitable for all.

Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

Luchezar Georgiev

unread,
Jan 27, 2009, 12:46:32 PM1/27/09
to
Richard Bonner пишет:

> *** Indeed I do, Charles. I also have MiniTrue, to which I am partial.

You're an "old house", as we say here ;-)

> Before I undertake to make the changes, I would want to test to be sure
> that the new coding would work on the popular DOS versions. So, I will
> play with this for a while before making such changes permanent.

Wait, wait! Are you going to do all this tough work just because you've
replaced DR-DOS with FreeDOS?! If so, why don't you replace DR-DOS with
Enhanced DR-DOS (http://www.drdosprojects.de)? I've worked on the DOS/C
(the real name of the FreeDOS kernel) and can tell you that it has much
more bugs than Enhanced DR-DOS! Plus there are many differences between
FreeDOS and DR-DOS but very few differences between DR-DOS and Enhanced
DR-DOS. So I recommend it to you. FreeDOS is also very slow on the file
system work, especially on writing files. Going for it will be an error.

Regards,
Lucho

ras...@highfiber.com

unread,
Jan 27, 2009, 2:09:25 PM1/27/09
to
On Jan 27, 10:03 am, ak...@chebucto.ns.ca (Richard Bonner) wrote:

>    I would still favour a simple way to pass the slash character as
> opposed to rewriting the entire test method for command-line switches in
> all those batch files. That could more easily be substituted using `grep',
> `sed' or `MiniTrue' because the methods are not exactly the same for every
> batch file. That means a blanket substitution for complicated code would
> not likely be suitable for all.

Well, it *might* be possible to modify the parser to allow escaping
the slashes on the command line. Lucho would have to decide whether
that would be possible without wreaking havoc -- there could be far-
reaching consequences; the 4DOS parser is complex.

I can personally guarantee that treating an UNescaped switch character
as anything other than a switch character would be an unmitigated
disaster....

--
Charles Dye ras...@highfiber.com

Luchezar Georgiev

unread,
Jan 27, 2009, 2:35:37 PM1/27/09
to
ras...@highfiber.com пишет:

> On Jan 27, 10:03 am, ak...@chebucto.ns.ca (Richard Bonner) wrote:
>
>> I would still favour a simple way to pass the slash character as
>> opposed to rewriting the entire test method for command-line switches in
>> all those batch files. That could more easily be substituted using `grep',
>> `sed' or `MiniTrue' because the methods are not exactly the same for every
>> batch file. That means a blanket substitution for complicated code would
>> not likely be suitable for all.

As I wrote, he could avoid this large work by staying with DR-DOS (Enhanced
DR-DOS). If his batch files worked in DR-DOS, they'll work also in EDR-DOS.
Switching from a superior DOS to an inferior one like FreeDOS is a bad idea
in my opinion.

> Well, it *might* be possible to modify the parser to allow escaping
> the slashes on the command line. Lucho would have to decide whether
> that would be possible without wreaking havoc -- there could be far-
> reaching consequences; the 4DOS parser is complex.

Even if the SET parser is modified, if the variables contain the switch
character, this can be a time bomb which can burst when the variable is used.

> I can personally guarantee that treating an UNescaped switch character
> as anything other than a switch character would be an unmitigated
> disaster....

Exactly.

Regards,
Lucho

Richard Bonner

unread,
Jan 28, 2009, 8:29:00 PM1/28/09
to
ras...@highfiber.com wrote:

> On Jan 27, 10:03=A0am, ak...@chebucto.ns.ca (Richard Bonner) wrote:
> > =A0 =A0I would still favour a simple way to pass the slash character as


> > opposed to rewriting the entire test method for command-line switches in
> > all those batch files.

(Snip)

> Well, it *might* be possible to modify the parser to allow escaping
> the slashes on the command line. Lucho would have to decide whether
> that would be possible without wreaking havoc -- there could be far-
> reaching consequences; the 4DOS parser is complex.

*** Perhaps adding another switch that would cause SET to pass any
switch characters following it. One would have to make it the last
switch if more than one was being used. Perhaps something such as:

SET /ISC /S=PARAMETER

`/ISC' would stand for "Ignore Switch Character".


> I can personally guarantee that treating an UNescaped switch character
> as anything other than a switch character would be an unmitigated
> disaster....
> --
> Charles Dye

** Well, DR-DOS currently allows it. However, its SET only has two
switches:

/?
/H (HI)

Both are for help. It passes any other switches to the variable - even
the `/' by itself.


Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

Richard Bonner

unread,
Jan 28, 2009, 8:48:41 PM1/28/09
to
Luchezar Georgiev (lu...@gawab.com) wrote:
> ras...@highfiber.com пишет:

> > On Jan 27, 10:03 am, ak...@chebucto.ns.ca (Richard Bonner) wrote:
> >> I would still favour a simple way to pass the slash character as
> >> opposed to rewriting the entire test method for command-line switches in
> >> all those batch files.

(Snip)

> As I wrote, he could avoid this large work by staying with DR-DOS
> (Enhanced DR-DOS). If his batch files worked in DR-DOS, they'll work
> also in EDR-DOS. Switching from a superior DOS to an inferior one like
> FreeDOS is a bad idea in my opinion.

*** I'm not switching. I aquired an extra laptop and wanted to toy with
FreeDOS, so I loaded it on.

In what ways do you consider FreeDOS inferior?


> > Well, it *might* be possible to modify the parser to allow escaping
> > the slashes on the command line. Lucho would have to decide whether
> > that would be possible without wreaking havoc -- there could be far-
> > reaching consequences; the 4DOS parser is complex.

> Even if the SET parser is modified, if the variables contain the switch
> character, this can be a time bomb which can burst when the variable is
> used.
>

> Lucho

*** I typically use it in this instance as follows:

SET %1=PARAMETER
IF "%/A%" == "PARAMETER" SET XCDATE=/DA:%2
IF "%/B%" == "PARAMETER" SET XCDATE=/DB:%2
IF "%/O%" == "PARAMETER" SET XCDATE=/DO:%2
IF "%/R%" == "PARAMETER" GOTO RANGE
...

I have used this method to avoid character case problems on the command
line since before the IF command's case sensitivity could be turned off. I
have never bothered to change it since it works so well. Well... until I
tried it under 4DOS and FreeDOS. (-:

Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

Richard Bonner

unread,
Jan 28, 2009, 8:53:03 PM1/28/09
to
Luchezar Georgiev (lu...@gawab.com) wrote:
> Richard Bonner пишет:
> > *** I also have MiniTrue, to which I am partial.

> You're an "old house", as we say here ;-)

*** I use what works and continues to work. (-:


> > Before I undertake to make the changes, I would want to test to be sure
> > that the new coding would work on the popular DOS versions. So, I will
> > play with this for a while before making such changes permanent.

> Wait, wait! Are you going to do all this tough work just because you've
> replaced DR-DOS with FreeDOS?! If so, why don't you replace DR-DOS with
> Enhanced DR-DOS (http://www.drdosprojects.de)? I've worked on the DOS/C
> (the real name of the FreeDOS kernel) and can tell you that it has much
> more bugs than Enhanced DR-DOS! Plus there are many differences between
> FreeDOS and DR-DOS but very few differences between DR-DOS and Enhanced
> DR-DOS. So I recommend it to you. FreeDOS is also very slow on the file
> system work, especially on writing files. Going for it will be an error.
>

> Lucho

*** Well, I am not going to replace DR-DOS. I put FreeDOS on an extra
laptop so as to experiment. I like to see what the differences are among
the popular DOS versions.

Richard Bonner
http://www.chebucto.ca/~ak621/DOS/

Luchezar Georgiev

unread,
Jan 29, 2009, 3:08:14 AM1/29/09
to
Richard Bonner пишет:

> In what ways do you consider FreeDOS inferior?

As I wrote, its kernel has more bugs and is slower. But you can experiment
with anything labelled as FreeDOS also staying with the EDR-DOS kernel and
if you wish, its (of EDR-DOS) COMMAND.COM. See http://www.drdosprojects.de
for more information, downloads, forum, etc. Note that because the sources
of anything but the kernel for DR-DOS are not available, EDR-DOS uses some
FreeDOS utilities like SYS and FORMAT too.

Regards,
Lucho

Luchezar Georgiev

unread,
Jan 29, 2009, 3:15:51 AM1/29/09
to
Richard Bonner пишет:

> In what ways do you consider FreeDOS inferior?

As I wrote, its kernel has more bugs and is slower. But you can experiment

0 new messages