Bash: Change to Directory with Space [duplicate] - bash

This question already has answers here:
How to cd into a directory with space in the name?
(18 answers)
Closed 9 years ago.
I have no idea what could be wrong here, I have just installed Ubuntu and I am trying to run a program called Exercise2.cpp. Exercise2.cpp is inside a folder called C++ Development in the Documents directory.
I can get as far as the Documents directroy, however when I try to change in to C++ Development it says " bash:cd: C++: No such file or directory"
What does this mean, I have been trying different things, like adding C++ Development in a quote but it still does not work.?

Escape the spaces with a backslash.
cd C++\ Development
In general, though, it's good practice to avoid using spaces in file and directory names. Avoiding spaces makes it much easier to use the simple UNIX tools to do sophisticated stuff with your data.

Related

How to `cd` to a directory with spaces? [duplicate]

This question already has answers here:
Bash script to cd to directory with spaces in pathname
(14 answers)
Closed 2 years ago.
I am trying to navigate the bash command line to a subdirectory of my /projects directory, and I keep getting 'No such file or directory'.
The ls command clearly shows the directory in existence.
What am I missing?
Note: I am trying to navigate to the directory to run npm tests, if that context matters :)
This may be due to the space in your directory name.
You can either rename it for easier access or just start writing the name and use autocompletion (with tab) to let the system write it properly for you.
If the above solutions still don't work, try to escape the space with a backslash (Content\ Creator) to see what happens.
You may try to put quotation marks around 'Content Creator' like that.
When you try to navigate to any directory, it is better you always use quotation marks even there is no space character. Because it could have similarity with a command. To prevent any trouble.

osx mkdir can not create folders at ~ [duplicate]

This question already has answers here:
"~/Desktop/test.txt: No such file or directory"
(2 answers)
Why isn't tilde (~) expanding inside double quotes? [duplicate]
(1 answer)
Closed 4 years ago.
I have a couple of scripts for configuring new computers. I have a section dedicated to osx, where I create specific osx stuff. I wanted to change the default location for screenshots,but first I need to create the required folder. However, when I try to create the folder at ~/Documents/screenshots I get a variety of errors:
If I just use mkdir, then it tells me that the file already exists
If I add the -p option then I get no error, but nothing happens, the file does not get created
I tried the same code on the console directly with identical results.
Here is a small part of the code. The get boolean response is just a small function that returs true or false depending if the user types Yes or No
#!/bin/bash
screenshotsFolder="~/Documents/screenshots"
if get_boolean_response "Create a folder for the screenshots at $screenshotsFolder?"; then
mkdir "$screenshotsFolder"
fi
I tried changing the name to a random one, but I get exactly the same results.
Any advice?

How can I access a directory that is in $HOME using bash? [duplicate]

This question already has answers here:
"~/Desktop/test.txt: No such file or directory"
(2 answers)
Why isn't tilde (~) expanding inside double quotes? [duplicate]
(1 answer)
Closed 4 years ago.
I'm new to Linux as well as bash. I made a script that accesses a folder that is located in the home directory, but the script will not always be called from the home directory. The prompt I'm getting when calling it from any subdirectories specifies that it can not find the file.
Here's an example of what I'm trying to do:
for entry in "~/.directory"/*
do
echo "$entry"
done
If I place the script in a subdirectory of /home and try to call it, the script is unable to find the directory. I know it exists as if I run ls ~/.directory in the subdirectory it is able to find the files and print them with no problem. Is there a different way I should be trying to access the directory in the bash shell? Thanks!
Voted to close my question. It seems rather specific to me, and the general solution was something I found earlier and was also posted in the comments below. I'll figure it out eventually -
Only unquoted tildes are expanded.
for entry in ~/".directory"/*

Why ./helloworld and not helloworld directly to run my program from terminal? [duplicate]

This question already has answers here:
Why do you need ./ (dot-slash) before executable or script name to run it in bash?
(9 answers)
Closed 8 years ago.
As the question asked I thought "." means the current directory so why can't we directly type helloworld to run the program?
Because '.', the current directory, is not in your environment's $PATH, which contains the list of paths where executables get searched. To see your PATH variable, type
echo $PATH
This is most likely for security reasons, to prevent execution of local executables named after system or other trusted installed ones. I have worked on systems where '.' was in the PATH and at the very least it lead to some confusing moments (the test utility being a favourite candidate for accidental replacement.)
I would advise against appending '.' to PATH for those reasons.

Is the convention for naming make files to use a capital 'm', such as Makefile? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Should I name “makefile” or “Makefile”?
What's the standard convention for make files as far as its capitalization. I've seen both Makefile and makefile. Does it depend on language? Project?
You can use either of them, but conventionally Makefile is preferred over makefile. If you have both Makefile and makefile in the same directory and you just type make then makefile is executed and Makefile is ignored.
It doesn't matter. The make program looks for either one. I personally prefer Makefile since I'm always on Linux and it shows up first in the directory listing since I use lower case on all of my .ccp and .h files.
I believe it is usually capitalized. At least on *nix systems.
Makefile (capitalized) is a standard in Unix world, where file system is case sensitive (i.e. makefile, MAKEFILE and Makefile are all different files). On Windows, it doesn't matter.

Resources