Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping in a Bash extended pattern @(..)

I stumbled across "Extended pattern" extglob for Bash. http://wiki.bash-hackers.org/syntax/pattern

I'm investigating this case:

Imagine a directory structure like this:

/basedir/2017/02/26/uniquedirs1/files.log 
/basedir/2017/02/27/uniquedirs2/files.log 
/basedir/2017/02/28/uniquedirs3/files.log 
/basedir/2017/03/01/uniquedirs4/files.log
/basedir/2017/03/02/uniquedirs5/files.log

If I'd like to list the files of the directory 2017/02/27 and 2017/02/28 I can simply write:

ls /basedir/2017/02/@("27"|"28")/*/files.log

Awesome! \o/

Now the question. How can I define multiple directories in a Bash extended pattern?
This doesn't work:

ls /basedir/2017/@("02/28"|"03/01")/*/files.log
ls /basedir/2017/@("02\/28"|"03\/01")/*/files.log

Is there any way I can get to define multiple directories for "Extended pattern"?

like image 415
Asgair Avatar asked Mar 10 '17 13:03

Asgair


1 Answers

Pathname generation only applies patterns to pathname components; they never match the / that separates components. Brace expansion would be cleaner here:

ls /basedir/2017/{2/28,3/01}/*/files.log

which would first expand to

ls /basedir/2017/2/28/*/files.log /basedir/2017/3/01/*/files.log

before performing pathname generation on the two resulting patterns.

like image 92
chepner Avatar answered Nov 09 '22 09:11

chepner