i have a few questions about the “4.aliases” topic
whenever i create a new session (meaning when i click the + button on the top left corner of the terminal) would the terminal load source ~/.bash_profile automatically?
can i just delete the alias or other commands in the ~/.bash_profile and do source ~/.bash_profile if i want to delete a alias or a command in the bash_profile??
First off, I believe that aliases and most other configuration belongs in ~/.bashrc.
My .bash_profiles on various machines all look something like this:
[[ -f ~/.bashrc ]] && . ~/.bashrc
All that does is to source my ~/.bashrc if it exists, so that all my shell configurations always run, with the exception of for non-interactive shells (like file syncing over network)
The first line of my .bashrc is:
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
And then follow everything else, such as aliases.
There is no way to reset what commands were run, you would instead run a new shell. If you have then removed commands from your .bashrc then they would no longer be in effect in that new shell, as they did not run.
That doesn’t seem much related to the question :<
The question isn’t about what an alias is, and doesn’t touch on variable scope or functions!
But i can understand the confusion of the questioner,
as me coming from an OpenVMS environment
i always had to struggle with the peculiarities of the UNIX/UNIX-look-a-likes…
oh so a new session on the terminal automatically does “source ~/.bash_profile”? sorry im very new in programming
When you open a new terminal you’ll get a new bash session. What files it then reads depends on how your system is set up, typically you don’t have to worry about it and you just put all the commands you want to run in a new shell in .bashrc in your home directory which will then be executed on each new bash session.
what if i want to delete a alias? do i just delete them off the .bashrc file and do source .bashrc?
Unless there is a command in your .bashrc that explicitly deletes that alias then no, sourcing .bashrc would not unalias it. Sourcing just causes the commands in that file to execute. If you just want to change one thing you could do so with a command, or you could remove the command in .bashrc that sets that alias so that it doesn’t run for future shells.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.