Index: /trunk/Ohana/src/opihi/cmd.basic/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/cmd.basic/Makefile	(revision 16167)
+++ /trunk/Ohana/src/opihi/cmd.basic/Makefile	(revision 16168)
@@ -47,4 +47,5 @@
 $(SRC)/substr.$(ARCH).o     \
 $(SRC)/strpop.$(ARCH).o     \
+$(SRC)/strsub.$(ARCH).o     \
 $(SRC)/usleep.$(ARCH).o     \
 $(SRC)/sleep.$(ARCH).o	     \
Index: /trunk/Ohana/src/opihi/cmd.basic/init.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.basic/init.c	(revision 16167)
+++ /trunk/Ohana/src/opihi/cmd.basic/init.c	(revision 16168)
@@ -34,4 +34,5 @@
 int substr_func     PROTO((int, char **));
 int strpop          PROTO((int, char **));
+int strsub          PROTO((int, char **));
 int wait_func  	    PROTO((int, char **));
 int which      	    PROTO((int, char **));
@@ -76,4 +77,5 @@
   {"substr",        substr_func,        "substring"},
   {"strpop",        strpop,             "pop a string"},
+  {"strsub",        strsub,             "replace instances of a key in a string"},
   {"wait",    	    wait_func,          "wait until return is typed"},
   {"which",   	    which,              "show command *"}
Index: /trunk/Ohana/src/opihi/cmd.basic/strsub.c
===================================================================
--- /trunk/Ohana/src/opihi/cmd.basic/strsub.c	(revision 16167)
+++ /trunk/Ohana/src/opihi/cmd.basic/strsub.c	(revision 16168)
@@ -1,7 +1,9 @@
 # include "basic.h"
 
-int strpop (int argc, char **argv) {
+int strsub (int argc, char **argv) {
 
-  char *p, *q, *string;
+  int N, Nkey, Noutput;
+  char *varName;
+  char *p, *q, *input, *output, *key, *value;
 
   // clear all sections
@@ -13,34 +15,45 @@
   }
 
-  if (argc != 2) {
-    gprint (GP_ERR, "USAGE: strsub (string) (replace) (value) [-var out]\n");
+  if (argc != 4) {
+    gprint (GP_ERR, "USAGE: strsub (string) (key) (value) [-var out]\n");
+    gprint (GP_ERR, "  replace instances of 'key' with the 'value'\n");
     return (FALSE);
   }
 
-  /* string is a copy of the value on the variable stack */
-  string = get_variable (argv[1]);
-  if (string == NULL) return (FALSE);
+  // input string 
+  input = argv[1];
   
-  /* thisword is an allocated string */
-  p = thisword (string);
+  // find this in the string
+  key = argv[2];
+  Nkey = strlen(key);
 
-  q = nextword (string);
-  if (q == NULL) {
-    set_str_variable (argv[1], "NULL");
-  } else {
-    set_str_variable (argv[1], q);
+  // replace with this
+  value = argv[3];
+
+  Noutput = MAX (16, strlen(input));
+  ALLOCATE (output, char, Noutput);
+  memset (output, 0, Noutput);
+
+  // 0123456789
+  // wordKEYnew
+  // p = 0, q = 4, q-p = 4 -> p = 7
+
+  p = input;
+  while (*p && ((q = strstr (p, key)) != NULL)) {
+    output = opihi_append (output, &Noutput, p, q);
+    output = opihi_append (output, &Noutput, value, strlen(value));
+    p = q + Nkey;
+  }
+  if (*p) {
+    output = opihi_append (output, &Noutput, p, strlen(p));
   }
   
-  if (argc == 3) {
-    set_str_variable (argv[2], p);
+  if (varName) {
+    set_str_variable (varName, output);
   } else {
-    gprint (GP_LOG, "%s\n", p);
+    gprint (GP_LOG, "%s\n", output);
   }
 
-  free (p);
-  free (string);
+  free (output);
   return (TRUE);
 }
-
-strsub /data/@HOST@ @HOST@ foobar
-
