【发布时间】:2021-01-04 08:33:27
【问题描述】:
在 bash 中,给定一个路径,例如:
mypath='my/path/to/version/5e/is/7/here'
我想提取包含数字的第一部分。对于我要提取的示例:5e
有没有比使用 while 循环各个部分并检查每个部分是否有数字更好的方法?
while IFS=/ read part
do
if [[ $part =~ *[0-9]* ]]; then
echo "$part"
fi
done <<< "$mypath"
【问题讨论】: