Question

I'm getting an issue with this code below, set -x is telling me that the variables ARE being assigned, but trying to echo them outside of this loop does not seem to be working?

          export "ex_$x"=$(git rev-parse HEAD | cut -c1-10)

      done
    ((used++))

    echo $ex_render
    echo $ex_storage

    exit # =/

    php -f "${cdir}/../public/bootstrap.php" -- "${line}" "${ex_render}" "${ex_storage}"
Was it helpful?

Solution

It looks like your code got truncated, but it sounds like the classic pipe-to-read problem.

$ echo hi | read x
$ echo $x
$ # Nothing!
$ read x <<< hi
$ echo $x
hi

Basically, a pipe creates an implicit subshell. To avoid it, either avoid the pipe:

while read foo; do things; done < <(process substitution)

Or explicitly create the subshell so you can control the scope:

inputcommand | ( while read foo; do things; done;
  # variables still assigned as long as you're in the subshell
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top