For a while now I'm experiencing an annoying bash-completion problem, namely it doesn't work when a path contains an escaped space. For example, I am in /cygdrive/c and type
$ cd Pro
pressing Tab key completes to "cd Program", pressing twice shows all directories with this "Program" prefix:
Program Files/ Program Files (x86)/ ProgramData/
I want to cd to "Program Files" so I type
$ cd Program\
(with space after backslash) and from now on pressing Tab does nothing. It used to work some time ago but I cannot identify when exactly it stopped. Any hints on what can be the cause of this?
It looks like the there is a problem with the bash_completion package. I was having your problem with cd but not other programs like ls. You can either remove that package or put complete -r cd in your .bashrc.
Related
I did
brew install python3
when i run python --version it shows 2.7
Document says:
If you still see 2.7 ensure in PATH /usr/local/bin/ takes precedence over /usr/bin/
How do I go about this?
First, you'll want to verify the problem is as stated.
Try running e.g.
> echo $PATH
/usr/local/bin:/Users/jsh/code/go/bin:/usr/bin:/bin:/usr/local/sbin:/usr/texbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
You'll notice that the output is a series of paths separated by ':' characters. Your terminal looks in those locations, in order, until it finds something that matches your command (in this case 'python') and it runs that binary.
This means that earlier items take precedence over later items. You'll note that in my listing, /usr/local/bin/ is at the very beginning, and /usr/bin/ is somewhat later in the listing.
If your listing also has this ordering, you're getting a misleading message, and will need to dig deeper. Hopefully, however, you will find that either /usr/local/bin/ isn't in your list at all, or it is for some reason occurring after /usr/bin/. That's good -- you've now identified the problem -- and we're now at your nominal question, vis: how do you change the ordering?
The environment variable $PATH can be modified by any number of startup tools. There are probably ways to systematically observe all the things that are editing your $PATH, but what I would do is
1) Search in your home directory for things that might be messing with $PATH, something like:
> egrep -d skip -l PATH .*
.gvimrc
.zhistory
.zshrc
.zhistory, here, is a red herring -- it's a list of the stuff I've done in my shell, so I can ignore it.
.gvimrc is also misleading, because it's actually setting $GOPATH, not $PATH.
So the only configuration file I have messing with my $PATH, at least in my home directory, is .zshrc, the config file for my shell itself. This is typically true, and you can just start by assuming this, but it's always good to do a quick search...
2) Edit the responsible file until it is setting PATH so that /usr/bin/local/ precedes /usr/bin/. Open the file in your choice of editor and either modify the line that sets PATH, or add a line that prepends /usr/local/bin/ to PATH (if you go with the latter, make sure that prepend happens after all other modifications to the variable).
For example, my .zshrc has a block like this:
# PATH setup (Starting with hard reset)
export PATH=/sbin
export PATH=/usr/sbin:$PATH
export PATH=/usr/texbin:$PATH
export PATH=/usr/local/sbin:$PATH
export PATH=/bin:$PATH
export PATH=/usr/bin:$PATH
export PATH=/Users/jsh/code/go/bin:$PATH
export PATH=/usr/local/bin:$PATH
(Note that the FINAL LINE is the one prepending /usr/local/bin !)
Then restart your shell (or prompt it to reload the config file, but I'm betting if you knew how to do that, you wouldn't have needed this guidance!). Now re-run 'echo $PATH', and verify that the ordering is correct. If so, try running python again, and you should have an uncle named Bob.
Good luck!
kdevelop provides this AppImage binary:
wget -O KDevelop.AppImage https://download.kde.org/stable/kdevelop/5.1.1/bin/linux/KDevelop-5.1.1-x86_64.AppImage
chmod +x KDevelop.AppImage
./KDevelop.AppImage
It works well. So I want to make a soft link called kd to that binary in /usr/bin, eg:
/usr/bin/sudo ln -s KDevelop-5.1.1-x86_64.AppImage kd
Now if I run kd file1, I'd expect that it would open a file name file1 in the current folder, but it always tries to open a file name file1 in my home folder - which is not where it should be.
Is there some way to fix this issue?
Some possible causes:
The application always assumes that you want to open files in your home directory, effectively or literally prepending $HOME to the path. This would be a bug in any *nix program, and should be reported.
The application behaves differently when $(basename "$0") is not KDevelop.AppImage (what #Scheff said).
You are actually running a different kd.
Possible workarounds/investigations:
Pass the full path to the file on the command line. If it tries to open /home/you//full/path/you/provided it is obviously buggy, and you have a test case. If it does not, then there might be some gotcha to what your $PWD actually is. Try checking its value before running.
Symlink with the same name, using sudo ln -s KDevelop-5.1.1-x86_64.AppImage /usr/bin, and try running that. If it behaves the same, you've at least proven that the symlink is not the problem.
Run type -a kd and verify that your /usr/bin/kd comes up first. If not there might be an alias or shell built-in which takes precedence.
That said, what is the actual error message?
What does cd - exactly do ? ( the change directory command, plus a dash )
I noticed that if I run it in my /home/user folder repeatedly it outputs either /home/user or /home, this changes if I run it from a different folder.
cd -
pop the last directory you were from the stack of directory. It's like hitting "back" on the browser.
Exemple :
you are in /user/alex
you can test that with :
pwd
that give you
/user/alex
then if you do
%cd project1/subfolder
%pwd
/user/alex/project1/subfolder
%cd subsubfolder
%pwd
/user/alex/project1/subfolder/subsubfolder
%cd -
pwd
/user/alex/project1/subfolder
cd -
pwd
/user/alex
NB : it's not going back a level upper in the folder hierarchy. it's going to the previous current folder. ( a level upper is cd .. ).
The syntax
cd -
allows you to switch back to the "last directory you were in when you changed to the current directory". Running the command twice allows you to switch back to the current directory (since the current directory would then become the "last directory you were in when you changed to the current directory").
This is very useful if you are in a very long directory which you don't want to type out over and over, and you go to another lengthy named directory. Instead of retyping it, you can just do a 'cd -', which is similar to how some people use the alt-tab (or command-tab) to switch between applications. This key combo shortcut lets you essentially toggle between the last two applications.
cd stands for Change Directory
It is used to navigate arond your folders
So if you're in /home/user and have a folder in that directory called 'top-secret', you would access it by typing:
cd /top-secret
I am building a source file with some alias to executable files (these are working just fine) and assigning directories to variables in order to get to the directory quicker, with less typing. For example, if I source example.source:
#!/usr/bin/bash
mydir="/path/to/some/dir"
I can get to /path/to/some/dir with
cd $mydir
However, I am not being able to use tab complete to navigate through other sub-directories like I would do by typing the complete path. I mean, if I use the tab key to complete the variable I get cd $mydir but not cd $mydir/ (I have to delete the last space character and manually type the slash / to see the next sub-directories). Hope this is an understandable question. Is there any workaround for this?
EDIT: the linux distribution I'm using is Slackware Linux 3.2.31.c x86_64 GenuineIntel GNU/Linux
EDIT2: GNU bash, version 4.2.37(2)-release
Apparently this feature is starting to be implemented in bash 4.3, release 26-Feb-2014 09:25.
Reading the NEWS file in bash 4.3 I found this:
i. The word completion code checks whether or not a filename
containing a
shell variable expands to a directory name and appends `/' to the word
as appropriate. The same code expands shell variables in command names
when performing command completion.
Unfortunately I cannot do a de novo installation of bash (because I'm working on a server) but I hope this can help others.
If I understand your question, then I believe it can be solved by putting this at the top of your example.source. This will list your contents every-time that you cd.
#!/usr/bin/bash
# Make cd change directories and then list the contents
function cd() {
builtin cd $*;
ls;
}
mydir="/path/to/some/dir"
cd $mydir
My other suggestion is to try to put cd within your alias. Something like this:
mydir="cd /path/to/some/dir"
$mydir
Let's say we have a directory called foo: /home/user/foo. After I cd to foo I change execute permission for current directory: chmod -x ../foo. After removing execute permission I cannot access any files, which is normal. But when I write "cd ..", I can change directory. Why does "cd .." work?
At least in bash, cd .. is implemented specially. It doesn't read the .. directory from the current directory; rather, it computes the name of the parent directory by removing the trailing component.
Quoting builtins/cd.def from the bash 4.3 sources:
The default is to follow symbolic links, as if -L' were specified.
..' is processed by removing the immediately previous pathname
component back to a slash or the beginning of DIR.
You can see this as part of the output of help cd.
This help text seems to have been introduced in bash 4.3, but the functionality goes back at least to bash 3.2.
Other shells may or may not behave the same way.