if case not always working

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batchnewbie
Posts: 7
Joined: 08 Nov 2021 19:35

if case not always working

#1 Post by batchnewbie » 17 Aug 2022 03:28

Code: Select all

if %lower_prefix_log_with_datetime%==yes (SET second_stg_rman_log_trc_prefix=%source_host_db%_%log_datetime%_%partial_rman_script_log_prefix%) else (SET second_stg_rman_log_trc_prefix=%partial_rman_script_log_prefix%_%source_host_db%_%log_datetime%)

echo second_stg_rman_log_trc_prefix %second_stg_rman_log_trc_prefix%
echo lower_comp_prefix_with_rman_arg %lower_comp_prefix_with_rman_arg%
SET initial_rman_log_trc_prefix=
echo initial_rman_log_trc_prefix %initial_rman_log_trc_prefix%
REM exit /B

if %lower_comp_prefix_with_rman_arg%==yes(SET initial_rman_log_trc_prefix="2nd_delcampo") else (SET initial_rman_log_trc_prefix="2nd_abcdef")


REM SET initial_rman_log_trc_prefix=%first_rman_arg%_%second_rman_arg%_%third_rman_arg%_%second_stg_rman_log_trc_prefix%

echo second lower_comp_prefix_with_rman_arg %lower_comp_prefix_with_rman_arg%
echo second initial_rman_log_trc_prefix %initial_rman_log_trc_prefix%
results/outcome

Code: Select all

C:\Users\lzhlzh>echo second_stg_rman_log_trc_prefix lap63-sin_wcdb_20220817_172222_set_scn_scn_number
second_stg_rman_log_trc_prefix lap63-sin_wcdb_20220817_172222_set_scn_scn_number

C:\Users\lzhlzh>echo lower_comp_prefix_with_rman_arg yes
lower_comp_prefix_with_rman_arg yes

C:\Users\lzhlzh>SET initial_rman_log_trc_prefix=

C:\Users\lzhlzh>echo initial_rman_log_trc_prefix
initial_rman_log_trc_prefix

C:\Users\lzhlzh>REM exit /B

C:\Users\lzhlzh>if yes == yes(SET initial_rman_log_trc_prefix="2nd_delcampo") else (SET initial_rman_log_trc_prefix="2nd_abcdef")

C:\Users\lzhlzh>REM SET initial_rman_log_trc_prefix=one_two_three_lap63-sin_wcdb_20220817_172222_set_scn_scn_number

C:\Users\lzhlzh>echo second lower_comp_prefix_with_rman_arg yes
second lower_comp_prefix_with_rman_arg yes

C:\Users\lzhlzh>echo second initial_rman_log_trc_prefix
second initial_rman_log_trc_prefix

C:\Users\lzhlzh>exit /B
while my first if statement works

it sets second_stg_rman_log_trc_prefix lap63-sin_wcdb_20220817_172222_set_scn_scn_number

but my second if statement look like it never really run

it is supposed to set initial_rman_log_trc_prefix="2nd_delcampo"

but it never sets. Instead it is back to "" .an empty string


any insight will be greatly appreciated. many thanks in advance

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: if case not always working

#2 Post by aGerman » 17 Aug 2022 08:18

Looks like the space between "yes" and "(" is missing in the second IF statement. Maybe this causes the problem.

Steffen

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: if case not always working

#3 Post by miskox » 18 Aug 2022 00:46

Additional to Steffen's answer:add " to the IF statements.

Code: Select all

if "%lower_prefix_log_with_datetime%"=="yes" (...
Also

/I should be added to the IF.

In this way empty strings cannot cause problems and you see if there are additional spaces that should not be there (or if a space is missing).

Saso

batchnewbie
Posts: 7
Joined: 08 Nov 2021 19:35

Re: if case not always working

#4 Post by batchnewbie » 19 Aug 2022 03:25

thanks a lot,

I solve the problem

I wanted to confirm that if it no possible to do a multiple line if else statement in batch files.

many thanks

Post Reply