> +1 and `cd -' has the similar problem.

So, I guess there are several cases to consider.

1.  CDPATH
2.  cdable_vars
3.  -
4.  cdspell

I have attached another patch that would prevent echoing the path in
all of these cases with the `-q` option.
--- builtins/cd.def.orig	2014-01-20 16:52:02.000000000 -0700
+++ builtins/cd.def	2014-01-20 20:31:49.000000000 -0700
@@ -92,6 +92,8 @@
 	links
     -e	if the -P option is supplied, and the current working directory
 	cannot be determined successfully, exit with a non-zero status
+    -q  prevent the working directory from being echoed when DIR
+	is found using - or CDPATH or spell correction or a variable name
 
 The default is to follow symbolic links, as if `-L' were specified.
 
@@ -187,7 +189,7 @@
      WORD_LIST *list;
 {
   char *dirname, *cdpath, *path, *temp;
-  int path_index, no_symlinks, opt, lflag;
+  int path_index, no_symlinks, opt, lflag, qflag;
 
 #if defined (RESTRICTED_SHELL)
   if (restricted)
@@ -198,9 +200,10 @@
 #endif /* RESTRICTED_SHELL */
 
   eflag = 0;
+  qflag = 0;
   no_symlinks = no_symbolic_links;
   reset_internal_getopt ();
-  while ((opt = internal_getopt (list, "LP")) != -1)
+  while ((opt = internal_getopt (list, "LPq")) != -1)
     {
       switch (opt)
 	{
@@ -213,6 +216,9 @@
 	case 'e':
 	  eflag = 1;
 	  break;
+	case 'q':
+	  qflag = 1;
+	  break;
 	default:
 	  builtin_usage ();
 	  return (EXECUTION_FAILURE);
@@ -250,7 +256,7 @@
 #if 0
       lflag = interactive ? LCD_PRINTPATH : 0;
 #else
-      lflag = LCD_PRINTPATH;		/* According to SUSv3 */
+      lflag = qflag ? 0 : LCD_PRINTPATH;  /* According to SUSv3 */
 #endif
     }
   else if (absolute_pathname (list->word->word))
@@ -274,7 +280,7 @@
 		 is used to find the directory to change to, the new
 		 directory name is echoed to stdout, whether or not
 		 the shell is interactive. */
-	      if (opt && (path = no_symlinks ? temp : the_current_working_directory))
+	      if (opt && !qflag && (path = no_symlinks ? temp : the_current_working_directory))
 		printf ("%s\n", path);
 
 	      free (temp);
@@ -323,7 +329,8 @@
       temp = get_string_value (dirname);
       if (temp && change_to_directory (temp, no_symlinks))
 	{
-	  printf ("%s\n", temp);
+	  if (!qflag)
+	    printf ("%s\n", temp);
 	  return (bindpwd (no_symlinks));
 	}
     }
@@ -336,7 +343,8 @@
       temp = dirspell (dirname);
       if (temp && change_to_directory (temp, no_symlinks))
 	{
-	  printf ("%s\n", temp);
+	  if (!qflag)
+	    printf ("%s\n", temp);
 	  return (bindpwd (no_symlinks));
 	}
       else

Reply via email to