How to add an alias to .bashrc file?


How to add an alias to .bashrc file?



I am new to Ubuntu. I need to set path in my .bashrc file, but I am getting permission denied error even if am the admin of the system .


.bashrc


export TCFRAME_HOME=~/tcframe
alias tcframe=$TCFRAME_HOME/scripts/tcframe



Now when I type tcframe version I get


tcframe version


bash: /home/p46562/tcframe/scripts/tcframe: No such file or directory



How to fix this?





Possible duplicate of How to permanently set $PATH on Linux/Unix?
– LTClipp
Jul 2 at 19:30





This question is thoroughly and repeatedly documented on places like ehem stack overflow.
– LTClipp
Jul 2 at 19:31





There's nothing wrong with the alias definition here (although it would be simpler to just add ~/tcframe/scripts to your path instead). You are probably missing the execute permissions on tcframe itself; chmod +x ~/tcframe/scripts/tcframe.
– chepner
Jul 2 at 19:42


~/tcframe/scripts


tcframe


chmod +x ~/tcframe/scripts/tcframe





@An0n That's thoroughly misguided advice. Editing your personal file as root will only lead to new permission problems.
– tripleee
Jul 2 at 20:10





That's misguided too, for the same reason.
– tripleee
Jul 2 at 20:14




1 Answer
1



The error message is telling you that you are trying to execute a file which does not exist.



We can vaguely guess about what files do exist, but without access to your system, we can't know for sure what you have actually installed and where.



Perhaps you have a file named tcframe in a directory called scripts in your home directory?


tcframe


scripts


alias tcframe=$HOME/scripts/tcframe



A common arrangement to avoid littering your environment with one or more aliases for each random utility you have installed somewhere is to create a dedicated directory for your PATH - a common convention is to call it bin - and populate it with symlinks to things you want to have executable.


PATH


bin



Just once,


mkdir $HOME/bin



and edit your .profile (or .bash_profile or .bashrc if you prefer) to include the line


.profile


.bash_profile


.bashrc


PATH=$HOME/bin:$PATH



From now on, to make an executable script accessible from anywhere without an explicit path, create a symlink to it in bin;


bin


ln -s $HOME/scripts/tcframe $HOME/bin



Notice that the syntax is like cp; the last argument is the destination (which can be a directory, or a new file name) and the first (and any subsequent arguments before the last, if the last is a directory) are the sources. When the destination is a directory, the file name of each source argument is used as the name of a new symlink within the destination directory.


cp



Also notice that you generally want to use absolute paths; a relative path is resolved relative to bin (so e.g.


bin


ln -s ../scripts/tcframe $HOME/bin



even if you are currently in a directory where ../scripts does not exist.)


../scripts



Scripts, by definition, need to be executable. If they aren't, you get "permission denied" when you try to run them. This is controlled by permissions; each file has a set of permission bits which indicate whether you can read, write to (or overwrite), and execute this file. These permissions are also set separately for members of your group (so you can manage a crude form of team access) and everyone else. But for your personal scripts, you only really care that the x (executable) bit is set for yourself. If it isn't, you can change it - this is only required once.


x


chmod +x scripts/tcframe





Sometimes you see recommendations to use chmod 777 but this is a serious seurity problem. Don't panic; back away slowly, then run.
– tripleee
Jul 3 at 9:43



chmod 777






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?