Search code examples
linuxshellglob

SHELL: How do I use a or operator when defining a string


This may not even be possible but Im writing my first shell script and I need to use a regexp type operator in my string (shown below)

FILES=tif2/name(45|79)*.pdf

Is this possible? Or would I just have to have two strings.

FILES=tif2/name45*.pdf
FILES=tif2/name79*.pdf

Solution

  • Alternatives in the shell globbing syntax use a comma-separated list enclosed by semicolons. Your example becomes:

    FILES=tif2/name{45,79}*.pdf
    

    There's a pretty nice quick reference here to the glob syntax supported by most shells.

    For the more esoteric bash-specific glob syntax, see http://www.gnu.org/software/bash/manual/bashref.html#Shell-Expansions