8,560
edits
(Created page with "==Что такое .bashrc? Что такое альяс?== * '''.bashrc''' - это '''конфигурационный файл''' для bash, интерпретатора...") |
(Updating to match new version of source page) Tags: Mobile web edit Mobile edit |
||
Line 1: | Line 1: | ||
<languages/> | <languages/> | ||
__TOC__ | __TOC__ | ||
<div class="mw-translate-fuzzy"> | |||
==Что такое .bashrc? Что такое альяс?== | ==Что такое .bashrc? Что такое альяс?== | ||
* '''.bashrc''' - это '''конфигурационный файл''' для bash, интерпретатора команд и оболочки linux. | * '''.bashrc''' - это '''конфигурационный файл''' для bash, интерпретатора команд и оболочки linux. | ||
Line 57: | Line 58: | ||
==Смотрите также== | ==Смотрите также== | ||
[https://www.gnu.org/software/bash/manual/html_node/index.html Документация по Bash] | [https://www.gnu.org/software/bash/manual/html_node/index.html Документация по Bash] | ||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
The syntax for creating a bash function is very easy. They can be declared in two different formats: | |||
{{File|file=~/.bashrc| | |||
content=<pre>... | |||
function_name () { | |||
[commands] | |||
} | |||
...</pre>}} | |||
or | |||
{{File|file=~/.bashrc| | |||
content=<pre>... | |||
function function_name { | |||
[commands] | |||
} | |||
...</pre>}} | |||
To pass any number of arguments to the bash function simply, put them right after the function’s name, separated by a space. The passed parameters are $1, $2, $3, etc., corresponding to the position of the parameter after the function’s name. The $0 variable is reserved for the function name. | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
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] | |||
</div> | |||
[[Category:Contents Page{{#translation:}}]] | [[Category:Contents Page{{#translation:}}]] | ||
[[Category:Terminal{{#translation:}}]] | [[Category:Terminal{{#translation:}}]] |