On 3/4/18 6:15 PM, Zach Hadgraft wrote: > Bash Version: 4.4 > Patch Level: 19 > Release Status: release > > Description: > global variable assignments fail when part of a sequence that > includes read and begins with a function invoked by command substitution > read can be invoked by another function, or invoked by another > command and the result is the same > > Repeat-By: > > """ > #!/bin/bash > > > r= > > f () > { > if [ -z "$r" ]; then > r="x" > read > fi > echo "$r" > } > > echo "$(f)" > echo "$(f)" > """
What do you expect to happen, and what happens instead? When I run this script, the `read' gets satisfied when you enter a line of text followed by a newline, and `x' is assigned to r: line x line x Since command substitution happens in a subshell, and subshells can't affect their parent's environment, `r' isn't going to change in the calling shell. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/