On 01/22/2018 10:00 AM, Steve Aberle wrote: > > #/bin/sh > # Example: use of tee following an if-then-else-fi construct > # clobbers a variable set within that construct.
Not a problem of tee, but a limitation of your shell. > # tee into a file (after if-then-else-fi construct) - CLOBBERS VARIABLE > VAR_3="none" > if [ "$VAR_3" == "none" ] > then > VAR_3="true" > echo -e "Location 7:\t\$VAR_3 = \"$VAR_3\"" > else > VAR_3="false" > echo -e "Location 8:\t\$VAR_3 = \"$VAR_3\"" > fi | tee $LOG3 POSIX says that the use of a pipeline can (but not must) create a subshell for the elements of the pipeline; once you have a subshell, changes made in that shell are NOT visible to the parent shell. It is not tee that is clobbering variables, but the fact that your shell chose to use a subshell to implement the pipeline. There's nothing coreutils can do about your shell, so you may be better off redirecting your question to a forum on shell programming. http://mywiki.wooledge.org/BashFAQ/024 has more details about this common shell programming pitfall. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
