博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bash 字符串分割_如何在Bash中按字符串分割字符串?
阅读量:2516 次
发布时间:2019-05-11

本文共 981 字,大约阅读时间需要 3 分钟。

bash 字符串分割

How to a by string in Bash? For example,

如何在Bash中按字符串 ? 例如,

"a string   separated by" =>["a", "string", "separated", "by", "space"]

and

"a,string,separated,by,comma" =>["a", "string", "separated", "by", "comma"]

You can convert a string to an array using the grammar like

您可以使用如下语法将字符串转换为数组

inarr=(${a})

If the delimiter is not space and delimiter is a single character or a string consisting of 1 or more of the characters, set the IFS like

如果定界符不是空格,并且定界符是单个字符或由1个或多个字符组成的字符串 ,则将IFS设置为

IFS=',' inarr=(${a})

For the examples in the question:

对于问题中的示例:

For the space separated string:

对于以空格分隔的字符串:

$ a="a string   separated by space"$ inarr=(${a})

Check the result:

检查结果:

$ echo ${inarr[@]}a string separated by space

For the ‘,’ separated string, set the IFS:

对于以','分隔的字符串,设置IFS

$ a="a,string,separated,by,comma";$ IFS=',' inarr=(${a});

Check the result:

检查结果:

$ echo ${inarr[@]}a string separated by comma
Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自:

bash 字符串分割

转载地址:http://hqowd.baihongyu.com/

你可能感兴趣的文章
玩转CSS3,嗨翻WEB前端,CSS3伪类元素详解/深入浅出[原创][5+3时代]
查看>>
iOS 9音频应用播放音频之播放控制暂停停止前进后退的设置
查看>>
Delphi消息小记
查看>>
HNOI2016
查看>>
JVM介绍
查看>>
将PHP数组输出为HTML表格
查看>>
Java中的线程Thread方法之---suspend()和resume() 分类: ...
查看>>
经典排序算法回顾:选择排序,快速排序
查看>>
BZOJ2213 [Poi2011]Difference 【乱搞】
查看>>
c# 对加密的MP4文件进行解密
查看>>
AOP面向切面编程C#实例
查看>>
访问修饰符、封装、继承
查看>>
更换pip源到国内镜像,提升pip下载速度.
查看>>
Kendo MVVM 数据绑定(七) Invisible/Visible
查看>>
插入返回ibatis 的selectKey 实现插入数据后获得id
查看>>
解决win7下打开Excel2007,报“向程序发送命令时出现问题”的错误
查看>>
Win form碎知识点
查看>>
避免使用不必要的浮动
查看>>
第一节:ASP.NET开发环境配置
查看>>
sqlserver database常用命令
查看>>