Почему в скрипте bash
message='123456789'
echo "${message//[0-9]/*}"
отображается *********
, а в
message='123456789'
echo "${message//./*}"
отображается 123456789
?
Вся документация, которую я видел, говорит, что .
соответствует любому символу в регулярном выражении, даже в bash, но это не работает для меня. Как вы подходите любому персонажу в bash?
Где в документации делает она говорит это .
средства какой-либо символ в сопоставлении с образцом? В man bash
это говорит:
Pattern Matching
Any character that appears in a pattern, other than the special
pattern characters described below, matches itself. The NUL
character may not occur in a pattern. A backslash escapes the
following character; the escaping backslash is discarded when
matching. The special pattern characters must be quoted if
they are to be matched literally.
The special pattern characters have the following meanings:
* Matches any string, including the null string.
When the globstar shell option is enabled, and
is used in a pathname expansion context, two
adjacent *s used as a single pattern will match
all files and zero or more directories and
subdirectories. If followed by a /, two
adjacent s will match only directories and
subdirectories.
? Matches any single character.
Регулярные выражения не являются тем же как сопоставлением с образцом оболочки: https://unix.stackexchange.com/questions/439875/why-not-seeing-shell-globs-as-a-dialect-of-regex. Если Вы хотите заменить все символы другим символьным использованием ${parameter/pattern/string}
синтаксис в Bash необходимо использовать ?
как этот:
$ echo "${message//?/*}"
*********
Вы могли использовать .
вместо ?
в программах, которые используют регулярные выражения такой как sed
:
$ sed 's,.,*,g' <<< "$message"
*********