Why substring "on" or "off" not echo?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Why substring "on" or "off" not echo?

#1 Post by goodywp » 20 Dec 2021 14:10

Hi, I have a string as str which containing substring either on or off as below

Code: Select all

set str=Cha-cana-e2eeconfig-off-unsigned

for /f "tokens=1-5 delims=- " %%a in ("%str%") do set fla=%%a&set ca=%%b&set cfg=%%c&set e2ee=%%d&set sign=%%e
echo %fla%
echo %ca%
echo %cfg%
echo %e2ee%
echo %sign%
why I only got
Cha
cana
e2eeconfig
unsigned

not echoing %%d, which is off
There must be something I do not know regarding on or off here?
I need know the substring either on or off from the above string...

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Why substring "on" or "off" not echo?

#2 Post by jeb » 20 Dec 2021 15:04

Hi goodywp,

the echo command uses some special key words, like on, off, /? or <nothing> for special behaviour.
echo on - Enable the echo off each command before it will be executed (a debug output)
echo off - Disable the echo off commands
echo - Show the state of ON or OFF
echo /? - Show the help

To avoid the behaviour you could add a simple opening parenthesis.

Code: Select all

echo(%fla%
echo(%ca%
echo(%cfg%
echo(%e2ee%
echo(%sign%

goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Re: Why substring "on" or "off" not echo?

#3 Post by goodywp » 20 Dec 2021 15:22

Hi Jeb,
Thanks for your help.

WY

Post Reply