bash - Regex not matching name in filepath -
i have folder ipa files. need identify them having appstore
or enterprise
in filename.
mles:drive-ios-swift mles$ ls build com.project.drive-appstore.ipa com.project.test.swift.dev-enterprise.ipa com.project.drive_v2.6.0._20170728_1156.ipa
i've tried:
#!/bin/bash -vee filenameregex="**appstore**" appfile in build-test/*{.ipa,.apk}; if [[ $appfile =~ $filenameregex ]]; echo "$appfile matches" else echo "$appfile not match" fi done
however nothing matches:
mles:drive-ios-swift mles$ ./test.sh build-test/com.project.drive-appstore.ipa not match build-test/com.project.drive_v2.6.0._20170728_1156.ipa not match build-test/com.project.test.swift.dev-enterprise.ipa not match build-test/*.apk not match
how correct script match build-test/com.project.drive-appstore.ipa
?
you confusing between glob string match regex match. greedy glob match *
can use test operator ==
,
#!/usr/bin/env bash filenameglob='*appstore*' # ^^^^^^^^^^^^ single quote regex string appfile in build-test/*{.ipa,.apk}; # skip non-existent files [[ -e $appfile ]] || continue if [[ $appfile == *${filenameglob}* ]]; echo "$appfile matches" else echo "$appfile not match" fi done
produces result
build-test/com.project.drive_v2.6.0._20170728_1156.ipa not match build-test/com.project.drive-appstore.ipa matches build-test/com.project.test.swift.dev-enterprise.ipa not match
(or) regex use greedy match .*
as
filenameregex='.*appstore.*' if [[ $appfile =~ ${filenameregex} ]]; # rest of code
that said match original requirement match enterprise
or appstore
string in file name use extended glob matches in bash
using glob:
shopt -s nullglob shopt -s extglob fileextglob='*+(enterprise|appstore)*' if [[ $appfile == ${fileextglob} ]]; # rest of code
and regex,
filenameregex2='enterprise|appstore' if [[ $appfile =~ ${filenameregex2} ]]; # rest of code
Comments
Post a Comment