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

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

From Manjaro
(Created page with "Давайте создадим простую функцию bash, которая будет создавать каталог и затем переходить в него:...")
 
 
Line 22: Line 22:
==Смотрите также==
==Смотрите также==
[https://www.gnu.org/software/bash/manual/html_node/index.html Документация по Bash]
[https://www.gnu.org/software/bash/manual/html_node/index.html Документация по Bash]
[https://wiki.archlinux.org/title/Bash_(Русский)#Псевдонимы ArchWiki]
[https://wiki.archlinux.org/title/Bash_(Русский)#Псевдонимы ArchWiki]

Latest revision as of 07:42, 30 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]

Давайте создадим простую функцию bash, которая будет создавать каталог и затем переходить в него:

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

Теперь вместо того, чтобы использовать mkdir для создания нового каталога, а затем cd для перемещения в этот каталог, вы можете просто набрать:

user $ mkcd new_directory COPY TO CLIPBOARD


.

Хранение альяса bash в другом файле

Bash позволяет добавлять локальные альясы в Ваш ~/.bashrc. Для этого создайте файл ~/.bash_aliases и добавьте его содержимое в Ваш файл ~/.bashrc:

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

Теперь вы можете добавить любые альясы в Ваш ~/.bash_aliases и затем загрузить их в свою Bash-сессию с помощью команды source ~/.bashrc.

Заключение

Этот список не является исчерпывающим. Почти все, что часто используется, можно сократить с помощью альяса.

Смотрите также

Документация по Bash

ArchWiki

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