0

In a bash shell on a MacOS machine, I can see by typing ls that there is a director Application Support:

$ ls
Accounts                FontCollections     PreferencePanes
Application Scripts     Fonts               Preferences
Application Support     GameKit             Printers
Assistant               Google              PubSub
Assistants              Group Containers    Safari
Audio                   IdentityServices    SafariSafeBrowsing
Caches                  Input Methods       Saved Application State
Calendars               Internet Plug-Ins   Screen Savers
CallServices            Keyboard            Services
ColorPickers            Keyboard Layouts    Sharing
Colors                  KeyboardServices    Sounds
Compositions            Keychains           Spelling
Containers              LanguageModeling    Suggestions
Cookies                 LaunchAgents        SyncedPreferences
CoreFollowUp            Library             VirtualBox
Developer               Logs                Voices
Dictionaries            Mail                WebKit
F5Networks              Messages            com.apple.internal.ck
Family                  Metadata            iMovie
Favorites               Mobile Documents
FileProvider            Passes

However, if I trying to cd into this directory using either quotes or escape characters as described in How to cd to a directory that contains a space in its name?, I still get an error:

LM-SJN-21018636:Library kupeek$ cd "Application Support"
-bash: cd: Application: No such file or directory
LM-SJN-21018636:Library kupeek$ cd Application\ Support
-bash: cd: Application: No such file or directory

It seems like bash is not 'picking up' the quotes or escape characters and is instead looking for a directory called "Application". Any ideas why this is not working?

  • 2
    Perhaps you have an alias or similar for cd that is badly written. What does command -v cd print? – meuh Nov 18 '18 at 19:22
  • 2
    I would suspect a poorly written function. And I think command -v cd from the first comment should be command -V cd (capital V); type -a cd should also work. – Kamil Maciorowski Nov 18 '18 at 19:27
  • 1
    What happens if you "autofill" it with the Tab-key? Same error? – Aulis Ronkainen Nov 18 '18 at 19:45
5

Your cd may be a poorly defined function or alias. Run type -a cd to find out.

A possible alias is explained in this other answer. My answer concentrates on shell functions.

For example if the function used

  • command cd $* (command builtin explained here) or
  • command cd $@ or
  • command cd $1

instead of correct

  • command cd "$@" or
  • command cd "$1" (not as good as the above, still not fatal)

and your Bash didn't throw too many arguments (pre-4.4 version, see this question), the behavior would be exactly as you described because Application Support being a single argument to the function would undergo word splitting inside the function itself, so command cd would see Application as its first argument.

If your cd is indeed a poorly defined function, you should track the place where it is defined and fix it. An ad hoc solution would be to add the command word before cd, like this:

command cd "Application Support"

or

command cd Application\ Support

(This will also work if alias is the culprit).

1

Try using more than one set of quotes,

e.g. put the name in single quotes within double quotes:

cd "'Application Support'"

"An argument enclosed in double quotes presents itself as a single word, even if it contains whitespace separators." Advanced Bash-Scripting Guide

Using two sets of quotes (quotes within quotes) is a viable workaround, assuming that the problem here is that the original cd command has been aliased. The following definition

alias cd='eval command cd'

would reproduce the problem reported here (in pre-4.4 version of Bash, see this answer). It happens that eval parses the command line for the second time and, on the first pass of parsing, one layer of quoting is removed. Using two sets of quotes works because, removed the first set of quotes, eval will pass the argument with the second set of quotes to cd.

If such alias is the case, the best solution is to fix it in the first place.

  • Simple. I believe the problem here is that the original "cd" command has been aliased. The alias gets the path string as argument and it gets it correctly if you put the first set of quotes. Then it passes it to "cd" but it goes there without quotes and fails. If you put two sets of quotes, the alias gets the string with the first set and then it passes it to "cd" with the second set of quotes and... Magic, it works! – GiopperOne Nov 18 '18 at 23:32
  • Thanks for your suggestion, I edited my answer and added a reference. I don't have to explain here how to modify a "cd" alias, that would be off-topic. I am answering the question "Any ideas why this is not working?", the answer is because using single quotes alone. Put it within double quotes and it will work. – GiopperOne Nov 19 '18 at 5:23
  • Good job! Thank you for cooperation. – Kamil Maciorowski Nov 19 '18 at 7:00
0

There could be more blanks or other non-printable chars that you don't see. Try cd Application*Scrip* or similar.

  • 1
    This could be it in some other case, but not in this particular one. Note the message is -bash: cd: Application: No such file or directory, not -bash: cd: Application Support: No such file or directory. The command doesn't see the whole argument string in the first place. – Kamil Maciorowski Nov 18 '18 at 19:38
0

IF your cd isn't a weird alias, then I'd just use TAB with bash's autocomplete (if it's enabled) to fill a working format for you.

Typing

cd ApTAB

looks like it should autofill to something like

cd Application\ S

(If you do have a weird cd alias, then appending Kamil's answer of typing command cd A... should work with TAB's too)

and then wait for you to type more of the wanted name (followed by anoter TAB to autocomplete the rest). Or just typing TAB once or twice more will display your available options.

(I'd also not use plain ls, but ls -la or maybe ls -1 instead to see only one entry per line, your ls output isn't clear)

  • This may be a good advice in a general case (i.e. for future users with similar problems) but I doubt it will immediately help the OP. Note the message is Application: No such file or directory, not Application Support: No such file or directory. If the directory name in the command line simply didn't match the actual name, cd would still comply about the whole argument being wrong. I don't downvote answers that may apply to very similar problems, still I'm noting they don't entirely fit the OP's issue and they cannot explain the root of it. – Kamil Maciorowski Nov 19 '18 at 9:35
  • I thought so too, but it's a little annoying when the title doesn't fully match the real problem ("My cd is broken"), and tab complete was only mentioned briefly in a comment, so a fuller answer for the "title problem" seemed appropriate. – Xen2050 Nov 19 '18 at 11:59
-1

It's because you're missing by one word. Try using:

cd "Application Support GameKit"
  • I'm repeating myself: This could be it in some other case, but not in this particular one. Note the message is -bash: cd: Application: No such file or directory, not -bash: cd: Application Support: No such file or directory. The command doesn't see the whole argument string in the first place. – Kamil Maciorowski Nov 18 '18 at 19:39
  • You mis-read the OP; they're 2 different columns – Tetsujin Nov 18 '18 at 19:39

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.