如何在bash中获取字符串的第一部分
发布时间:2020-12-15 22:50:29 所属栏目:安全 来源:网络整理
导读:假设我在bash脚本中有来自ls的以下文件名: things-hd-91-Statistics.dbthings.things_domain_idx-hd-38-Data.db 在bash中,如何能够在任何一种情况下获得字符串’thing’的第一部分? 基本上删除第一个字符串的其余部分 – 或. 解决方法 你会用 parameter ex
假设我在bash脚本中有来自ls的以下文件名:
things-hd-91-Statistics.db things.things_domain_idx-hd-38-Data.db 在bash中,如何能够在任何一种情况下获得字符串’thing’的第一部分? 解决方法
你会用
parameter expansion:
string="things-hd-91-Statistics.db" echo "${string%%-*}" things 在${parameter %% pattern}中,’pattern'( – *)与’parameter’的末尾匹配.结果是删除了最长匹配的’参数’的扩展值. 同样,对于您的其他示例,模式将为%%.* (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |