如何在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'
或仅使用 bash 的问题,
您的问题代表bash :
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