In the terminal, how do I use an alias during the same terminal session it's created?

Is it possible to reload bashrc with a terminal command?

https://stackoverflow.com/questions/2518127/how-to-reload-bashrc-settings-without-logging-out-and-back-in-again

Answering your question in the title of the thread, if you define an alias on the command line, then itā€™ll be available throughout that entire session, as long as you donā€™t close the window.

Answering your second question, yes, you can reload ~/.bashrc from the running sessionā€¦ :arrow_down:

source ~/.bashrc

However, this is where I must point out that you must check whether you are indeed running bash, because terminal window sessions now use zsh by default in all three of the official Manjaro editions, and for zsh you need ~/.zshrc instead.

1 Like

or using dot:
. ~/.bashrc

Yes, but considering that the dot is duplicitous in the eyes of newbies ā€” you know, as in ā€œdot filesā€ ā€” I deliberately omitted that. :wink:

Indeed, the dot (.) ā€” followed by a space ā€” is a built-in shell command that does the same thing as the (equally built-in) command source. :slight_smile:

Soā€¦

. ~/.bashrc

ā€¦ is the same thing asā€¦

source ~/.bashrc

:slight_smile:

So when creating an alias at the command line, the alias can only be used during that session. Well \hen how can I make a permanent alias?

Canā€™t speak to ZSH, but you can put an alias in your .bashrc file:

alias <whatever_your_alias_name>='whatever_your_command_is'

Re-source your .bashrc, and viola.

As an aside, I have a .bash_aliases file. Keeps my .bashrc nice and neat.

To load zsh, we type zsh

Now we can type alias zsh='source ~/.zshrc
Also alias zshconfig='micro ~/.zshrc

Exit that terminalā€¦ open a new one and type bash

Then type zsh - loads shell

Then type zshconfig loads config.

By putting the alias inside your ~/.zshrc. :wink:

Haha yes, I copied from the config but said just put in the terminal - after you put in the alias, you can test it with ā€˜zshconfigā€™ and then edit the config.

Personally I prefer ā€˜codeā€™ and open it separately from the terminal.
Screenshot_20220901_064135
but micro is good tooā€¦
Screenshot_20220901_064415

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.