Tuesday, May 14, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1781  / 2 Years ago, mon, august 15, 2022, 8:40:08

I am trying to create an alias and I have added this line in ~/.bash_aliases:



alias server-python='open http://localhost:8000 && python -m SimpleHTTPServer'


alias ssh-saad='ssh saad@<my-server>' <my-server> is replaced by the IP address of my server. So in my ~/.bashrc file these lines are uncommented



if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi


and in my ~/.profile:



# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi


I believe that whenever I start the terminal my aliases should work. However, unless I run the command source ~/.bash_aliases it’s not working. Also, for the first server-python alias I am getting an error:



Couldn't get a file descriptor referring to the console


I have looked into these solutions here:

How to create a permanent "alias"?

Ubuntu alias not applied in bashrc



but still cannot make it work. I would really appreciate it if someone could point out to me what I am doing wrong. I know that the problem is very trivial, but I must be just missing something.






I have now fixed the error



Couldn't get a file descriptor referring to the console


by using sensible-browser instead of open:



alias server-python='sensible-browser http://localhost:8000 && python -m SimpleHTTPServer'

More From » bash

 Answers
7

I finally found one suitable solution for this problem. if there is a ~/.bash_login file and its not empty then ~/.bashrc file is not automatically loaded when we open the shell. If we move that ~/.bash_login



mv ~/.bash_login ~/.bash_login_old


then ~/.bashrc file will be loaded and also it will load the ~/.bash_aliases file if the following lines are uncommented in the ~/.bashrc file.



if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi


One other solution I can think of is if you dont want to rename or delete your ~/.bash_login file then what you can do is when you are in the shell just type this command bash and it will load the ~/.bashrc file.


[#33714] Monday, August 15, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
peratingcit

Total Points: 253
Total Questions: 122
Total Answers: 94

Location: Botswana
Member since Sat, Jan 7, 2023
1 Year ago
peratingcit questions
Thu, Feb 23, 23, 18:33, 1 Year ago
Wed, Jul 27, 22, 03:43, 2 Years ago
Mon, Dec 6, 21, 13:03, 2 Years ago
;