Index: trunk/Ohana/src/opihi/lib.shell/ListOps.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/ListOps.c	(revision 40651)
+++ trunk/Ohana/src/opihi/lib.shell/ListOps.c	(revision 40652)
@@ -213,4 +213,5 @@
       if (!strcmp (temp, "-x")) goto escape;
       if (!strcmp (temp, "-glob")) goto escape;
+      if (!strcmp (temp, "-file")) goto escape;
       if (!strcmp (temp, "-split")) goto escape;
       if (!strcmp (temp, "-join")) goto escape;
Index: trunk/Ohana/src/opihi/lib.shell/expand_vars.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/expand_vars.c	(revision 40651)
+++ trunk/Ohana/src/opihi/lib.shell/expand_vars.c	(revision 40652)
@@ -23,7 +23,13 @@
 
   /* look for form $a$b..$n and expand only the last ones */
+
+  // expand from line (L) into newline (N)
   for (L = line, N = newline; *L != 0; N++, L++) {  /* loop until end of line */
+
+    // look for end of line or start of variable ($)
     for (done = FALSE; !done;) {
       if (*L == 0) done = TRUE;
+
+      // look for the last $var
       if (*L == '$') {
 	V1 = aftervar(L);
@@ -31,4 +37,6 @@
 	if (V1 == NULL) done = TRUE;
       }
+
+      // copy into newline
       if (!done) { 
 	*N = *L;
@@ -44,4 +52,5 @@
     }
 
+    // end of the line
     if (*L == 0) break;
 
@@ -50,5 +59,5 @@
     /* note: V1 points to a fraction of L, it does not need to be freed */
 
-    /* no variable name */
+    /* no variable name, e.g., word$ or $$.  keep the $ intact */
     if (V0 == NULL) {
       *N = *L;
@@ -62,5 +71,5 @@
     }
 
-    /* variable assignment (skip these variables) */
+    /* variable assignment ($ at start of the line) : skip these variables */
     if ((L == line) && (V1 != NULL)) {
       int isAssignment;
@@ -86,4 +95,23 @@
     }
 
+    // V0 is the name of a variable.  
+    // $tree_$branch_$twig should work (e.g,. $foo_bar_baz exists, $twig = baz, $foo_bar_$twig )
+    // $ref = name; echo $$ref:n word  need to expand $ref to get value of $name:n
+
+    // examples of valid nested variables, given $name = value, $ref = name, $name:n = 1, $name:0 = a, $i = 0
+    // $$ref -> value
+    // $$ref:n -> $name:n
+    // $$ref:$i -> $$ref:0 $name:9
+    
+    // is there a $ in the previous character?
+    // do not include ':' in the variable name
+    int isRef = FALSE;
+    if ((L != line) && (L[-1] == '$')) {
+      free (V0);
+      V0 = thisref(L);
+      isRef = TRUE;
+    }
+
+    // check for macro-arguments ($1, $2)
     found = TRUE;
     for (c = V0; isdigit(*c); c++); /* test if this is a macro argument variable (ie, $1.2) */
@@ -100,4 +128,6 @@
       }
     }
+
+    // we have something of the form $word, where V0 now is word.  expand it out:
 
     Val = get_variable_ptr (V0);
@@ -117,10 +147,14 @@
     N--; /* we overshoot on last loop */
 
-    /* skip past the variable in the source line */
+    /* skip past the variable (or reference) in the source line */
     /* L currently points at $ */
     L++;
     if (*L == '?') L++;  /* skip past ? in $?name */
 
-    while (ISVAR(*L)) L++;
+    if (isRef) {
+      while (ISREF(*L)) L++;
+    } else {
+      while (ISVAR(*L)) L++;
+    }
     L--; /* we overshoot */
 
Index: trunk/Ohana/src/opihi/lib.shell/opihi.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/opihi.c	(revision 40651)
+++ trunk/Ohana/src/opihi/lib.shell/opihi.c	(revision 40652)
@@ -8,7 +8,7 @@
   pid_t ppid;
 
-  general_init (&argc, argv);
-  program_init (&argc, argv);
-  startup (&argc, argv);
+  general_init (&argc, argv); // in startup.c : init drand48, signals, gprint, opihi_error
+  program_init (&argc, argv); // in mana.c.in, dvo.c.in, etc
+  startup (&argc, argv);      // in startup.c : set global variables, load history, --norc, --only
   prompt = get_variable("PROMPT");
   history = get_variable("HISTORY");
Index: trunk/Ohana/src/opihi/lib.shell/string.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/string.c	(revision 40651)
+++ trunk/Ohana/src/opihi/lib.shell/string.c	(revision 40652)
@@ -114,4 +114,27 @@
 }
 
+/* take a pointer to the beginning of a variable (ie $foo)
+and extract only the variable name (eg, foo) */
+
+char *thisref (char *string) {
+
+  int i, start;
+  char *word;
+
+  if (string == (char *) NULL) return ((char *) NULL);
+  if (string[0] != '$') return ((char *) NULL);
+
+  /* special case $?name : check that name is valid */
+  start = 1;
+  if (string[1] == '?') start = 2;
+
+  for (i = start; ISREF(string[i]); i++);
+  if (i == start) return ((char *) NULL);
+
+  /* the ? is part of the variable */
+  word = strncreate (&string[1], i - 1);
+  return (word);
+
+}
 
 /**********************************************************************/
