0

The following command works on cli itself:

someCall prefix.+([[:digit:]]).postfix

But NOT in bash script.

The idea is that I want to give files with names like prefix.1.postfix oder prefix.112.postfix to the program.

What do I have to change in the script?

EDIT: forgot to mention the error it throws:

syntax error near unexpected token `('

EDIT 2: If I source the bash script with source myScript.sh then it works :-\

2 Answers 2

1

You seem to be confusing shell globbing and regex matching. These are different things and use different meta characters.

There is no way in (standard POSIX) globbing to express "one or more of this", as the regex + quantifier does.

However, you could try if this is selective enough:

$ touch prefix.1.postfix
$ echo prefix.[[:digit:]]*.postfix
prefix.1.postfix
Sign up to request clarification or add additional context in comments.

3 Comments

Oh, sorry, my wording was then wrong. So it's called globbing. Thx.
What I still do not get: The command in the initial question works now (see Edit 2). So is this now globbing or regex?
@Michael It's globbing if the shell does pathname expansion with it; it's regex when used as the argument to grep, egrep or other regex utilities. If I run a command like echo foo(bar)baz I get a syntax error both at the prompt, and when sourcing a file with that line. There's something you're not telling us.
1

Put + after ([[:digit:]]) and escape .:

^prefix\.([[:digit:]])+\.postfix$

Also if you don't need the captured group of digits, do:

^prefix\.[[:digit:]]+\.postfix$

1 Comment

Does not help, still gives me the error mentioned in the question (sry, forgot that initially)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.