It's smth. more fundamental. I guess I'm missing something in Bash. Versions are 5.1.21, 4.3.33. Or I'm missing a thing in understanding of Linux fork().
Are there any specific options or features responsible for stdin/stdout manipulations and pass in the case?
More general example:
Code: Select all
#!/bin/bash
PS4="+:lineno=\$LINENO: "
set -xeu
while read d ; do
c="$( read -p "Enter smth.: " v ; echo "${v}" )"
echo "$d -> $c"
done < <( find /sys/class/block/ )
Expected behavior: it requests value for "v" in terminal, and variable "v" value is set by "read" built-in using stdin produced in terminal in child shell instance.
De facto "v" is set in child shell instance from stdout, but from _parent's_ shell stdout, when no explicit redirection. Smth. implicit is going on.
Looks like parent stdout passed into child sub-shell. May be parent and child streams are the same instance of the stream. How to manage it?
Example output:
Code: Select all
+:lineno=9: read d
++:lineno=13: find /sys/class/block/
++:lineno=11: read -p 'Enter smth.: ' var
++:lineno=11: echo /sys/class/block/loop1
+:lineno=11: c=/sys/class/block/loop1
+:lineno=12: echo '/sys/class/block/ -> /sys/class/block/loop1'
/sys/class/block/ -> /sys/class/block/loop1
Are there any specific options or features responsible for stdin/stdout manipulations and pass in the case?