One safe possibility is to use a function:
expand_pattern() {
pattern="$x and $y"
}
That's all. Then use as follows:
x=1 y=1
expand_pattern
echo "$pattern"
You can even use x
and y
as environment variables (so that they are not set in the main scope):
x=1 y=1 expand_pattern
echo "$pattern"