Bash 4.3.33 中的字符串替换(小写)- 替换错误错误
String replacement (to lowercase) in Bash 4.3.33 - bad substitution error
我正在尝试使用 bash 中的字符串替换将大写字母更改为小写字母,但出现错误的替换错误。
> a=HEY
> echo $a
HEY
> echo ${a,,}
-bash: ${a,,}: bad substitution
# desired output is hey
我见过类似的问题,但在大多数情况下,它归结为使用 bash 的早期版本。我正在使用 GNU bash 4,但仍然遇到同样的问题。
> bash --version
GNU bash, version 4.3.33(1)-release (x86_64-apple-darwin14.1.0)
这可能是 Mac 的事情?任何帮助将不胜感激。
根据对我的评论的评论,这是答案:
echo $a | tr '[:upper:]' '[:lower:]'
看起来 PATH
中第一个 bash 恰好是 4.3.33,但是 bash 你在 运行ning 在交互式会话中是可能是旧版本。 运行 echo "$BASH_VERSION"
检查。
如果以上正确,运行
type bash
查看较新版本的路径,可能类似于 /opt/local/bin/bash
。我会假设它是。如果您希望它成为您的登录名 shell,请先将其添加到 /etc/shells
sudo -e /etc/shells
之后,用户可以 select 使用 chsh
(change [=25] 作为他们的登录 shell =]shell) 命令
chsh -s /opt/local/bin/bash
我正在尝试使用 bash 中的字符串替换将大写字母更改为小写字母,但出现错误的替换错误。
> a=HEY
> echo $a
HEY
> echo ${a,,}
-bash: ${a,,}: bad substitution
# desired output is hey
我见过类似的问题,但在大多数情况下,它归结为使用 bash 的早期版本。我正在使用 GNU bash 4,但仍然遇到同样的问题。
> bash --version
GNU bash, version 4.3.33(1)-release (x86_64-apple-darwin14.1.0)
这可能是 Mac 的事情?任何帮助将不胜感激。
根据对我的评论的评论,这是答案:
echo $a | tr '[:upper:]' '[:lower:]'
看起来 PATH
中第一个 bash 恰好是 4.3.33,但是 bash 你在 运行ning 在交互式会话中是可能是旧版本。 运行 echo "$BASH_VERSION"
检查。
如果以上正确,运行
type bash
查看较新版本的路径,可能类似于 /opt/local/bin/bash
。我会假设它是。如果您希望它成为您的登录名 shell,请先将其添加到 /etc/shells
sudo -e /etc/shells
之后,用户可以 select 使用 chsh
(change [=25] 作为他们的登录 shell =]shell) 命令
chsh -s /opt/local/bin/bash