Is this a bug in the Bash shell [closed] - bash

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Have I found a bug in bash?
I have created a folder named Test
cd Test/
rm -rf ../Test (Deleted the PWD while I was in that directory, as shown in image)

Not a bug, not related to bash either. You're current working directory (and all the environment variables that hold the path info in your shell) is simply pointing to a filesystem node that's been orphaned. Listing it will give you what's in the node, which is nothing because . and .. are gone (because it's orphaned). Note that rm removes everything in the directory before orphaning the node. Thus, ls gives you nothing.
Also note that when you try to create a file while inside the deleted directory with something like touch blah or mkdir blah, it'll give you a file not found error.
"orphaned" may not be the correct term, I'm simply using it to mean that it has no parent node.

Related

Is there any shorter syntax for changing several directory levels back up with bash cd? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
If I need to change to some directory several levels up, I usually do this in bash:
cd ../../../../some/other/folder
Since it is quite annoying to type all those periods and slashes, I was wondering if there is some shorter way to type it; like for example:
cd ..4/some/other/folder
I have not been able to find it so far from for example cd --help.
There's no standard way.
You can declare a function that takes a number of parent directories as the first argument, and the relative path as the second one:
cdu () {
local n=$1
local p=""
while ((n--)) ; do
p+=../
done
cd "$p/$2"
}
You can then shorten cd ../../../bin to cdu 3 bin
What I use is
alias ..='cd ..'
alias ...='cd ../..'
To get 6 levels up, I just type ... + Enter three times.
according to cd man page, the immediate answer is "no".
if it helps, you may add the following to your .bashrc:
export prev1=".."
export prev2="../.."
export prev3="../../.."
export prev4="../../../.."
and so on.
example:
export prev4="../../../.."
mkdir -p /1/2/3/4/5
cd /1/2/3/4/5
pwd => result is /1/2/3/4/5
cd $prev4
pwd => result is /1

bash LS command giving hidden folders in output [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am not sure when this behavior started but by typing the ls command, I am getting the following output:
$ls
./ ../ .DS_Store Books/
I am not very sure about the first three items and they always come in every folder. Can anyone explain me how to get rid of them? I am using OS X Yosemite
The first two: ./ and ../ are current directory and parent directory respectively. You can't get rid of them. The last one .DS_Store is probably some config file/directory which you can remove with:
rm -f .DS_Store # use -r if it's a directory
But be sure to check what's its for!
The bahaviour of ls is not the reason for the "extra" output. You probably have an alias something like:
alias ls='ls -a'
in your shell. To find out exactly what it's aliased to, do:
type ls

How do I delete this '# ... #' Emacs File? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
There is a file in my home directory that is called #snake#. I want to remove it but none of the regular remove commands will work. How can this "file" be removed without causing any damage, and what type of file is it?
It's an autosave file, it's there in case your computer crashes. You can delete these from emacs quite conveniently. Open up dired (C-x d) and press # to select all of them in the directory. Then x for delete.
Alternatively in a shell, just put the name in quotes, e.g. rm "#snake#"
The "problem" is that the # sign is interpreted as the start of a comment in a shell. Try enclose the file name in quotes, like:
rm "#snake#"

Shell: How to create the directory with slash and parentheses? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'd like to create the directory "Dir (A/B)" in "test" folder in one go with the following command:
$ mkdir -vp "test/dir (A/B)"
test
test/dir (A
test/dir (A/B)
Unfortunately it's creating 'dir (A' in 'test'.
I've tried to escape it, but without success e.g. mkdir -vp "test/dir (A\/B)".
When creating manually in Finder, it works.
How should I escape the arguments? Thanks.
I'm using bash shell.
Do:
$ mkdir -vp "test/dir (A:B)"
The directory will appear as dir (A/B) in Finder and file open dialogs, but dir (A:B) in shell and other Unix applications.
Note that this is very Mac-specific, it won't work on other flavors of Unix.
Although i would not recommend this, you can create a filename like this:
mkdir 'test:dir (A:B)'
# when creating missing folders
mkdir -pv 'test/dir (A:B)'
In the finder it will show as: "test/dir (A/B)"
but if you look in the bash shell (ls -al), you will see "test:dir (A:B)"

How to execute shell script in cygwin? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
the name.sh already save in C:\Documents and Settings\user, i type sh name.sh
sh: testing.sh: No such file or directory
any help will be appreciated!
You can just type ./name.sh and your script should run.
If your current directory is not in your $PATH, adding the ./ tells the shell to look there.
The other possibility is that you're not currently in the right directory. If the result of pwd shows you are not in C:\Documents and Settings\user, then you will need to cd to that directory, or move the script to whatever directory you are in.
Add ./ in front of the name. ./name.sh

Resources