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

查看:210
本文介绍了在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天全站免登陆