[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

COMP_WORDS, namerefs and readonly variables

From: Grisha Levit
Subject: COMP_WORDS, namerefs and readonly variables
Date: Fri, 24 Feb 2017 18:39:13 -0500

In bind_comp_words, the readonly attribute is unconditionally removed from COMP_WORDS, even if that variable is a nameref.  This allows unsetting the readonly attribute on any arbitrary variable.

    v = find_variable ("COMP_WORDS");
    if (v == 0)
      v = make_new_array_variable ("COMP_WORDS");
    if (readonly_p (v))
      VUNSETATTR (v, att_readonly);

For example:

    $ readonly var=foo
    $ declare -n COMP_WORDS=var
    $ f() { :; }
    $ compgen -F f .
    bash: compgen: warning: -F option may not work as you expect
    $ declare -p var
    declare -a var=([0]="foo")

I'm not sure why shooting yourself in the foot by making COMP_WORDS readonly should be forbidden, since the readonly attribute is not removed from any of the other COMP_* variables.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]