-1

This command:

echo '18' | source meta-cmf-raspberrypi/setup-environment

Not set the environment variables as instead happened with a simply:

source meta-cmf-raspberrypi/setup-environment

With "18" in input.
The question at link: Environment variables are not set when my function is called in a pipeline

Not solve my problem because i have try:

echo '18' > >(source meta-cmf-raspberrypi/setup-environment)

Without success. How do I solve the problem?

1 Answers1

2

In the pipeline, the script is being sourced in a separate environment. Likewise in the process substitution example. This means that variables set in the script are set in a child environment to the calling shell. Changes in a child environment can never propagate to the parent environment.

You could solve this in two ways, avoiding sourcing the script in a separate environment.

The first way would work in a shell that understand "here-strings":

source meta-cmf-raspberrypi/setup-environment <<<18

The second way is to use a standard here-document:

source meta-cmf-raspberrypi/setup-environment <<END_INPUT
18
END_INPUT

In both variations, the script is sourced in the current environment, with its input redirected from the here-string/here-document.

Kusalananda
  • 333,661