Comparing content of two variables

I have very abstract need of "comparing two variables" and take subsequent actions.

please refer to image below

I have a part of script which reads a file and generates variables based on content of this file.(Variables generated in same shell)

The reason i have categorized the design in user and script environment is that the script environment must be able to handle changes made in user environment.
The changes will only be in the form of new line entries in file1.txt

I need help on how to move from desired output to final output:(

How about this:

while [ $# -gt 1 ]
do
    arg=$1
    val=$2
    grep -wq "$arg" file1.txt && echo $arg=$val
    shift
    shift
done

It will just print

a1=1
a2=2
b2=3

What i need is for this code:

echo "a1 is " $a1

output i have now:I have reached up to here)

a1 is a1

output i need now is:

a1 is 1

If i change your code to

grep -wq "$arg" file1.txt && echo $arg=$val > file_out && source file_out

I will get what i need.
But again. there is one more problem.. since i am not experienced with grep, i will need your help.
my file1.txt is actually like this:

$source_dir/script_B_1 a1 >$output_dir/scriptb1
$source_dir/script_B_2 a2 b2 >$output_dir/scriptb2
$source_dir/script_B_3 a3 b3 c3 >$output_dir/scriptb3

Now i need to extract just the arguments in file_out.
how to proceed?

Could this help you ?

$>cat infile
$source_dir/script_B_1 a1 >$output_dir/scriptb1
$source_dir/script_B_2 a2 b2 >$output_dir/scriptb2
$source_dir/script_B_3 a3 b3 c3 >$output_dir/scriptb3
$>awk '{$1=$NF=""}1' infile

O/P

 a1
 a2 b2
 a3 b3 c3

printing out just the arguments is not what i am looking at.

consider the file1 and file2 below.

file1

$source_dir/script_b_1 a1 >$output_dir/scriptb1
$source_dir/script_b_2 a1 a2 >$output_dir/scriptb2
.
.

file2

$source_dir/script_b_1 $a1 >$output_dir/scriptb1
$source_dir/script_b_2 $a1 $a2 >$output_dir/scriptb2
.
.

what i want is..
either format file1 to file2 or format file2 to file1