bug-bash
[Top][All Lists]
Advanced

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

Patch against 2.05 Bash to make cd take 2 Args like ksh


From: Eli
Subject: Patch against 2.05 Bash to make cd take 2 Args like ksh
Date: Fri, 22 Jun 2001 14:38:17 -0400

*** origBash/bash-2.05/builtins/cd.def  Wed Oct 11 11:10:20 2000
--- bash-2.05/builtins/cd.def   Fri Jun 22 14:31:08 2001
***************
*** 187,192 ****
--- 187,225 ----
        }
        lflag = interactive ? LCD_PRINTPATH : 0;
      }
+   else if (list->next)
+     {
+       /* if next then 2 args, so replace in PWD arg1 with arg2 */
+       int beginLen, oldLen, newLen, endLen;
+       char *replace;
+       path = get_string_value ("PWD");
+       if (( replace = strstr( path,list->word->word)) == (char *)0 )
+         {
+          builtin_error ("Couldn't find arg1 in PWD");
+          return (EXECUTION_FAILURE);
+       }
+       beginLen = replace - path;
+       oldLen = strlen( list->word->word);
+       newLen = strlen( list->next->word->word);
+       endLen = strlen( path + beginLen + oldLen ) + 1 ;
+ 
+       dirname = xmalloc( beginLen + newLen + endLen );
+       /* copy path up to begining of string to replace */
+       memcpy( dirname, path, beginLen );
+ 
+       /* then add new replacement string */
+       memcpy( dirname + beginLen, list->next->word->word, newLen );
+ 
+       /* finally add end of path after replacement */
+       memcpy( dirname + beginLen + newLen, path + beginLen+
oldLen,endLen);
+ 
+       printf("%s\n",dirname);
+       if (change_to_directory (dirname, no_symlinks))
+       {
+          free(dirname);
+          return (bindpwd (posixly_correct || no_symlinks));
+       }
+     }
    else if (absolute_pathname (list->word->word))
      dirname = list->word->word;
    else if (cdpath = get_string_value ("CDPATH"))



reply via email to

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