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

how to write embeded if statement

3 views
Skip to first unread message

thinktwice

unread,
Jun 19, 2008, 9:13:51 AM6/19/08
to
i have written something like:
if not (%1) == () (
if not %1 == "" (set SENDER=%1))

but it doesn't work, it's invalid if statement

Tom Lavedas

unread,
Jun 19, 2008, 9:35:54 AM6/19/08
to

This one is tricky - it took a minute to figure out. Even though it
appears that the blank condition of the replaceable parameter, %1, is
being tested; the syntax of the second part of your compound statement
is being parsed, anyway. This is because the command processor is a
single pass processor and the parentheses make the multiple lines a
single statement (all of which is evaluated at one time). Therefore,
if %1 is empty, a syntax error results.

Try something like this ...

if not (%1) == () (
if not [%1] == [""] (set SENDER=%1))

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Dean Wells (MVP)

unread,
Jun 19, 2008, 10:14:20 AM6/19/08
to
"thinktwice" <memor...@gmail.com> wrote in message
news:80ed8d8f-229b-41c2...@f24g2000prh.googlegroups.com...

What are you trying to determine by the condition?

... I can guess of course, but I'd like to make sure I'm not incorrectly
inferring your goal.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l

thinktwice

unread,
Jun 20, 2008, 12:30:44 AM6/20/08
to
On 6月19日, 下午10时14分, "Dean Wells \(MVP\)"
<dwe...@maskmsetechnology.com> wrote:
> "thinktwice" <memorial...@gmail.com> wrote in message

thanks for you help, i'm trying to make sure the parameter that passed
to my batch file isn't empty nor ""

Al Dunbar

unread,
Jun 20, 2008, 1:13:27 AM6/20/08
to

"thinktwice" <memor...@gmail.com> wrote in message
news:89d52bac-2f98-421a...@p25g2000pri.googlegroups.com...

try this, then:

if "%~1" EQU "" (
echo/first parameter is either empty (null, missing) or ""
) else (
echo/an actual non-null value was passed as the first parameter.
)

This can sometimes be useful too:

(set _param=%~1)
if defined _param (
echo/an actual non-null value was passed as the first parameter.
) else (
echo/first parameter is either empty (null, missing) or ""
)

/Al


0 new messages