Results 1 to 3 of 3
Hi,
I tried to make a (very simple) function to put in my .bashrc file to make a local backup of a file, but when I call the function and ...
- 07-05-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 7
[SOLVED] .bashrc function tab completion problem
Hi,
I tried to make a (very simple) function to put in my .bashrc file to make a local backup of a file, but when I call the function and try to use tab completion I get the following error:
The function I added is as follows:Code:cp: cannot stat `help': No such file or directory
Interestingly, the tab completion still technically "works" properly, but this message inserts itself into the tab-completed file name.Code:function bk { \cp -f --backup=numbered ${1} ${1}.bak }
So for example, if there is a file called "doc.txt" that I want to make a backup copy of, and at the prompt I type "bk do[tab]", I immediately see "bk docp: cannot stat `help': No such file or directory\nc.txt" (the "\n" there is actually a new line, it doesn't print "\n"). And then if I press enter, it performs the backup.
Also interestingly, if I define this function at the prompt rather than in my .bashrc, tab completion works fine.
Thoughts?
Thanks.
- 07-08-2010 #2
not sure why you really need to perform that as a function. have you tried using it as an alias?
Code:alias bk='cp -f --backup=numbered ${1} ${1}.bak'linux user # 503963
- 07-08-2010 #3Just Joined!
- Join Date
- Jul 2010
- Posts
- 7
Hi Scathefire.
Thanks for the idea. However, as far as I understand, aliases in bash do not support argument passing. Thus, because I want to be able to use the argument multiple times (source and part of destination name), I needed to be able to reference it (as ${1}). This is why I was using a function rather than an alias.
Also, I recently was pointed in the correct direction as to source of my problem. I was defining the function in my .bashrc before I was sourcing my /etc/bash_completion file. When I made sure to put my function definition after /etc/bash_completoin was sourced, everything worked properly.


