package Psh
::Support
::Env
;
# string do_setenv(string command)
# command is of the form "VAR VALUE" or "VAR = VALUE" or "VAR"; sets
# $ENV{VAR} to "VALUE" in the first two cases, or to "$VAR" in the
# third case unless $VAR is undefined. Used by the setenv and export
# builtins. Returns VAR (which is a string with no $).
if( $arg=~ /^\s*(\w+)(\s+|\s*=\s*)(.+)/ ) {
if( $value=~ /^\'(.*)\'\s*$/ ) {
# If single quotes were used, do not interpret
if ($value=~ /^\"(.*)\"/) {
# Use eval so that variables may appear on RHS
# ($value); use protected_eval so that lexicals
# in this file don't shadow package variables
Psh
::PerlEval
::protected_eval
("\$ENV{$var}=\"$value\"", 'do_setenv');
} elsif( $arg=~ /(\w+)/ ) {
Psh
::PerlEval
::protected_eval
("\$ENV{$var}=\$$var if defined(\$$var);",