Bash 4, expansão e colocação em minúsculas

0

Eu vejo isso no Bash > A expansão da variável 4.0 é usada para diminuir uma variável. Por exemplo

echo ${variable,,}

Lendo a página de manual eu realmente não entendo por que a casca está convertendo a string para minúsculas.

A sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters, and incr, an optional increment, is an integer. When integers are supplied, the expression expands to each number between x and y, inclusive. Supplied integers may be prefixed with ‘0’ to force each term to have the same width. When either x or y begins with a zero, the shell attempts to force all generated terms to contain the same number of digits, zero-padding where necessary. When characters are supplied, the expression expands to each character lexicographically between x and y, inclusive, using the default C locale. Note that both x and y must be of the same type. When the increment is supplied, it is used as the difference between each term. The default increment is 1 or -1 as appropriate.

Por que a variável é convertida em minúsculas?

    
por Matteo 08.02.2016 / 10:32

2 respostas

3

Você está lendo a seção errada da documentação; olhe para expansão do parâmetro shell .

${parameter^pattern}

${parameter^^pattern}

${parameter,pattern}

${parameter,,pattern}

This expansion modifies the case of alphabetic characters in parameter. The pattern is expanded to produce a pattern just as in filename expansion. Each character in the expanded value of parameter is tested against pattern, and, if it matches the pattern, its case is converted. The pattern should not attempt to match more than one character. The ‘^’ operator converts lowercase letters matching pattern to uppercase; the ‘,’ operator converts matching uppercase letters to lowercase. The ‘^^’ and ‘,,’ expansions convert each matched character in the expanded value; the ‘^’ and ‘,’ expansions match and convert only the first character in the expanded value. If pattern is omitted, it is treated like a ‘?’, which matches every character. If parameter is ‘@’ or ‘*’, the case modification operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘*’, the case modification operation is applied to each member of the array in turn, and the expansion is the resultant list.

    
por 08.02.2016 / 10:39
2

Você está citando a parte "Expansão de contraventamento", "Expansão de contraventamento" não inicia com $ .

Você deve executar este comando:

LESS=+/'\{parameter\^pattern\}' man bash

Para encontrar a parte da "modificação de caso" que começa com $ ( ${ ^^ } ).

    
por 08.02.2016 / 11:17

Tags