0

I have a folder of audio files. Most are single sounds -- or soundSprites -- while some are several soundSprites concatenated into spriteLists. These spriteLists use a naming convention with a _SL added to the end of the file name. How can I create two arrays of soundSprites and spriteLists? I've tried using find to exclude the spriteLists like so:

soundSprites+=($(find . -maxdepth 1 ! -name "*_SL*"))

But this adds a ./ before every file name which I want to avoid. Instead of figuring out how to then iterate through the array and remove every ./ I can only assume there's an elegant solution to this that I'm simply unaware of.

Any help is greatly appreciated.

Urphänomen
  • 81
  • 1
  • 8
  • The `./` is a feature, you should be glad it's there (otherwise you end up in trouble when `find` finds files whose names start with `-` and you pass them to a command which thinks it's the name of an option which it doesn't support). – tripleee Aug 30 '17 at 04:20

2 Answers2

3

Don't use find here; this will fail for file names that contain characters the shell will use for word-splitting or pathname generation. Instead, use a pattern designed for pathname generation.

shopt -s extglob
soundSprites+=( !(*_SL*) )
chepner
  • 497,756
  • 71
  • 530
  • 681
0

With the information from the best answer of this question: How can I use inverse or negative wildcards when pattern matching in a unix/linux shell? you can do:

    shopt  extglob
    soundSprites=(!(*_SL*))
fineliner
  • 152
  • 2
  • 5
  • chepner was a bit faster, but using += could be dangerous. Don't forget to deactivate the extglob option if you don't need it any longer. – fineliner Aug 29 '17 at 15:48