Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!not-for-mail From: Linda Walsh Newsgroups: gnu.bash.bug Subject: language inconsistency(wart) & RFE Date: Fri, 16 Oct 2015 18:18:21 -0700 Lines: 85 Approved: bug-bash@gnu.org Message-ID: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1445044717 25931 208.118.235.17 (17 Oct 2015 01:18:37 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash Envelope-to: bug-bash@gnu.org User-Agent: Thunderbird X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 173.164.175.65 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11679 Ok, thinking this from a different way. shopt -s implicit_vars_local or shopt -s localize_func_implicit_vars.... whatever... Right now, in a function, you *can* use local in a function to make a local var. Thing is, both 'declare' and 'typeset' also make a *local* var in a function, unless the "-g" switch is used. I.e. All standard, overt ways (local declare typeset) of creating a var in a function all result in it being local, BUT, (and I think this is an ugly wart), any *implicit vars* without local, or the misleading declare or typeset, become global. examples: In these two for statements, used in functions, 'i' becomes global: for((i=0; i<10; ++i)); do : done for i in {1..10}; do : done And same with 'myarray': readarray myarray=$(echo "one";echo "two") and reads and assignments, and 'lets' read ln < <(echo "one"; echo "two") ln2="one two" read ln3 <<< "one two" but if this isn't a potential for confusion: > function aa { read ln < <(echo "one"; echo "two") ln2="12" read ln3 <<< "one two" ar1=(one two) typeset -i ln2=34 typeset -a ar1=(three four) } > whence aa aa is a function aa () { read ln < <(echo "one"; echo "two"); ln2="12"; read ln3 <<< "one two"; ar1=(one two); typeset -i ln2=34; typeset -a ar1=(three four) } > aa > declare -p ln ln2 ln3 ar1 declare -- ln="one" declare -- ln2="12" declare -- ln3="one two" declare -a ar1='([0]="one" [1]="two")' !!! -- sure looks like I was trying to set the "type" of ln2 and ar1... boy could that be confusing... .... So, how about a "shopt" to declare that **what's implicity declared in funcs, stays in funcs** maybe shopt -s vegasvars ?..... but seriously -- it's so odd that anything you declare explicitly becomes local, while implicit vars default to global -- I know standards and compat must keep it that way... BUT it would have made more sense to have implicit vars in a function always be 'local' and maybe have explicit declarators be global (which has effectively been done with -g)...but originally, I also thought it strange that 'declare/typeset' were equivalent to 'local' inside a function. This way, you wouldn't have to change any syntax parsing functions and there certain isn't ANYTHING that would look like perl, even though perl was originally designed to be like shell with many shell standard functions built-in. ???