There are a few tools that automatically produce Bourne-compatible shell fragments intended to be evaled directly or put in a script.Many of these tools produce assignments of the form:VAR=value; export VARWhy do they do this instead of using export VAR=value directly? I think this strategy is widespread enough to have an explanation / history. Are there some Bourne-compatible shells that can't handle the combined export/assignment syntax? It seems like the type of thing that addressed an ancient bug and now is just something people do sometimes, like ${1+$@}.cpan produces a fragment like this one and appends it to your *shrc. I replaced literal occurrences of my home directory with ${HOME}.PATH=${HOME}/perl5/bin${PATH:+:${PATH}}; export PATH;PERL5LIB=${HOME}/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}; export PERL5LIB;PERL_LOCAL_LIB_ROOT=${HOME}/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}; export PERL_LOCAL_LIB_ROOT;PERL_MB_OPT=--install_base \${HOME}/perl5\; export PERL_MB_OPT;PERL_MM_OPT=INSTALL_BASE=${HOME}/perl5; export PERL_MM_OPT;opam config env does something similar.$ opam config env | sed -e 's:'$HOME':${HOME}:g' | perl -pe 's/=.*/=.../ if /^PATH=/ or /^MANPATH=/'CAML_LD_LIBRARY_PATH=${HOME}/.opam/4.02.3/lib/stublibs; export CAML_LD_LIBRARY_PATH;OPAMUTF8MSGS=1; export OPAMUTF8MSGS;MANPATH=...PERL5LIB=${HOME}/.opam/4.02.3/lib/perl5:${HOME}/perl5/lib/perl5; export PERL5LIB;OCAML_TOPLEVEL_PATH=${HOME}/.opam/4.02.3/lib/toplevel; export OCAML_TOPLEVEL_PATH;PATH=...PATH and MANPATH have been omitted in the above example.
Why do many tools emit `VAR=value; export VAR` instead of `export VAR=value`?
shell