dysbulic
dysbulic

Reputation: 3105

Changing to a directory named -

I have a script that traverses the directory tree using pushd and popd. It is choking on a directory named -. I have tried:

pushd -- -

But the dash is still interpreted as an option (and the previous directory is pushed on the stack). I have the same problem with cd.

Upvotes: 2

Views: 117

Answers (1)

DigitalRoss
DigitalRoss

Reputation: 146073

In different flavors, this is an interview question. (How would I remove a file named "-"?)

$ cd ./-
$ pushd ./-
$ pushd ./$next
$ pushd $PWD/- # Yay JL
$ pushd /what/ever/-

Upvotes: 6

Related Questions