define variable with scope the following process

Is it in bash scripting possible to define a variable which is scoped to the following process? Something like:

X="123" echo "$X"

Ultimately, I want to do catch the output of some process and write that (with some other surrounding text as well) to some output file:

X=$(...) echo "...$X..." > output_file

In general you're right, you can set variables in the environment of the command:

VAR=value some_command_that_uses_variable_VAR

But be aware of the order of Shell Expansions:

x=123 echo "$x"

the shell will expand $x before it evaluates x=123