1

Similar to this question, I made a directory called Test Directory - 1 and I can't cd to it.

I have tried:

  • cd Test\ Directory\ \-\ 1/ (suggested by tab completion)
  • cd "Test Directory - 1"
  • cd "Test Directory - 1/"
  • cd 'Test Directory - 1'
  • cd 'Test Directory - 1/'
  • cd 'Test Directory \- 1'

All of these fail and throw the error:

Usage: cd [-LP] [directory]

Or: cd [ options ] old new

How do I interact with this directory?

Community
  • 1
  • 1
alex
  • 6,818
  • 9
  • 52
  • 103
  • FWIW they all work in bash on OS X... – jonrsharpe Jan 16 '18 at 18:38
  • @jonrsharpe This is a ksh question. I'll try bash instead. **EDIT**: bash worked. I'm going to leave the question open to get an idea as to why this doesn't work in ksh. – alex Jan 16 '18 at 18:39
  • All (not the last) comands work in my ksh (93u+ 2012-08-01). The last one has `cd: Test Directory \- 1: [No such file or directory]` – ULick Jan 16 '18 at 19:17
  • 1
    Agree that this should work in `ksh` as well, and that the last item should fail (as it does), becuase of the extra '\' quoting char. Please edit your Q to include output of `echo ${.sh.version); uname -srv` . Check for alias/functions that might be overriding the built-in `alias | grep 'cd ' ; functions | grep 'cp '`. Good luck – shellter Jan 16 '18 at 19:35

1 Answers1

1

What system you are on makes a difference here. On my Mac, I have no problem with the directory in quote or without quotes:

cd Test\ Directory\ -\ 1

My understanding is that the spaces are the only characters you have to escape because the shell will split arguments with whitespace. You do not need to escape the - because it has no meaning in the cd shell built-in as it would with say grep.

In general, I would list directories and then process them putting escape characters, i.e. backslash, in front of problematic characters.

BruceK
  • 11
  • 2