_bash_profile
Good Afternoon,
I placed mkdircd() function in _bash_profile and saved using VI editor. # vi .bash_profile function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\"";} I expected to use it next day I logged on. But it did not recognize this function. I read that _bash_profile is hidden file and ctl+H will be able to view it but I cannot view the contents of the file. Sorry, where bash_profile is? what purpose does it serve? Please answer when you can. Thank you:) Irina |
It's .bash_profile (not _bash_profile or bash_profile) and it must be in your home directory (~) to work.
If you logged on at a graphical logon ("greeter") screen, ~/.bash_profile may not have been run; not all of the graphical logon programs run ~/.bash_profile. You can test whether ~/.bash_profile is creating the mkdircd function like this: Code:
source ~/.bash_profile |
Quote:
I believe I cannot see my .bash_profile. I tried the following: source ~/.bash_profile declare -f from my username/localhost command line in terminal screen. However if I try from this command to do again vi .bash_profie the editor is open .bash_profile as a new file but I cannot see what I saved before ( my mkdircd function ).I will reserach more. Somewhere I am wrong. Thank you for patience. I really enjoy this help line. Fells like our beutiful world is so small:) |
Quote:
Assuming you did see that, either you saved .bash_profile in a different directory or under a different name (or you did not save it). Assuming the name contains _profile and you saved it under your home directory, you could find it by Code:
cd |
_bash_profile
Place in your ~user/.bashrc
Next time you start a new session it will be there. |
the VI text editor for the terminal is not "new linux user friendly"
how exactly did you save the text file in VI ( should save on exit) and what mode were you in and what commands did you use to close out vi for small edits i normally use "nano" it is a much more user friendly editor and perfect for minor edits but if you have a desktop gui installed "gedit" or " kate" are the default editors |
why we use .bash_profile:
my PATH set up into a .profile file (because I sometimes use other shells) my bash aliases and functions into my .bashrc Then use this: .bash_profile: simply: According to the bash man page, .bash_profile is executed for login shells.When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt. |
Quote:
which broght me back to user/localhost. Function find is great it showed all my directories and files. I can see .bashrc and see my new saved function there. Now if I use it it creates directory but does not automatically redirect to it. Is it because I am in user/localhost propmt? Thank you:) |
That's strange -- it works for me:
Code:
c@CW8:/tmp$ function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\"";} Code:
c@CW8:/tmp/foo$ set -xv To turn off the set -xv use Code:
set +xv |
Quote:
.bashrc which I access from user@localhost command line via VI editor contains my function mkdircd (). It is getting intersting... now when i type mkdircd lala it said bash : mkdircd : command not found. "Find" command shows that I have ./bashrc and ./.bashrc files. |
Place it in your home/user/.bashrc
Code:
I placed in mine & tested and works fine. |
Quote:
This could be tested by logging in and running ... Code:
source ~/.bashrc A login bash shell uses /etc/profile and the first of ~/.bash_profile, ~/.bash_login and ~/.profile that exists. An "interactive non-login" bash shell uses ~/.bashrc. So, if the function definition is in ~/.bashrc and you login to bash the function is not available. A common technique to have the same customisation regardless of login or non-login, is to source ~/.bashrc in ~/.bash_profile: Code:
[[ -f ~/.bashrc ]] && source ~/.bashrc |
Quote:
Perfect! Thank you very much! I tried code :source ~/.bashrc and then used my function mkdircd perfectly. I also updated .bash_profile to "include" functions from .bashrc and ran my function mkdircd succesfully. And what I relly liked to accompllish is to exit the terminal and login back and the function works! Thank you so much! You are great! Excellent! The whole idea to help each other is amazing! I hope I can help someone in the future:) |
All times are GMT -5. The time now is 04:54 AM. |