Manjaro Difference between revisions of "Translations:Aliases in .bashrc/3/en"

Difference between revisions of "Translations:Aliases in .bashrc/3/en"

From Manjaro
(Importing a new version from external source)
Tags: Mobile web edit Mobile edit
 
(No difference)

Latest revision as of 16:14, 29 December 2022

Information about message (contribute)
This message has no documentation. If you know where or how this message is used, you can help other translators by adding documentation to this message.
Message definition (Aliases in .bashrc)
Let’s create a simple bash function which will create a directory and then navigate into it:
{{File|file=~/.bashrc|
content=<pre>...
mkcd ()
{
  mkdir -p -- "$1" && cd -P -- "$1"
}
...</pre>}}
Now instead of using mkdir to create a new directory and then cd to move into that directory , you can simply type:
{{UserCmd|command=mkcd new_directory}}
==Keeping bash alias in a different file==
Bash allows you to add local aliases in your ~/.bashrc file. To do this create a file called ~/.bash_aliases and add these contents in your ~/.bashrc file:
{{File|file=~/.bashrc|
content=<pre>...
if [ -e $HOME/.bash_aliases ]; then
   source $HOME/.bash_aliases
fi
...</pre>}}
Now you can add any aliases in your ~/.bash_aliases file and then load them into your Bash session with the source ~/.bashrc command.
==Conclusion==
This list is not comprehensive. Almost anything that is commonly used can be shortened with an alias
==See Also==
[https://www.gnu.org/software/bash/manual/html_node/index.html Bash documentation]
[https://wiki.archlinux.org/title/bash#Aliases ArchWiki]

Let’s create a simple bash function which will create a directory and then navigate into it:

~/.bashrc
...
mkcd ()
{
  mkdir -p -- "$1" && cd -P -- "$1"
}
...

Now instead of using mkdir to create a new directory and then cd to move into that directory , you can simply type:

user $ mkcd new_directory COPY TO CLIPBOARD


Keeping bash alias in a different file

Bash allows you to add local aliases in your ~/.bashrc file. To do this create a file called ~/.bash_aliases and add these contents in your ~/.bashrc file:

~/.bashrc
...
if [ -e $HOME/.bash_aliases ]; then
    source $HOME/.bash_aliases
fi
...

Now you can add any aliases in your ~/.bash_aliases file and then load them into your Bash session with the source ~/.bashrc command.

Conclusion

This list is not comprehensive. Almost anything that is commonly used can be shortened with an alias

See Also

Bash documentation ArchWiki

Cookies help us deliver our services. By using our services, you agree to our use of cookies.