如何在Bash中的定界符`上分割字符串? [英] How do I split a string on a delimiter ` in Bash?

查看:72
本文介绍了如何在Bash中的定界符`上分割字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅通过以下途径获得modules/bx/motif?

How can I get modules/bx/motif only on the following through pipeline?

$ find . | grep denied
find: `modules/bx/motif': Permission denied

推荐答案

只需使用sed:

find . 2>&1 | sed 's/^[^:]*: .\(.*\).: Permission denied/\1/p;d'

或仅使用的问题,

您的问题代表:

or by using bash only,

As your question stand for bash:

string=$'find: `modules/bx/motif\047: Permission denied'
echo $string 
find: `modules/bx/motif': Permission denied

part=${string#*\`} 
echo ${part%\'*}
modules/bx/motif

这篇关于如何在Bash中的定界符`上分割字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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