www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/10/23/09:01:34

X-Authentication-Warning: kendall.sfbr.org: jeffw set sender to jeffw AT darwin DOT sfbr DOT org using -f
Date: Tue, 23 Oct 2001 07:57:09 -0500
From: JT Williams <jeffw AT darwin DOT sfbr DOT org>
To: djgpp AT delorie DOT com
Cc: "Mark E." <snowball3 AT bigfoot DOT com>
Subject: Re: bash 2.04: $# not preserved?
Message-ID: <20011023075709.A25230@kendall.sfbr.org>
Mail-Followup-To: djgpp AT delorie DOT com, "Mark E." <snowball3 AT bigfoot DOT com>
References: <20011018115345 DOT A21027 AT kendall DOT sfbr DOT org> <m6r8ttc1ccccafdl6gqm6d84tiftk5oq5t AT 4ax DOT com>
Mime-Version: 1.0
User-Agent: Mutt/1.2.5i
In-Reply-To: <m6r8ttc1ccccafdl6gqm6d84tiftk5oq5t@4ax.com>; from snowball3@bigfoot.com on Mon, Oct 22, 2001 at 03:09:37PM -0400
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

-: So -- going by the comment quoted above -- the Solaris example does
-: seem to report the correct value, but I can't find any code in Bash
-: that detects when the "dollar vars" have changed and behave like the
-: Solaris example.

It seems to be tied up with DESTRUCTIVE, in builtins/common.c (see
below).  Every instance of remember_args that I can find is called with
destructive=1, but it isn't clear (to me) if that is responsible for
the observed behavior.

jtw

---

/* Remember LIST in $0 ... $9, and REST_OF_ARGS.  If DESTRUCTIVE is
   non-zero, then discard whatever the existing arguments are, else
   only discard the ones that are to be replaced. */
void
remember_args (list, destructive)
     WORD_LIST *list;
     int destructive;
{
  register int i;

  for (i = 1; i < 10; i++)
    {
      if ((destructive || list) && dollar_vars[i])
        {
          free (dollar_vars[i]);
          dollar_vars[i] = (char *)NULL;
        }

      if (list)
        {
          dollar_vars[i] = savestring (list->word->word);
          list = list->next;
        }
    }

  /* If arguments remain, assign them to REST_OF_ARGS.
     Note that copy_word_list (NULL) returns NULL, and
     that dispose_words (NULL) does nothing. */
  if (destructive || list)
    {
      dispose_words (rest_of_args);
      rest_of_args = copy_word_list (list);
    }

  if (destructive)
    set_dollar_vars_changed ();
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019