You would pass them pretty much the same as you would pass arguments in any other way:
sed -i 's/ = /=/' "$file"
source "$file"
/path/to/another/script.sh "$variable1" "$variable2"
Obviously using the appropriate command line switches (or not if applicable).
If using the code as above, the value of $variable1
will be available in the other script as $1
(the 1st command line argument), while $variable2
will be available as $2
.
To keep the original names in your new script you would need to reassign them using the positional parameters, ie:
variable1=$1
variable2=$2
However this may not be the most efficient way to do this, you might be better off with the suggestion below:
It sounds like you may actually want to source your file within the second script and not the first. In which case you may want to do the following:
script1.sh:
sed -i 's/ = /=/' "$file"
/path/to/another/script2.sh "$file"
script2.sh:
file=$1
source "$file"
printf '%s\n' "$variable1"
printf '%s\n' "$variable2"
Related recommended reading: 3.4.1 Positional Parameters
Note: assigning $1
to the file
variable is not necessary, you could also simply source "$1"
but I have written it this way in an attempt to show how positional parameters are handled