Solution – string not in pwd

string not in pwd

You may get an ‘string not in pwd’ error when you are using a mac. When you want to navigate a folder in the Mac terminal, you will need the pwd command, which can show you which directory or folder you are in. If you already tried the pwd command, you will know that it can show up the exception ‘string not in pwd’.

Although you find the error frustrating, it is not a hard nut to crack. It is like using a command prompt that you may have seen in Windows. Today, we help you find the solution to this problem. Let’s figure out how to fix the ‘string not in pwd’ issue

How to Fix ‘string not in pwd’

If we want to fix the issue, we have to look for the example of how the error occurs and then find the best possible solutions to tackle the error.

How Error Occurs

If you are trying to change the directory to a specific folder on the desktop terminal, you may have the ‘string not in pwd’ error. Suppose, you are changing the directory to a folder winter 2022 classes.

You are trying to open ‘winter 2022 classes’ from your desktop like this:

cd desktop 
cd winter 2022 classes

and then you end up with the following error

string not in pwd: winter  
or 
too many arguments 

Now, let’s shed light on the solutions of this error

Solution 1 – Use quotes

The cause of ‘string not in pwd’ is because the cd command is confused thinking it to be three different directories like winter, 2022, and classes. And, this has to be a single command. To solve the error, you need to add the quotes to make it a single directory. Follow the below command

cd "winter 2022 classes"

the quotes can easily fix the error.

Solution 2 – Fill the spaces

This is another solution that you can also try. To make it a single directory instead of three different directories, you need to fill the spaces. The reason for filling the space is to give a clear direction to the cd command. Check out how can you do it

cd winter\ 2020\ classes

Solution Scenario

To summarize both above solutions, let’s have a look at the code to understand it better

The directory I'm trying to cd into is "! java core" 
using "cd ! js basics" which won't work.

I was able to access the folder by escaping the space 
using this: \

USE THIS INSTEAD "cd \!\ java\ core"
each \ escapes the command the code reads and instead 
reads it as text.

Conclusion

And that’s how you can code to remove an ‘string not in pwd’ error. The issue can be fixed easily with the above solutions. You can go ahead with the article any time when you want to remove the error to take the reference.

I hope you find it helpful!

Your comments are always entertained so don’t hesitate to drop a message below!

Posted in Mac

Leave a Reply

Your email address will not be published. Required fields are marked *