-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?

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.

| improve this answer | |
  • Thank you, works perfectly! – Riccardo La Marca Apr 1 at 13:46
  • 1
    @RiccardoLaMarca instead of here-docs or here-strings (which will use a temporary file in bash, zsh and other shells), you could use a process substitution: source script < <(echo 18) – mosvy Apr 1 at 16:47
  • Thanks also more mosvy – Riccardo La Marca Apr 2 at 10:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.