how set variable in parent shell, subshell?
a=3 (a=4) echo $a
the whole point of subshell doesn't affect calling session. in bash subshell child process, other shells differ variable setting in subshell not affect caller. definition.
do need subshell? if need group use braces:
a=3 { a=4;} echo $a
gives 4
(be careful of spaces in one). alternatively, write variable value stdout , capture in caller:
a=3 a=$(a=4;echo $a) echo $a
avoid using back-ticks ``, deprecated , can difficult read.
Comments
Post a Comment