Clever Geek Handbook
πŸ“œ ⬆️ ⬇️

Bash

Bash (from the English B ourne a gain sh ell , pun "Born again" shell - "revived" shell) - an improved and modernized variation of the command shell Bourne shell . One of the most popular modern variations of the UNIX command shell. Especially popular in the Linux environment, where it is often used as a pre-installed shell.

GNU Bourne-Again Shell
Bash screenshot.png
Typical Bash Session
Type ofUNIX shell
AuthorBrian Fox
DeveloperChet Ramey
Written onSi
operating systemUnix-like
Interface languagesEnglish , multilingual ( gettext )
First edition
Hardware platform
Latest version
Readable File Formats
LicenseGNU General Public License
Websitegnu.org/software/bash/

It is a command processor that works, as a rule, interactively in a text window. Bash can also read commands from a file called a script (or script ). Like all Unix shells, it supports autocompletion of file and directory names, substitution of the output of command results, variables, control over the execution order, branch and loop operators. Keywords, syntax, and other basic language features were borrowed from sh . Other features, such as history, were copied from csh and ksh . Bash basically complies with the POSIX standard, but with a number of extensions [2] .

The name "bash" is an acronym for English. Bourne-again-shell ("another-command-shell-Bourne") and is a pun: Bourne-shell - one of the popular varieties of the command shell for UNIX (sh), authored by Stephen Bourne ( 1978 ), improved in 1987 by Brian Fox . The surname Bourne (Bourne) has something in common with the English word born , meaning "born", hence: born-again-command shell.

In September 2014, a widely exploited Bashdoor vulnerability was discovered in bash.

Syntax Differences

The vast majority of important Bourne shell scripts can be run unchanged in bash, with the exception of those that refer to special Bourne variables or use the Bourne built-in commands. The Bash command syntax includes ideas borrowed from Korn shell ( ksh ) and C shell ( csh ), such as command line editing, command history, directory stack, $RANDOM and $PPID , $(…) command replacement syntax. When Bash is used as an interactive command processor, it supports the completion of program names, files, variables, etc. using the Tab β†Ή key.

Internal Commands

The bash interpreter has many built-in commands, some of which have similar executable files in the operating system. However, it should be noted that most often there are no man pages for built-in commands, and when you try to view help on a built-in command, the help on the executable file will actually be issued. The executable file and the built-in command may differ in parameters. Information on built-in commands is described in the bash man page:

man bash

Input Output
echodisplays the expression or contents of a variable ( stdout ), but has limitations in use [3]
printfformatted output command, extended echo command
read"Reads" the value of a variable from standard input ( stdin ), in interactive mode it is a keyboard
File system
cdchanges the current directory
pwddisplays the name of the current working directory (from the English print working directory )
pushdchanges the current directory with the ability to return in the reverse order
popdreturns current directory after pushd
dirslist or clear the contents of the directory stack stored via pushd
Actions on Variables
letperforms arithmetic operations on variables
evaltranslates a list of arguments from a list to commands
setchanges the values ​​of internal script variables
unsetdeletes a variable
exportexports a variable, making it available to child processes
declare , typesetset and / or impose constraints on variables
getoptsused to parse the arguments passed to the script from the command line
Script management
source (point)running the specified script
exitscript shutdown
execreplaces the current process with a new exec command
shoptallows you to change the keys (options) of the shell on the fly
Teams
truereturns completion code zero (success)
falsereturns a completion code that indicates failure
type progprints the full path to prog
hash progremembers the path to prog
help COMMANDdisplays a brief reference on using the internal command COMMAND
Management of tasks launched in the command shell
jobsshows a list of tasks launched in the command shell, or information about a specific task by its number
fgswitches the input stream to the current task (or to a specific task, if its number is specified) and continues its execution
bgcontinues to execute the currently paused task (or certain tasks, if their numbers are indicated) in the background
waitawaits completion of specified tasks

Scripts

In the simplest case, a script is a simple list of commands written to a file. The command processor should know that it should process this file, and not just read its contents. A special construct called shebang serves for this: #! . The # character specifies a comment, but in this case shebang means that after this special character there is a path to the interpreter for script execution.

Syntax

The syntax for bash commands is the extended syntax for Bourne shell commands. The final bash command syntax specification is in the Bash Reference Manual distributed by the GNU project. [four]

"Hello world"

  #! / usr / bin / env bash
 echo 'Hello World!'

This script contains only two lines. The first line tells the system which program is used to run the file. The second line is the only action that this script executes; it actually prints β€œHello world!” In the terminal.

Run Script

In order for the script to become executable, the following commands can be used:

  chmod + rx scriptname # granting read / execute rights to any user
 chmod u + rx scriptname # granting rights to read / execute only to the "owner" of the script

For security reasons, the path to the current directory . not included in the $PATH environment variable. Therefore, to run the script, you must explicitly specify the path to the current directory in which the script is located:

  ./scriptname

In addition, you can pass such a file for execution to the Bash interpreter explicitly using the bash command:

  bash scriptname

In this case, neither setting the access rights nor using the sequence #! is required #! in code.

I / O Redirection

There are built-in file descriptors in bash: 0 (stdin), 1 (stdout), 2 (stderr).

  • stdin - standard input - what the user types in the console;
  • stdout - standard output of the program;
  • stderr - standard error output.

There are special characters for operations with these and user descriptors: > (output redirection), < (input redirection). Symbols & , - can precede the descriptor number; for example, 2>&1 - redirecting handle 2 (stderr) to handle 1 (stdout).

0<filename or <filenameRedirecting input from filename
1>filename or >filenameRedirecting output to the file "filename". If the noclobber option is disabled, the file is overwritten with incoming data.
1>|filename or >|filenameRedirecting output to the file β€œfilename”, the file is overwritten by the incoming data
1>>filename or >>filenameRedirecting the output to the file "filename", the data is added to the end of the file. If there is no file, it is created.
2>filenameRedirecting standard error output to the file "filename"
2>>filenameRedirecting standard error output to the file "filename", data is added to the end of the file. If there is no file, it is created.
&>filenameRedirecting output and errors to the file "filename"
2>&1Redirecting error output to standard output

Bash has an individual redirection syntax that is not supported in the Bourne shell. Example of simultaneously redirecting standard output and standard errors:

  command & > file

This is easier to type than the equivalent command in the Bourne shell syntax.

  command > file 2 > & 1

Redirect "from script code"

The heredoc syntax is supported:

  • With the interpretation of variables and language constructs inside a block:
  $ a = 'multi-line'
 command << MYDOC123
 $ a
 text
 $ (<$ HOME / my_file.txt)
 MYDOC123
  • Without interpretation of variables:
  command << 'PERLCODE'
 my $ first = 'Hello';
 my $ second = 'world';
 say join (',', $ first, $ second), '!';
 PERLCODE
  • With removal of initial indents (only indents are supported by tabs):
  command << - 'TABSTRIP'
 for ((i = 0; i <10; i ++))
 do
 echo "$ i"
 done
 TABSTRIP

Starting with version 2.05b, bash can redirect standard input from a string using the following here strings syntax:

  command <<< "string to be read as standard input"

If a string contains spaces, it should be enclosed in quotation marks or apostrophes, or escape spaces with a backslash.

Be careful: the line you enter using here strings contains an implicit sequence to end the line: either 1 extra byte of line feed , or 2 extra bytes: carriage return and line feed.

  cat - <<< '123' |  wc -c
 # Result: 4
 cat < ( echo -n '123' ) |  wc -c
 # Result: 3
 wc -c <<< '123'
 # Result: 4
 echo -n 123 |  wc -c
 # Result: 3

Starting with version 4.1 [5], it became possible to indicate a terminating sequence of characters in one line and, immediately after it, a bracket. This may be useful for assigning a here-doc content variable:

  var = $ ( cat - << 'TERMSEQ'
 February.  Get ink and cry!
 Write about feverishly about February,
 While the rumbling slush
 In spring it burns black.
 TERMSEQ )

In this case, a BASH warning message will be generated.

Redirection for the whole process

Example (redirecting standard output to a file, writing data, closing a file, resetting stdout):

  # make Filedescriptor (FD) 6 a copy of stdout (FD 1)
 exec 6 > & 1
 # open file "test.data" for writing
 exec 1 > test.data
 # produce some content
 echo "data: data: data"
 # close file "test.data"
 exec 1 > & -
 # make stdout a copy of FD 6 (reset stdout)
 exec 1 > & 6
 # close FD6
 exec 6 > & -

Opening and closing files:

  # open file test.data for reading
 exec 6 <test.data
 # read until end of file
 while read -u 6 dta
 do
   echo " $ dta " 
 done
 # close file test.data
 exec 6 < & -

Command Substitution

Capturing the output of external commands:

  # execute 'date' and put the result in VAR
 VAR = " $ ( date ) "
 echo " $ VAR " # will display the date at the time the previous line was called

At the same time, null-character strings are not supported, the final line feeds disappear, unlike channels and other file I / O.

Conditional Operator

  #! / usr / bin / env bash
 T1 = 'foo'
 T2 = 'bar'
 if [[ $ T1 == " $ T2 " ]] 
 then
   echo 'condition is satisfied'
 else
   echo 'condition not fulfilled'
 fi

Note that quotation marks around the left side are optional. [6]

Cycles

  #! / usr / bin / env bash
 for i in "Number" { 1 ..10 }
 do
   echo " $ i "
 done
  1 #! / Usr / bin / env bash
 2 COUNTER = 0
 3 while [[ $ COUNTER -lt 10 ]] 
 4 do
 5 echo The counter is $ COUNTER
 6 let COUNTER = COUNTER + 1
 7 done
  #! / usr / bin / env bash
 i = 0
 until [[ $ i -eq 10 ]] 
 do
   echo " $ i "
   i = $ (( $ i + 1 ))
 done
  #! / usr / bin / env bash
 # inside double parentheses, variables can be written in C-style (without $ and separating operators and operands with a space)
 for (( i = 0 ; i < 10 ; i ++ ))
 do
	 echo -n " $ i ;"
 done

Arrays

In bash, only one-dimensional arrays are implemented. Indexes can be either integer values ​​(an "ordinary" array ) or strings ( an associative array , or a "hash").

Despite the unification of the syntax for working with regular and associative arrays, the former are not a variation of the latter either from the point of view of the end user or from the point of view of the internal logic of the interpreter itself.

As a natural consequence of the support of "associative" keys, in bash there is an extremely limited ability to emulate multidimensional arrays.

General Operations

Get a string consisting of all [7] elements of the array, separated by a space.

  values = " $ { arr [@] } "

Get a string with all [7] indexes or array keys, regardless of whether they are numeric or text:

  keys = " $ { ! arr [@] } "

Carry out mass replacement of the first occurrence of the substring β€œMAY” with β€œMARCH” in all [7] elements of the array and return a string composed of the resulting elements of the array, separated by a space:

  values = " $ { arr [@] / MAY / MARCH } "

The same, but in each [7] element of the array all occurrences of the substring β€œMAY” will be replaced:

  values = " $ { arr [@] // MAY / MARCH } "

Until now, not all the features declared in the documentation work correctly for arrays. For example:

  [ -v 'array_name' ]

fails for an empty array. [8]

Indexed Array Operations

Bash has support for one-dimensional arrays. The elements of the array can be initialized as: my_array[xx] . You can also explicitly declare an array in a script using the declare directive:

  declare -a my_array

You can access individual elements of the array using curly braces: "${my_array[xx]}" .

There are two ways to initialize an indexed array:

one)

  Array = ( element1 element2 element3 )

2)

  temp_array [ 0 ] = element1
 temp_array [ 5 ] = element
 temp_array [ 9 ] = elementN

Adding elements to the end of an indexed array:

  declare -a arrAnimals
 arrAnimals = ( dog elephant horse cow fox koala turtle )
 # Output the contents of the array:
 echo " $ { arrAnimals [@] } "
 # At the end of the arrAnimals array, add a new element: "pig"
 arrAnimals + = ( pig )
 # And again, show the contents of the array:
 echo " $ { arrAnimals [@] } "

Get the first element of the array:

  echo " $ { arrAnimals [0] } "

Both indexed and associative arrays support the so-called β€œslices”:

  # Another way to get the first element of an array
 echo " $ { arrAnimals [@]: 0 : 1 } "

 # Output 3 elements of the array, starting from the 2nd:
 echo " $ { arrAnimals [@]: 2 : 3 } "

Note: in the case of associative arrays, the sequence of values ​​in the general case will be random (determined by the hash function used), therefore, the operation of cutting on the associative array, although valid, has a very limited area of ​​practical application.

In arrays with numerical indices, β€œreverse” (β€œnegative”) addressing is allowed, which allows access to elements starting from the end of the array:

  # The value of the last element of the array
 echo " $ { arrAnimals [-1] } "
 # The value of the penultimate element of the array
 echo " $ { arrAnimals [-2] } "
 # ... etc.

Using the built-in mapfile (synonym: readarray ), you can map the contents of a text file to an indexed array:

  declare -a fileWithLogins
 mapfile fileWithLogins </ etc / passwd
 for (( i = 0 ; i < $ {# fileWithLogins [@] } ; i ++ ))
 do
	 echo "Line # $ i : $ { fileWithLogins [ $ i ] } "
 done

Associative Array Operations

Starting with version 4.0, bash introduced support for associative arrays (the so-called hash arrays).

To declare associative arrays, use the -A switch of the declare built-in command:

  declare -A hshArray

As with indexed arrays, two different syntaxes can be used to populate associative arrays:

one)

  TheCapitalOf [ Georgia ] = 'Tbilisi'
 TheCapitalOf [ Australia ] = 'Canberra'
 TheCapitalOf [ Pakistan ] = 'Islamabad'

2)

  TheCapitalOf = ([ Georgia ] = 'Tbilisi' [ Australia ] = 'Canberra' [ Pakistan ] = 'Islamabad' )

Using associative arrays you can simulate support for multidimensional arrays:

  declare -A a # declares an associative array 'a'
 i = 1 ;  j = 2 # initialize multiple indexes
 a [ $ i , $ j ] = 5 # assigning the value β€œ5” to the cell β€œ$ i, $ j” (ie β€œ1,2”)
 echo $ { a [ $ i , $ j ] } # output stored values ​​from "$ i, $ j"

Unfortunately, in current versions of bash, copying the contents of one associative array into another is not possible with a simple assignment. This problem can only be circumvented, for which there are two fundamentally different approaches:

1) Emulate the declaration of the second hash β€œfrom scratch” by copying the declaration of the first hash:

  declare -A hsh1
 hsh1 = ( ... )

 source < ( declare -p hsh1 | sed 's / ^ declare -A hsh1 / declare -A hsh2 /' )

2) Iterate over all [7] elements of the source hash and copy them to the target hash:

  declare -A hsh1 hsh2
 hsh1 = ( ... )

 for k in " $ { ! hsh1 [@] } "
 do
	 hsh2 [ " $ k " ] = " $ { hsh1 [ " $ k " ] } "
 done

Safe work with arrays

Arrays are a convenient way to pass dynamically generated arguments to functions or commands. In addition, each element of the array is a separate argument.

  args = ( -l -a / )
 ls " $ { args [@] } " # ls -l -a /
 ls $ { args [@] } # ls -l -a /
 ls $ { args [*] } # ls -l -a /

However, when using arrays in this way, you should be careful because of the features of expanding arrays when using the special characters @ and * as indices.

If the array is enclosed in quotation marks and expanded using the @ index, a string of words is formed, where each word is a separate element of the array. However, if you do not enclose the expansion of the array in double quotation marks, then you may get a completely different result: the spaces that make up the array elements become word delimiters.

  args = ( -l -a '/ home / user / Desktop' )
 ls " $ { args [@] } " # view the contents of the directory '/ home / user / Desktop'
 ls $ { args [@] } # error: the directories '/ home / user / Worker' and './table' do not exist

An array with index * enclosed in double quotation marks is expanded on one line, connecting all elements of the array through the delimiters stored in the IFS variable. If you do not specify double quotation marks, then the array is expanded similarly to expansion when using the @ index.

  args = ( '' usr local bin )
 IFS = '/' ls " $ { args [*] } " # view the contents of the directory '/ usr / local / bin'
 IFS = '/' ls $ { args [*] } # alternately viewing the contents of the directories '.', './Usr', './local' and './bin'

When creating an array from the contents of a text variable, you must consider the possible presence of spaces in the text. For example, as one of the ways to create an array from an enumerated string, you can consider replacing the separator character with a space. However, the presence of gaps in shared elements will lead to fragmentation of the elements themselves into parts.

  array = ( $ { text //, / } ) # wrong: the text in the variable 'text' could contain whitespace

 IFS = ',' array = ( $ text ) # right: the separator character is a comma.
 IFS = ',' read -r -a array <<< " $ text " # is correct (alternative with redirecting the contents of the variable 'text' to the command 'read')

Errors can be caused by creating an array from text received as a command output or from a file, since not only line breaks, but also spaces with tabs will be considered delimiters by default [9] .

  array = ( " $ ( ls ) " ) # wrong: spaces in the file name can split the file name into two array elements

 IFS = $ '\ n' array = ( " $ ( ls ) " ) # right: only line breaks will be a delimiter
 mapfile -t array << ( ls ) # correct: alternative via the built-in mapfile command

Conveyor

The conveyor transfers the output of the previous command to the input of the next or to the input of the shell. The method is often used to link a sequence of commands into a single chain. The conveyor is indicated by | .

Example (grep works like a filter for standard output):

  cat filename |  grep pattern

Logical operations

Logical OR is denoted as || . In condition checking operations, the operator || returns 0 (success) if one of the operands is true (TRUE).

Logical AND is denoted as && . In condition checking operations, the && operator returns 0 (success) if and only if both operands are true (TRUE).

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅: ВозмоТная ΠΏΡƒΡ‚Π°Π½ΠΈΡ†Π° Π² ΠΏΠΎΠ½ΠΈΠΌΠ°Π½ΠΈΠΈ Π²ΠΎΠ·Π½ΠΈΠΊΠ°Π΅Ρ‚ ΠΈΠ·-Π·Π° Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎ ΠΊΠΎΠΌΠ°Π½Π΄Π° true (ΠΈ ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎΠ΅ Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΠ΅ любой ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹) Π·Π°Π²Π΅Ρ€ΡˆΠ°Π΅Ρ‚ΡΡ с ΠΊΠΎΠ΄ΠΎΠΌ Π²ΠΎΠ·Π²Ρ€Π°Ρ‚Π° 0, success ( false , Π½Π°ΠΎΠ±ΠΎΡ€ΠΎΡ‚, Π½Π΅ 0), Π² Ρ‚ΠΎ врСмя ΠΊΠ°ΠΊ логичСскоС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ true/false β€” ΠΎΡ‚Π»ΠΈΡ‡Π½ΠΎ ΠΎΡ‚ нуля/Ρ€Π°Π²Π½ΠΎ Π½ΡƒΠ»ΡŽ.

Examples:

 if false ; then echo "successfully" ; else echo "unsuccessfully" ; fi
unsuccessfully
 let "a=(( 1 && 0 && 123))" ; echo $?  ; echo $a
1 # Код Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΡ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹
0 # Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ "a", Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ логичСской ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΈ
if (( 1 && 0 && 123 )) ; then echo "true" ; else echo "false" ; fi
false
let "a=(( 1 && 123 && -345 ))" ; echo $?  ; echo $a
0 # Код Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΡ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹
1 # Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ "a", Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ логичСской ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΈ
if (( 1 && 123 & -345 )) ; then echo "true" ; else echo "false" ; fi
true
 false && echo "УспСшноС Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΠ΅" || echo "ΠΠ΅ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎΠ΅ Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΠ΅"
ΠΠ΅ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎΠ΅ Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΠ΅

ЦСлочислСнная ΠΌΠ°Ρ‚Π΅ΠΌΠ°Ρ‚ΠΈΠΊΠ°

Bash ΠΌΠΎΠΆΠ΅Ρ‚ Π²Ρ‹ΠΏΠΎΠ»Π½ΡΡ‚ΡŒ цСлочислСнныС вычислСния Π²Π½ΡƒΡ‚Ρ€ΠΈ процСсса, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ ((…)) ΠΈ синтаксис ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ $((…)) [10] , ΠΊΠ°ΠΊ ΠΏΠΎΠΊΠ°Π·Π°Π½ΠΎ Π½ΠΈΠΆΠ΅:

 VAR = 55 # УстанавливаСм ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ VAR, Ρ€Π°Π²Π½ΠΎΠΉ 55
(( VAR = VAR + 1 )) # ДобавляСм Π΅Π΄ΠΈΠ½ΠΈΡ†Ρƒ ΠΊ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ VAR. ΠžΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅ Π½Π° отсутствиС Π·Π½Π°ΠΊΠ° '$'
(( VAR += 1 )) # Бокращённая Ρ„ΠΎΡ€ΠΌΠ° записи ΠΈΠ½ΠΊΡ€Π΅ΠΌΠ΅Π½Ρ‚Π°
(( ++VAR )) # Π”Ρ€ΡƒΠ³ΠΎΠΉ способ увСличСния VAR Π½Π° Π΅Π΄ΠΈΠ½ΠΈΡ†Ρƒ. ВыполняСт прСфиксный ΠΈΠ½ΠΊΡ€Π΅ΠΌΠ΅Π½Ρ‚
(( VAR++ )) # Π”Ρ€ΡƒΠ³ΠΎΠΉ способ увСличСния VAR Π½Π° Π΅Π΄ΠΈΠ½ΠΈΡ†Ρƒ. ВыполняСт постфиксный ΠΈΠ½ΠΊΡ€Π΅ΠΌΠ΅Π½Ρ‚
echo $(( VAR * 22 )) # Π£ΠΌΠ½ΠΎΠΆΠ°Π΅ΠΌ VAR Π½Π° 22 ΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°Π΅ΠΌ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ ΠΊΠΎΠΌΠ°Π½Π΄Π΅
echo $ [ VAR * 22 ] # Π£ΡΡ‚Π°Ρ€Π΅Π²ΡˆΠΈΠΉ способ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ Ρ‚ΠΎ ΠΆΠ΅
(( VAR <<3)) # ΠŸΠΎΠ±ΠΈΡ‚ΠΎΠ²Ρ‹ΠΉ сдвиг Π²Π»Π΅Π²ΠΎ (Ρ‚ΠΎ ΠΆΠ΅, Ρ‡Ρ‚ΠΎ VAR*8)
((VAR>>3 )) # ΠŸΠΎΠ±ΠΈΡ‚ΠΎΠ²Ρ‹ΠΉ сдвиг Π²ΠΏΡ€Π°Π²ΠΎ (Ρ‚ΠΎ ΠΆΠ΅, Ρ‡Ρ‚ΠΎ VAR/8)

Команда ((…)) Ρ‚Π°ΠΊΠΆΠ΅ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π² условных утвСрТдСниях, Ρ‚Π°ΠΊ ΠΊΠ°ΠΊ Π΅Ρ‘ исходный ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ β€” это 0 ΠΈΠ»ΠΈ 1, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΌΠΎΠ³ΡƒΡ‚ ΠΈΠ½Ρ‚Π΅Ρ€ΠΏΡ€Π΅Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒΡΡ ΠΊΠ°ΠΊ true ΠΈΠ»ΠΈ false:

 if (( VAR == Y * 3 + X * 2 ))
then
  echo Yes 
fi
(( Z > 23 )) && echo Yes

Команда ((…)) ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Ρ‹ ставнСния: == != > < >= <= .

Bash Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ вычислСния Π²Π½ΡƒΡ‚Ρ€ΠΈ процСсса с числами с ΠΏΠ»Π°Π²Π°ΡŽΡ‰Π΅ΠΉ Ρ‚ΠΎΡ‡ΠΊΠΎΠΉ. Волько ΠΊΠΎΠΌΠ°Π½Π΄Π½Ρ‹Π΅ процСссоры Unix Korn shell (вСрсия 1993 Π³ΠΎΠ΄Π° ) ΠΈ zsh (начиная с вСрсии 4.0) ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°ΡŽΡ‚ эту Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ.

Бписок матСматичСских ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΉ: + , - , * , / , ** (Π²ΠΎΠ·Π²Π΅Π΄Π΅Π½ΠΈΠ΅ Π² ΡΡ‚Π΅ΠΏΠ΅Π½ΡŒ), % (Π΄Π΅Π»Π΅Π½ΠΈΠ΅ ΠΏΠΎ ΠΌΠΎΠ΄ΡƒΠ»ΡŽ, остаток ΠΎΡ‚ дСлСния), let β€” позволяСт ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ сокращСния арифмСтичСских ΠΊΠΎΠΌΠ°Π½Π΄ (сокращая количСство ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΡ‹Ρ… ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Ρ…; Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€: a += b эквивалСнтно a = a + b ΠΈ Ρ‚. ΠΏ.).

ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΈ Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Ρ‹

АргумСнты:

$$pid Ρ‚Π΅ΠΊΡƒΡ‰Π΅Π³ΠΎ shell (самого процСсса-сцСнария)
$!pid послСднСго процСсса Π² Ρ„ΠΎΠ½ΠΎΠ²ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅
$?ΠΊΠΎΠ΄ Π²ΠΎΠ·Π²Ρ€Π°Ρ‚Π° послСднСго процСсса (Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ ΠΈΠ»ΠΈ скрипта)
$ xΠ³Π΄Π΅ x β€” Π½ΠΎΠΌΠ΅Ρ€ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π°, ΠΏΠ΅Ρ€Π΅Π΄Π°Π½Π½ΠΎΠ³ΠΎ скрипту ( $1 , $2 ΠΈ Ρ‚. Π΄., $0 β€” послСдний Π·Π°ΠΏΡƒΡ‰Π΅Π½Π½Ρ‹ΠΉ скрипт)
$#количСство Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ΠΎΠ² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строки
$*всС [7] Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Ρ‹ Π² Π²ΠΈΠ΄Π΅ ΠΎΠ΄Π½ΠΎΠΉ строки (слова)
$@Ρ‚ΠΎ ΠΆΠ΅ самоС, Ρ‡Ρ‚ΠΎ ΠΈ $* , Π½ΠΎ ΠΏΡ€ΠΈ этом ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ [7] ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ прСдставлСн ΠΊΠ°ΠΊ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Π°Ρ строка (слово)
$-список Ρ„Π»Π°Π³ΠΎΠ², ΠΏΠ΅Ρ€Π΅Π΄Π°Π½Π½Ρ‹Ρ… ΡΡ†Π΅Π½Π°Ρ€ΠΈΡŽ
$_содСрТит послСдний Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅ΠΉ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹

ВстроСнныС ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅:

$BASHΠΏΡƒΡ‚ΡŒ ΠΊ исполняСмому Ρ„Π°ΠΉΠ»Ρƒ bash
$BASH_VERSINFO[n]массив, состоящий ΠΈΠ· 6 элСмСнтов, содСрТащий ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ ΠΎ вСрсии bash
$BASH_VERSIONвСрсия Bash, установлСнного Π² систСмС
$DIRSTACKсодСрТимоС Π²Π΅Ρ€ΡˆΠΈΠ½Ρ‹ стСка ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΎΠ²
$EDITORΠ·Π°Π΄Π°Π½Π½Ρ‹ΠΉ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ Ρ€Π΅Π΄Π°ΠΊΡ‚ΠΎΡ€
$EUID«эффСктивный» ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΎΠ½Π½Ρ‹ΠΉ Π½ΠΎΠΌΠ΅Ρ€ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ (Effective User ID)
$FUNCNAMEимя Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ
$GLOBIGNOREΠΏΠ΅Ρ€Π΅Ρ‡Π΅Π½ΡŒ ΡˆΠ°Π±Π»ΠΎΠ½Π½Ρ‹Ρ… символов, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π±ΡƒΠ΄ΡƒΡ‚ ΠΏΡ€ΠΎΠΈΠ³Π½ΠΎΡ€ΠΈΡ€ΠΎΠ²Π°Π½Ρ‹ ΠΏΡ€ΠΈ Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ подстановки ΠΈΠΌΡ‘Π½ Ρ„Π°ΠΉΠ»ΠΎΠ² (globbing)
$GROUPSΠ³Ρ€ΡƒΠΏΠΏΡ‹, ΠΊ ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΌ ΠΏΡ€ΠΈΠ½Π°Π΄Π»Π΅ΠΆΠΈΡ‚ Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ
$HOMEдомашний ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ
$HOSTNAMEсСтСвоС имя хоста
$HOSTTYPEΡ‚ΠΈΠΏ ΠΌΠ°ΡˆΠΈΠ½Ρ‹ (ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΡ†ΠΈΡ€ΡƒΠ΅Ρ‚ Π°ΠΏΠΏΠ°Ρ€Π°Ρ‚Π½ΡƒΡŽ Π°Ρ€Ρ…ΠΈΡ‚Π΅ΠΊΡ‚ΡƒΡ€Ρƒ)
$IFSΡ€Π°Π·Π΄Π΅Π»ΠΈΡ‚Π΅Π»ΡŒ ΠΏΠΎΠ»Π΅ΠΉ Π²ΠΎ Π²Π²ΠΎΠ΄ΠΈΠΌΠΎΠΉ строкС
$LC_COLLATEΠ·Π°Π΄Π°Ρ‘Ρ‚ порядок сортировки символов, Π² опСрациях подстановки ΠΈΠΌΡ‘Π½ Ρ„Π°ΠΉΠ»ΠΎΠ² ΠΈ Π² поискС ΠΏΠΎ ΡˆΠ°Π±Π»ΠΎΠ½Ρƒ
$LC_CTYPEопрСдСляСт ΠΊΠΎΠ΄ΠΈΡ€ΠΎΠ²ΠΊΡƒ символов
$LINENOНомСр строки исполняСмого сцСнария
$MACHTYPEаппаратная Π°Ρ€Ρ…ΠΈΡ‚Π΅ΠΊΡ‚ΡƒΡ€Π°
$OLDPWDΠΏΡ€Π΅ΠΆΠ½ΠΈΠΉ Ρ€Π°Π±ΠΎΡ‡ΠΈΠΉ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³
$OSTYPEΡ‚ΠΈΠΏ ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΎΠ½Π½ΠΎΠΉ систСмы
$PATHΠΏΡƒΡ‚ΡŒ поиска (Π²ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ Π² сСбя ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³ΠΈ /usr/bin/ , /usr/X11R6/bin/ , /usr/local/bin ΠΈ Ρ‚. Π΄.)
$PIPESTATUSКод Π²ΠΎΠ·Π²Ρ€Π°Ρ‚Π° ΠΊΠ°Π½Π°Π»Π° (ΠΊΠΎΠ½Π²Π΅ΠΉΠ΅Ρ€Π°)
$PPIDPID (ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€) Ρ€ΠΎΠ΄ΠΈΡ‚Π΅Π»ΡŒΡΠΊΠΎΠ³ΠΎ процСсса
$PS1ΠΏΡ€ΠΈΠ³Π»Π°ΡˆΠ΅Π½ΠΈΠ΅ ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строки
$PS2Π²Ρ‚ΠΎΡ€ΠΈΡ‡Π½ΠΎΠ΅ ΠΏΡ€ΠΈΠ³Π»Π°ΡˆΠ΅Π½ΠΈΠ΅ ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строки, выводится Ρ‚ΠΎΠ³Π΄Π°, ΠΊΠΎΠ³Π΄Π° ΠΎΡ‚ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ оТидаСтся Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹ΠΉ Π²Π²ΠΎΠ΄. ΠžΠ±Ρ‹Ρ‡Π½ΠΎ отобраТаСтся ΠΊΠ°ΠΊ Β«>Β»
$PS3Ρ‚Ρ€Π΅Ρ‚ΠΈΡ‡Π½ΠΎΠ΅ ΠΏΡ€ΠΈΠ³Π»Π°ΡˆΠ΅Π½ΠΈΠ΅, выводится, ΠΊΠΎΠ³Π΄Π° ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ Π²Ρ‹Π±ΠΎΡ€ Π² ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€Π΅ select
$PS4ΠΏΡ€ΠΈΠ³Π»Π°ΡˆΠ΅Π½ΠΈΠ΅ Ρ‡Π΅Ρ‚Π²Ρ‘Ρ€Ρ‚ΠΎΠ³ΠΎ уровня, выводится (Π² ΠΈΠ·ΠΌΠ΅Π½Ρ‘Π½Π½ΠΎΠΌ Π²ΠΈΠ΄Π΅) Π² Π½Π°Ρ‡Π°Π»Π΅ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ строки ΠΎΡ‚Π»Π°Π΄ΠΎΡ‡Π½ΠΎΠ³ΠΎ Π²Ρ‹Π²ΠΎΠ΄Π° Ρ‚ΠΎΠ³Π΄Π°, ΠΊΠΎΠ³Π΄Π° сцСнарий вызываСтся с ΠΊΠ»ΡŽΡ‡ΠΎΠΌ -x . ΠžΠ±Ρ‹Ρ‡Π½ΠΎ отобраТаСтся ΠΊΠ°ΠΊ Β«+Β», Β«++Β» ΠΈ Ρ‚. Π΄.
$PWDΡ€Π°Π±ΠΎΡ‡ΠΈΠΉ (Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ) ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³
$REPLYпСрСмСнная ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ, ΠΊΡƒΠ΄Π° записываСтся Π²Π²ΠΎΠ΄ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ, Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½Π½Ρ‹ΠΉ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ read
$SECONDSврСмя Ρ€Π°Π±ΠΎΡ‚Ρ‹ сцСнария (Π² сСкундах)
$SHELLOPTSсписок допустимых ΠΎΠΏΡ†ΠΈΠΉ ΠΈΠ½Ρ‚Π΅Ρ€ΠΏΡ€Π΅Ρ‚Π°Ρ‚ΠΎΡ€Π° (доступна Ρ‚ΠΎΠ»ΡŒΠΊΠΎ для чтСния)
$SHLVLΡƒΡ€ΠΎΠ²Π΅Π½ΡŒ влоТСнности shell

РСгулярныС выраТСния Π²Π½ΡƒΡ‚Ρ€ΠΈ процСсса

Bash 3.0 ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ встроСнныС рСгулярныС выраТСния с синтаксисом, ΠΏΠΎΠ΄ΠΎΠ±Π½Ρ‹ΠΌ синтаксису Perl :

 [[ string = ~ regex ]]

Бинтаксис рСгулярных Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ Π·Π°Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½ Π½Π° страницах Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚Π°Ρ†ΠΈΠΈ man 7 regex. Бтатус Π²Ρ‹Ρ…ΠΎΠ΄Π° устанавливаСтся Π² 0, Ссли рСгулярноС Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ совпало со строкой, ΠΈ 1, Ссли Π½Π΅Ρ‚. Π—Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ подвыраТСния, Π·Π°ΠΊΠ»ΡŽΡ‡Ρ‘Π½Π½ΠΎΠ³ΠΎ Π² скобки, ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ [7] Ρ‡Π΅Ρ€Π΅Π· ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ ${BASH_REMATCH[@]} , Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€:

 REGEXP = 'foo(bar)bl(.*)'
if [[ "abcfoobarbletch" = ~ $REGEXP ]] 
then
  echo "РСгулярноС Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ совпало со строкой!" 
  echo " $BASH_REMATCH " # Π²Ρ‹Π²ΠΎΠ΄ΠΈΡ‚: foobarbletch
  echo " ${ BASH_REMATCH [1] } " # Π²Ρ‹Π²ΠΎΠ΄ΠΈΡ‚: bar
  echo " ${ BASH_REMATCH [2] } " # Π²Ρ‹Π²ΠΎΠ΄ΠΈΡ‚: etch
fi

ВстроСнныС рСгулярныС выраТСния ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ Ρ€Π°Π±ΠΎΡ‚Π°ΡŽΡ‚ быстрСС, Ρ‡Π΅ΠΌ Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ внСшнСй ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ grep, ΠΏΠΎΡ‚ΠΎΠΌΡƒ Ρ‡Ρ‚ΠΎ ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰Π΅Π΅ рСгулярноС Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ выполняСтся Π² Ρ€Π°ΠΌΠΊΠ°Ρ… процСсса bash. Если рСгулярноС Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ ΠΈΠ»ΠΈ строка содСрТат ΠΏΡ€ΠΎΠ±Π΅Π»Ρ‹ ΠΈΠ»ΠΈ мСтасимволы (Ρ‚Π°ΠΊΠΈΠ΅ ΠΊΠ°ΠΊ * ΠΈΠ»ΠΈ ? ), ΠΈΡ… слСдуСт Π²Π·ΡΡ‚ΡŒ Π² ΠΊΠ°Π²Ρ‹Ρ‡ΠΊΠΈ. РСкомСндуСтся ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ для хранСния рСгулярного выраТСния, ΠΊΠ°ΠΊ Π² Π²Ρ‹ΡˆΠ΅ΠΏΡ€ΠΈΠ²Π΅Π΄Ρ‘Π½Π½ΠΎΠΌ ΠΏΡ€ΠΈΠΌΠ΅Ρ€Π΅, для избСТания ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌ с экранированиСм ΡΠΏΠ΅Ρ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Ρ… символов. МоТно ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ Π²Ρ‹Π²ΠΎΠ΄ bash с ΠΎΠΏΡ†ΠΈΠ΅ΠΉ -x для ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ, ΠΊΠ°ΠΊ ΠΈΠΌΠ΅Π½Π½ΠΎ bash воспринимаСт вашС рСгулярноС Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅.

Π Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅ скобок

Π’ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ скобок заимствована Ρƒ csh . Она позволяСт ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ»ΡŒΠ½ΠΎΠΉ строкС Π±Ρ‹Ρ‚ΡŒ сформированной с использованиСм ΠΏΠΎΡ…ΠΎΠΆΠ΅ΠΉ Ρ‚Π΅Ρ…Π½ΠΈΠΊΠΈ, ΠΊΠ°ΠΊ это дСлаСтся с названиями Ρ„Π°ΠΉΠ»ΠΎΠ². Однако Π² bash сгСнСрированныС строки Π½Π΅ обязаны Π±Ρ‹Ρ‚ΡŒ ΠΈΠΌΠ΅Π½Π°ΠΌΠΈ Ρ„Π°ΠΉΠ»ΠΎΠ². Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ строки Π½Π΅ сортируСтся, сохраняСтся порядок слСва Π½Π°ΠΏΡ€Π°Π²ΠΎ:

 # Π­Ρ‚ΠΎ ΠΎΡΠΎΠ±Π΅Π½Π½ΠΎΡΡ‚ΡŒ присущая bash
echo a { p,c,d,b } e # ape ace ade abe

НС слСдуСт ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ эту ΠΎΡΠΎΠ±Π΅Π½Π½ΠΎΡΡ‚ΡŒ, Ссли скрипт планируСтся ΠΏΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ, ΠΏΠΎΡ‚ΠΎΠΌΡƒ Ρ‡Ρ‚ΠΎ Π² Ρ‚Ρ€Π°Π΄ΠΈΡ†ΠΈΠΎΠ½Π½Ρ‹Ρ… скриптах Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅ строки Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚ Π΄Π΅ΠΉΡΡ‚Π²ΠΎΠ²Π°Ρ‚ΡŒ:

 # Врадиционная ΠΎΠ±ΠΎΠ»ΠΎΡ‡ΠΊΠ° Π½Π΅ Π΄Π°Ρ‘Ρ‚ Ρ‚ΠΎΡ‚ ΠΆΠ΅ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚
echo a { p,c,d,b } e # a{p,c,d,b}e

Когда ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅ скобок Π² сочСтании с символами подстановки, скобки Ρ€Π°ΡΠΊΡ€Ρ‹Π²Π°ΡŽΡ‚ΡΡ ΠΏΠ΅Ρ€Π²Ρ‹ΠΌΠΈ, Π° Π·Π°Ρ‚Π΅ΠΌ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ обрабатываСтся Π² ΠΎΠ±Ρ‹Ρ‡Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅. Π’Π°ΠΊΠΈΠΌ ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ, список JPEG- ΠΈ PNG-ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ Π² Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΌ ΠΊΠ°Ρ‚Π°Π»ΠΎΠ³Π΅ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½ Ρ‚Π°ΠΊ:

 ls *. { jpg,jpeg,png } # скобки Ρ€Π°ΡΠΊΡ€Ρ‹Π²Π°ΡŽΡ‚ΡΡ Π΄ΠΎ *.jpg *.jpeg *.png, послС Ρ‡Π΅Π³ΠΎ выполняСтся поиск ΠΏΠΎ маскам

ГорячиС клавиши

  • Tab β†Ή : АвтодополнСниС строки Π·Π° курсором.
  • Ctrl + ! Ctrl + ! : ΠŸΠΎΠ²Ρ‚ΠΎΡ€ΠΈΡ‚ΡŒ послСднюю ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ.
  • Ctrl + a : ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Π΅Ρ‚ курсор Π² Π½Π°Ρ‡Π°Π»ΠΎ строки (эквивалСнтно клавишС Home ).
  • Ctrl + b : ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Π΅Ρ‚ курсор Π½Π° ΠΎΠ΄ΠΈΠ½ символ Π½Π°Π·Π°Π΄ (эквивалСнтно клавишС ← ).
  • Ctrl + r : Поиск ΠΏΠΎ Π½Π°Π±Ρ€Π°Π½Π½Ρ‹ΠΌ Ρ€Π°Π½Π΅Π΅ ΠΊΠΎΠΌΠ°Π½Π΄Π°ΠΌ.
  • Ctrl + c : ΠŸΠΎΡΡ‹Π»Π°Π΅Ρ‚ сигнал SIGINT Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΌΡƒ заданию, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΎΠ±Ρ‹Ρ‡Π½ΠΎ (Π½ΠΎ Π½Π΅ всСгда) ΠΏΡ€Π΅ΠΊΡ€Π°Ρ‰Π°Π΅Ρ‚ ΠΈ Π·Π°ΠΊΡ€Ρ‹Π²Π°Π΅Ρ‚ Π΅Π³ΠΎ.
  • Ctrl + d : ΠŸΠΎΡΡ‹Π»Π°Π΅Ρ‚ ΠΌΠ°Ρ€ΠΊΠ΅Ρ€ EOF , ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ (Ссли Π½Π΅ ΠΎΡ‚ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΎ ΠΎΠΏΡ†ΠΈΠ΅ΠΉ ΠΈ тСкущая строка Π½Π΅ содСрТит тСкста) Π·Π°ΠΊΡ€Ρ‹Π²Π°Π΅Ρ‚ Ρ‚Π΅ΠΊΡƒΡ‰ΡƒΡŽ ΠΎΠ±ΠΎΠ»ΠΎΡ‡ΠΊΡƒ (эквивалСнтно ΠΊΠΎΠΌΠ°Π½Π΄Π΅ exit ), ΠΏΡ€ΠΈ Π²Π²ΠΎΠ΄Π΅ Π² ΠΈΡΠΏΠΎΠ»Π½ΡΡŽΡ‰ΡƒΡŽΡΡ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡƒ Π·Π°Π²Π΅Ρ€ΡˆΠ°Π΅Ρ‚ Π²Π²ΠΎΠ΄, Ссли Π² строкС Π½Π΅Ρ‚ тСкста, ΠΈΠ½Π°Ρ‡Π΅ Π·Π°Π²Π΅Ρ€ΡˆΠ°Π΅Ρ‚ строку Π±Π΅Π· символа Π·Π°Π²Π΅Ρ€ΡˆΠ΅Π½ΠΈΡ строки.
  • Ctrl + d : УдаляСт Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ символ (Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ссли Π΅ΡΡ‚ΡŒ тСкст Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ строкС) (эквивалСнтно клавишС Delete ).
  • Ctrl + e : ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Π΅Ρ‚ курсор Π² ΠΊΠΎΠ½Π΅Ρ† строки (эквивалСнтно клавишС End ).
  • Ctrl + f : ΠŸΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Π΅Ρ‚ курсор Π½Π° ΠΎΠ΄ΠΈΠ½ символ Π²ΠΏΠ΅Ρ€Ρ‘Π΄ (эквивалСнтно клавишС β†’ ).
  • Ctrl + h : УдаляСт ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰ΠΈΠΉ символ (Ρ‚ΠΎ ΠΆΠ΅ самоС, Ρ‡Ρ‚ΠΎ ΠΈ клавиша ← Backspace ).
  • Ctrl + i : Π­ΠΊΠ²ΠΈΠ²Π°Π»Π΅Π½Ρ‚Π½ΠΎ клавишС Tab β†Ή .
  • Ctrl + j : Π­ΠΊΠ²ΠΈΠ²Π°Π»Π΅Π½Ρ‚Π½ΠΎ клавишС ↡ Enter .
  • Ctrl + k : ΠžΡ‡ΠΈΡ‰Π°Π΅Ρ‚ содСрТимоС строки послС курсора ΠΈ ΠΊΠΎΠΏΠΈΡ€ΡƒΠ΅Ρ‚ это Π² Π±ΡƒΡ„Π΅Ρ€ ΠΎΠ±ΠΌΠ΅Π½Π° экзСмпляра bash (kill ring).
  • Ctrl + l : ΠžΡ‡ΠΈΡ‰Π°Π΅Ρ‚ содСрТимоС экрана (эквивалСнтно ΠΊΠΎΠΌΠ°Π½Π΄Π΅ clear ).
  • Ctrl + m : Π­ΠΊΠ²ΠΈΠ²Π°Π»Π΅Π½Ρ‚Π½ΠΎ клавишС ↡ Enter .
  • Ctrl + n : (ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅Π΅) пСрСлистываСт ΠΊ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅ΠΉ ΠΊΠΎΠΌΠ°Π½Π΄Π΅ (эквивалСнтно клавишС ↓ ).
  • Ctrl + o : ВыполняСт Π½Π°ΠΉΠ΄Π΅Π½Π½ΡƒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ Π² истории, ΠΈ Π²Ρ‹Π±ΠΈΡ€Π°Π΅Ρ‚ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ строку ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ строки Π² истории для Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΡ‚Ρ€Π΅Π΄Π°ΠΊΡ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ.
  • Ctrl + p : (ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅Π΅) пСрСлистываСт ΠΊ ΠΏΡ€Π΅Π΄ΡˆΠ΅ΡΡ‚Π²ΡƒΡŽΡ‰Π΅ΠΉ ΠΊΠΎΠΌΠ°Π½Π΄Π΅ (эквивалСнтно клавишС ↑ ).
  • Ctrl + q : Π’ΠΎΠ·ΠΎΠ±Π½ΠΎΠ²ΠΈΡ‚ΡŒ Π²Ρ‹Π²ΠΎΠ΄ процСсса.
  • Ctrl + s : ΠŸΡ€ΠΈΠΎΡΡ‚Π°Π½ΠΎΠ²ΠΈΡ‚ΡŒ Π²Ρ‹Π²ΠΎΠ΄ процСсса (stop).
  • Ctrl + t : ОбмСн мСстами сосСдних символов.
  • Ctrl + u : ΠžΡ‡ΠΈΡ‰Π°Π΅Ρ‚ содСрТаниС строки Π΄ΠΎ курсора ΠΈ ΠΊΠΎΠΏΠΈΡ€ΡƒΠ΅Ρ‚ Π΅Π³ΠΎ Π² Π±ΡƒΡ„Π΅Ρ€ ΠΎΠ±ΠΌΠ΅Π½Π° экзСмпляра bash (kill ring).
  • Ctrl + w : Π£Π±ΠΈΡ€Π°Π΅Ρ‚ слово Π΄ΠΎ курсора ΠΈ ΠΊΠΎΠΏΠΈΡ€ΡƒΠ΅Ρ‚ Π΅Π³ΠΎ Π² Π±ΡƒΡ„Π΅Ρ€ ΠΎΠ±ΠΌΠ΅Π½Π° экзСмпляра bash (kill ring).
  • Ctrl + y : добавляСт содСрТимоС Π±ΡƒΡ„Π΅Ρ€Π° ΠΎΠ±ΠΌΠ΅Π½Π° экзСмпляра bash ΠΎΡ‚ ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ курсора.
  • Ctrl + z : ΠŸΠΎΡΡ‹Π»Π°Π΅Ρ‚ сигнал SIGTSTP Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΌΡƒ заданию, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ приостанавливаСт Π΅Π³ΠΎ Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅, ΠΈ возобновляСт ΠΏΡ€ΠΈΡ‘ΠΌ ΠΊΠΎΠΌΠ°Π½Π΄. Для возобновлСния Π΅Π³ΠΎ выполнСния Π² Ρ„ΠΎΠ½ΠΎΠ²ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ ΠΌΠΎΠΆΠ½ΠΎ ввСсти ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ bg. Для Ρ‚ΠΎΠ³ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π²Π΅Ρ€Π½ΡƒΡ‚ΡŒ Π΅Π³ΠΎ ΠΈΠ· Ρ„ΠΎΠ½ΠΎΠ²ΠΎΠ³ΠΎ Ρ€Π΅ΠΆΠΈΠΌΠ° ΠΈΠ»ΠΈ приостановки, ΠΌΠΎΠΆΠ½ΠΎ Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚ΡŒ fg.
  • Ctrl + / : ΠŸΡ€Π΅Ρ€Π²Π°Ρ‚ΡŒ Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ процСсс с Π΄Π°ΠΌΠΏΠΎΠΌ памяти (core dump), послав Π΅ΠΌΡƒ сигнал.
  • Ctrl + _ ( Ctrl + ⇧ Shift + - ): ΠžΡ‚ΠΊΠ°Ρ‚ рСдактирования.
  • Alt + > : ΠΏΠ΅Ρ€Π΅Ρ…ΠΎΠ΄ ΠΊ послСднСй ΠΊΠΎΠΌΠ°Π½Π΄Π΅ Π² истории.
  • Alt + b : (Π½Π°Π·Π°Π΄) ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Π΅Ρ‚ курсор Π½Π°Π·Π°Π΄ Π½Π° ΠΎΠ΄Π½ΠΎ слово (эквивалСнтно клавишС Ctrl + ← ).
  • Alt + d : Π‘ΠΎΠΊΡ€Π°Ρ‰Π°Π΅Ρ‚ слово послС курсора.
  • Alt + f : (Π²ΠΏΠ΅Ρ€Ρ‘Π΄) ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Ρ‰Π°Π΅Ρ‚ курсор Π²ΠΏΠ΅Ρ€Ρ‘Π΄ Π½Π° ΠΎΠ΄Π½ΠΎ слово (эквивалСнтно клавишС Ctrl + β†’ ).
  • Alt + t : ΠœΠ΅Π½ΡΠ΅Ρ‚ Π΄Π²Π° слова ΠΏΠ΅Ρ€Π΅Π΄ курсором мСстами.
  • Alt + . : ДобавляСт послСдний Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰Π΅ΠΉ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹.
  • Alt + c : Π—Π°ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Π±ΡƒΠΊΠ²Ρƒ ΠΏΠΎΠ΄ курсором Π½Π° Π·Π°Π³Π»Π°Π²Π½ΡƒΡŽ.
  • Alt + l : Π—Π°ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Π±ΡƒΠΊΠ²Ρƒ ΠΏΠΎΠ΄ курсором Π½Π° ΡΡ‚Ρ€ΠΎΡ‡Π½ΡƒΡŽ.
  • Ctrl + x Ctrl + x : ΠŸΠ΅Ρ€Π΅Π½ΠΎΡΠΈΡ‚ курсор ΠΊ Π½Π°Ρ‡Π°Π»Ρƒ строки ΠΎΡ‚ Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ ΠΏΠΎΠ·ΠΈΡ†ΠΈΠΈ, ΠΈ ΠΎΠ±Ρ€Π°Ρ‚Π½ΠΎ.
  • Ctrl + x Ctrl + e : Π Π΅Π΄Π°ΠΊΡ‚ΠΈΡ€ΡƒΠ΅Ρ‚ Ρ‚Π΅ΠΊΡƒΡ‰ΡƒΡŽ строку Π² ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ΅ $EDITOR, ΠΈΠ»ΠΈ vi, Ссли Π½Π΅ ΠΏΡ€Π΅Π΄ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΎ.
  • Ctrl + x Ctrl + v : Π’Ρ‹Π²ΠΎΠ΄ Π½Π° экран ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ ΠΎ вСрсии Ρ‚Π΅ΠΊΡƒΡ‰Π΅Π³ΠΎ экзСмпляра bash.

Π‘Ρ‚Π°Ρ€Ρ‚ΠΎΠ²Ρ‹Π΅ скрипты

Bash ΠΏΡ€ΠΈ запускС Π²Ρ‹Π·Ρ‹Π²Π°Π΅Ρ‚ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΈΠ· мноТСства Ρ€Π°Π·Π»ΠΈΡ‡Π½Ρ‹Ρ… скриптов.

Когда bash вызываСтся ΠΊΠ°ΠΊ интСрактивная ΠΎΠ±ΠΎΠ»ΠΎΡ‡ΠΊΠ° Π²Ρ…ΠΎΠ΄Π° Π² систСму, ΠΏΠ΅Ρ€Π²Ρ‹ΠΌ Π΄Π΅Π»ΠΎΠΌ ΠΎΠ½ Ρ‡ΠΈΡ‚Π°Π΅Ρ‚ ΠΈ Π²Ρ‹Π·Ρ‹Π²Π°Π΅Ρ‚ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΈΠ· Ρ„Π°ΠΉΠ»Π° /etc/profile , Ссли этот Ρ„Π°ΠΉΠ» сущСствуСт. ПослС чтСния этого Ρ„Π°ΠΉΠ»Π° ΠΎΠ½ смотрит ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ Ρ„Π°ΠΉΠ»Ρ‹ Π² ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅ΠΌ порядкС: ~/.bash_profile , ~/.bash_login ΠΈ ~/.profile , Ρ‡ΠΈΡ‚Π°Π΅Ρ‚ ΠΈ Π²Ρ‹Π·Ρ‹Π²Π°Π΅Ρ‚ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΈΠ· ΠΏΠ΅Ρ€Π²ΠΎΠ³ΠΎ, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ сущСствуСт ΠΈ доступСн для чтСния. ΠŸΡ€ΠΈ Π²Ρ‹Ρ…ΠΎΠ΄Π΅ bash Ρ‡ΠΈΡ‚Π°Π΅Ρ‚ ΠΈ выполняСт ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΈΠ· Ρ„Π°ΠΉΠ»Π° ~/.bash_logout .

Когда запускаСтся интСрактивная ΠΎΠ±ΠΎΠ»ΠΎΡ‡ΠΊΠ°, Π½ΠΎ Π½Π΅ для Π²Ρ…ΠΎΠ΄Π° Π² систСму, bash Ρ‡ΠΈΡ‚Π°Π΅Ρ‚ ΠΈ исполняСт ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΈΠ· Ρ„Π°ΠΉΠ»ΠΎΠ² /etc/bash.bashrc ΠΈ ~/.bashrc , Ссли ΠΎΠ½ΠΈ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‚. Π­Ρ‚ΠΎ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΎΡ‚ΠΌΠ΅Π½Π΅Π½ΠΎ ΠΎΠΏΡ†ΠΈΠ΅ΠΉ -norc . ΠžΠΏΡ†ΠΈΡ -rcfile file заставит bash ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΈΠ· Ρ„Π°ΠΉΠ»Π° file вмСсто /etc/bash.bashrc ΠΈ ~/.bashrc .

ΠŸΠ΅Ρ€Π΅Π½ΠΎΡΠΈΠΌΠΎΡΡ‚ΡŒ

ΠŸΠ΅Ρ€Π²ΠΎΠΉ строкой скрипта Π΄ΠΎΠ»ΠΆΠ½Π° Π±Ρ‹Ρ‚ΡŒ запись #!/bin/bash , Ссли извСстСн Π°Π±ΡΠΎΠ»ΡŽΡ‚Π½Ρ‹ΠΉ ΠΏΡƒΡ‚ΡŒ ΠΊ исполняСмому Ρ„Π°ΠΉΠ»Ρƒ, Π»ΠΈΠ±ΠΎ #!/usr/bin/env bash для автоматичСского опрСдСлСния ΠΏΡƒΡ‚ΠΈ ΠΊ исполняСмому Ρ„Π°ΠΉΠ»Ρƒ Ρ‡Π΅Ρ€Π΅Π· ΠΊΠΎΠΌΠ°Π½Π΄Ρƒ env с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ окруТСния PATH [11] .

Π‘ΠΊΡ€ΠΈΠΏΡ‚Ρ‹ ΠΎΠ±ΠΎΠ»ΠΎΡ‡Π΅ΠΊ, написанныС со спСцифичСскими для bash особСнностями, Π½Π΅ Π±ΡƒΠ΄ΡƒΡ‚ Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° систСмах, Π³Π΄Π΅ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ΡΡ Bourne shell (sh) ΠΈΠ»ΠΈ ΠΎΠ΄ΠΈΠ½ ΠΈΠ· Π΅Π³ΠΎ Π°Π½Π°Π»ΠΎΠ³ΠΎΠ² , Ссли bash Π½Π΅ Π±Ρ‹Π» установлСн Π² качСствС Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠΉ ΠΎΠ±ΠΎΠ»ΠΎΡ‡ΠΊΠΈ. Π­Ρ‚Π° ΠΏΡ€ΠΎΠ±Π»Π΅ΠΌΠ° стала особСнно Π²Π°ΠΆΠ½ΠΎΠΉ, ΠΊΠΎΠ³Π΄Π° Ubuntu Π½Π°Ρ‡Π°Π» с октября 2006 Π³ΠΎΠ΄Π° ΠΏΠΎΡΡ‚Π°Π²Π»ΡΡ‚ΡŒ Debian Almquist shell (dash) ΠΊΠ°ΠΊ ΡΠΊΡ€ΠΈΠΏΡ‚ΠΎΠ²ΡƒΡŽ ΠΎΠ±ΠΎΠ»ΠΎΡ‡ΠΊΡƒ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ, Ρ‡Ρ‚ΠΎ ΠΏΡ€ΠΈΠ²Π΅Π»ΠΎ ΠΊ нСработоспособности многочислСнных скриптов.

ГрафичСский интСрфСйс ΠΊ скриптам

БущСствуСт мноТСство ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌ, ΠΏΠΎΠ·Π²ΠΎΠ»ΡΡŽΡ‰ΠΈΡ… ΡΠΎΠ·Π΄Π°Π²Π°Ρ‚ΡŒ графичСский интСрфСйс ΠΊ bash-скриптам.

  • dialog β€” ΡƒΡ‚ΠΈΠ»ΠΈΡ‚Π°, ΠΏΠΎΠ·Π²ΠΎΠ»ΡΡŽΡ‰Π°Ρ ΡΠΎΠ·Π΄Π°Π²Π°Ρ‚ΡŒ Π΄ΠΈΠ°Π»ΠΎΠ³ΠΎΠ²Ρ‹Π΅ ΠΎΠΊΠ½Π° Π² консоли, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ curses ΠΈ ncurses .
  • whiptail β€” Π°Π½Π°Π»ΠΎΠ³ ΡƒΡ‚ΠΈΠ»ΠΈΡ‚Ρ‹ dialog, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅Ρ‚ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΡƒ newt .
  • zenity β€” Π½Π°ΠΈΠ±ΠΎΠ»Π΅Π΅ популярноС ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ для создания графичСского интСрфСйса ΠΊ скриптам.
  • kdialog β€” Π°Π½Π°Π»ΠΎΠ³ zenity Π² срСдС KDE .
  • yad β€” Ρ„ΠΎΡ€ΠΊ zenity, с большими возмоТностями.
  • xdialog β€” Π·Π°ΠΌΠ΅Π½Π° dialog, прСдназначСнная для придания запускаСмым ΠΈΠ· Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°ΠΌ интСрфСйса X Window System .
  • gtkdialog β€” Π½Π°ΠΈΠ±ΠΎΠ»Π΅Π΅ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΎΠ½Π°Π»ΡŒΠ½Π°Ρ ΡƒΡ‚ΠΈΠ»ΠΈΡ‚Π° для создания графичСских ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΉ Π½Π° bash-скриптах.

See also

  • Π‘Ρ€Π°Π²Π½Π΅Π½ΠΈΠ΅ ΠΊΠΎΠΌΠ°Π½Π΄Π½Ρ‹Ρ… ΠΎΠ±ΠΎΠ»ΠΎΡ‡Π΅ΠΊ
  • ΠŸΠ°ΠΊΠ΅Ρ‚Π½Ρ‹ΠΉ Ρ„Π°ΠΉΠ»
  • GNU Readline

Notes

  1. ↑ Bash-5.0 release available β€” 2019.
  2. ↑ William McCarty. Learning Debian GNU/Linux . 13. Conquering the BASH Shell (Π°Π½Π³Π».) . O'Reilly Media (6 October 1999) . Date of treatment December 6, 2018.
  3. ↑ НСвозмоТно вывСсти Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ, содСрТащСй -n (Π² ΠΎΡ‚Π»ΠΈΡ‡ΠΈΠ΅ ΠΎΡ‚ printf -- '%s\n' "${пСрСмСнная}" ), Ρ‚. ΠΊ. -n интСрпрСтируСтся ΠΊΠ°ΠΊ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ echo .
  4. ↑ Bash Reference Manual .
  5. ↑ Bash News (Π½Π΅ΠΎΠΏΡ€.) .
  6. ↑ BashGuide/TestsAndConditionals β€” Greg's Wiki.
  7. ↑ 1 2 3 4 5 6 7 8 Для получСния Π΄Π΅ΠΉΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ всСх элСмСнтов, Π²ΠΊΠ»ΡŽΡ‡Π°Ρ элСмСнты ΠΈΠ· ΠΏΡ€ΠΎΠ±Π΅Π»ΠΎΠ² ΠΈ пустыС строки, ΠΎΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΠΊΠ°Π²Ρ‹Ρ‡ΠΊΠΈ.
  8. ↑ Π—Π΄Π΅ΡΡŒ апострофы ΡƒΠΏΠΎΡ‚Ρ€Π΅Π±Π»Π΅Π½Ρ‹ ΠΏΡ€Π°Π²ΠΈΠ»ΡŒΠ½ΠΎ.
  9. ↑ bash(1): GNU Bourne-Again SHell β€” Linux man page (Π°Π½Π³Π».) . linux.die.net. Date of treatment July 11, 2017.
  10. ↑ Π£ΡΡ‚Π°Ρ€Π΅Π²ΡˆΠΈΠΉ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚: $[…] .
  11. ↑ env(1) β€” Linux manual page (Π½Π΅ΠΎΠΏΡ€.) . man7.org. Π”Π°Ρ‚Π° обращСния 21 января 2017.

Links

  • Bash Reference Manual (Π°Π½Π³Π».) . β€” ΠžΡ„ΠΈΡ†ΠΈΠ°Π»ΡŒΠ½ΠΎΠ΅ руководство. Π”Π°Ρ‚Π° обращСния 22 ноября 2010. Архивировано 23 августа 2011 Π³ΠΎΠ΄Π°.
  • Bash Reference Manual (Π½Π΅ΠΎΠΏΡ€.) . β€” ΠŸΠ΅Ρ€Π΅Π²ΠΎΠ΄ man -страницы ΠΎΡ‚ 2004 Π³ΠΎΠ΄Π°. Архивировано 18 мая 2012 Π³ΠΎΠ΄Π°.
  • Advanced Bash-Scripting Guide (рус.) . β€” Π Π°ΡΡˆΠΈΡ€Π΅Π½Π½ΠΎΠ΅ руководство ΠΏΠΎ написанию bash-скриптов. Π”Π°Ρ‚Π° обращСния 6 августа 2011. Архивировано 23 августа 2011 Π³ΠΎΠ΄Π°.
  • ЧастыС ошибки программирования Π½Π° Bash (Π½Π΅ΠΎΠΏΡ€.) . Π”Π°Ρ‚Π° обращСния 22 ноября 2010. Архивировано 23 августа 2011 Π³ΠΎΠ΄Π°.
  • Π’Π²Π΅Π΄Π΅Π½ΠΈΠ΅ Π² ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Π½Π° bash (Π½Π΅ΠΎΠΏΡ€.) . Π”Π°Ρ‚Π° обращСния 22 ноября 2010. Архивировано 23 августа 2011 Π³ΠΎΠ΄Π°.
  • Bash (рус.) . openSuse wiki. Π”Π°Ρ‚Π° обращСния 22 ноября 2010. Архивировано 23 августа 2011 Π³ΠΎΠ΄Π°.
  • ОписаниС ΠΊΠΎΠΌΠ°Π½Π΄ bash (Π°Π½Π³Π».) . Π”Π°Ρ‚Π° обращСния 22 ноября 2010. Архивировано 23 августа 2011 Π³ΠΎΠ΄Π°.
  • Π―Π½ Шилдс (Ian Shields). ΠŸΠΎΠ»Π΅Π·Π½Ρ‹Π΅ совСты Linux: ΠŸΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ bash ΠΈ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΡ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² (рус.) . Архивировано 15 октября 2012 Π³ΠΎΠ΄Π°.
Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ β€” https://ru.wikipedia.org/w/index.php?title=Bash&oldid=100477502


More articles:

  • Iolani Palace
  • Val Antonina
  • Turai Rishon
  • Alfonso X
  • Werewolf (2000 film)
  • Shelton Luton
  • Ayu Andre
  • Chudinov, Alexander Viktorovich
  • Blouse
  • Brazil Football Championship 2005

All articles

Clever Geek | 2019