Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: cd "" foo bug?



On Mon, Jan 11, 2016 at 11:58:04AM +0000, Peter Stephenson wrote:
> On Mon, 11 Jan 2016 12:20:26 +0100
> # should handle options up here...
> 
> if (( $# == 2 )); then
>   local src=$1 rep=$2 dir
>   integer n=1
>   while true; do
>     dir=${(I:${n}:)PWD/$src/$rep}
>     if [[ $dir = $PWD ]]; then
>       print -r "$0: no replacements found: $PWD / \"$src\" / \"$rep\"" >&2
>       return 1
>     fi
>     if [[ -d $dir ]]; then

>       cd -- $dir

How is this supposed to work?  The manual does not mention "--":

  http://zsh.sourceforge.net/Doc/Release/Shell-Builtin-Commands.html#Shell-Builtin-Commands

The shell silently accepts it but seems to completely ignore it:

  $ zsh --version
  zsh 5.0.2 (s390x-ibm-linux-gnu)

  $ mkdir /tmp/-1
  $ builtin cd /tmp
  # note: pushdminus and autopushd are on
  $ builtin cd -- -1
  ~
  $ pwd
  /home/<user>

But on the other hand it works with -- as the directory name:

  $ mkdir /tmp/--
  $ builtin cd /tmp
  $ builtin cd -- --
  $ pwd
  /tmp/--

As far as I can see there is no direct way to pass -<n>, +<n>, -q,
-s, -L or -P as a directory argument to the cd builtin.  -- is
undocumented but works like in many other Unix tools, but not when
used with one of the options above.  -- works fine with
two-argument cd calls.

>       return
>     fi
>     (( n++ ))
>   done
> else
>   builtin cd "$@"
> fi

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany



Messages sorted by: Reverse Date, Date, Thread, Author