Page 1 of 1

if case not always working

Posted: 17 Aug 2022 03:28
by batchnewbie

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

Re: if case not always working

Posted: 17 Aug 2022 08:18
by aGerman
Looks like the space between "yes" and "(" is missing in the second IF statement. Maybe this causes the problem.

Steffen

Re: if case not always working

Posted: 18 Aug 2022 00:46
by miskox
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

Re: if case not always working

Posted: 19 Aug 2022 03:25
by batchnewbie
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