Quantcast
Channel: User Dennis Williamson - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 61

Deduplicating Bash Brace Expansions

$
0
0

Brace expansions can produce multiple instances of file names if there is an overlap in the matches.

A simple example:

mkdir testdir; cd testdir
touch abcd
for f in *{b,c}*; do something_to "$f"; done
# or more simply:
ls -l *{b,c}*

That is a very simplified example just for illustration. In this case, the single file abcd would be processed (or listed) twice.

How can this list be best deduplicated?

  • An associative array could be used.
  • A carefully crafted glob/brace expansion could be used, but that's not robust.

Viewing all articles
Browse latest Browse all 61

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>