It seems a similar question was answered here.
You can of course use
source to assign the variables if you are comfortable, but you can also use
grep to only run specific lines from the file that look like variable declerations.
How to handle many variables
If you want to source all the variables assigned in
source <(grep -E '^\w+=' script1.sh)
grep to extract all lines from
script1.sh that look like
variable assignments. These lines are then run in the current shell,
assigning the variables.
If you use this approach first check to make sure that you want all
the variables and that there aren't any that will interfere with what
you are doing. If there are such, we can exclude them with a second
Considering the pieces in turn:
source file tells the shell to execute the
file in the current shell.
<(...) is called process substitution. It allows us to use the output of a command in place of a file name.
grep -E '^\w+=' script1.sh extracts all lines that seem like variable assignments. If you run this command by itself on
the command line, you should see something like:
and so on. You should do this first and inspect the output to make sure that these are the lines that you want to execute.