在 Bash 中用另一个字符替换一个字符 [英] Replace one character with another in Bash

查看:32
本文介绍了在 Bash 中用另一个字符替换一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做的是在 bash 的字符串中用一个点(.)替换一个空格().

I need to be able to do is replace a space () with a dot (.) in a string in bash.

我认为这会很简单,但我是新手,所以我无法弄清楚如何为此用途修改类似的示例.

I think this would be pretty simple, but I'm new so I can't figure out how to modify a similar example for this use.

推荐答案

使用内联 shell 字符串替换.示例:

Use inline shell string replacement. Example:

foo="  "

# replace first blank only
bar=${foo/ /.}

# replace all blanks
bar=${foo// /.}

http://tldp.org/LDP/abs/html/string-manipulation.html 了解更多详情.

这篇关于在 Bash 中用另一个字符替换一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆