Weird behavior while moving a directory - Servers Administration, Networking, & Virtualization

Users browsing this thread: 2 Guest(s)
movq
Long time nixers
(30-09-2016, 10:20 AM)venam Wrote: the environment variables are the "database" of those shells

It would appear that, sometimes, this is indeed the case. For example, in eval.c of Bash:

Code:
/* Send an escape sequence to emacs term mode to tell it the
   current working directory. */
static void
send_pwd_to_eterm ()
{
  char *pwd, *f;

  f = 0;
  pwd = get_string_value ("PWD");
  if (pwd == 0)
    f = pwd = get_working_directory ("eterm");
  fprintf (stderr, "\032/%s\n", pwd);
  free (f);
}

Or jobs.c:

Code:
/* Return the working directory for the current process.  Unlike
   job_working_directory, this does not call malloc (), nor do any
   of the functions it calls.  This is so that it can safely be called
   from a signal handler. */
static char *
current_working_directory ()
{
  char *dir;
  static char d[PATH_MAX];

  dir = get_string_value ("PWD");

  if (dir == 0 && the_current_working_directory && no_symbolic_links)
    dir = the_current_working_directory;

  if (dir == 0)
    {
      dir = getcwd (d, sizeof(d));
      if (dir)
    dir = d;
    }

  return (dir == 0) ? "<unknown>" : dir;
}

Funny thing is, I don't see $PWD being used in the "pwd" shell builtin. Instead, it calls get_working_directory() as mentioned in my previous post, which, in turn, calls the syscall getcwd().

In German, there's the nice expression, "das ist organisch gewachsen" (literal translation something like "grown in an organic manner"), which basically is a euphemism for "this is a very old code base and 1000 people have hacked on it and nobody ever cared to refactor things". :-)


Messages In This Thread
RE: Weird behavior while moving a directory - by movq - 30-09-2016, 01:22 PM