Selecting track(s) with a rofi-MOC script

Hi everybody. This is my first post ever.
Context. MOC is the default player for my local music folder. It runs on external USB output whenever available. Fast, painless and non-intrusive. However, browsing/searching gets tricky when it comes to the external library (more than a thousand of folders/albums in there). Here come "locate" looking at a dedicated database, and "rofi/dmenu" (multi-select enable) for selecting track(s) and adding selection to MOC playlist.
I'm fine with what I could build around that, playing with a short rofi-locate script by "Gotbletu". It runs safe but not without some flaw. Namely when selecting multiple tracks, mocp -ya would throw "Error: Can't stat /path/to/file" on some entry, usually the first one. No consequence as far as I can see other than playlist occasionally either stopping when reaching that flle or the one next to it, or skipping it; and/or mocp displaying relative path and filename instead of tags.
Thanks in advance to whoever could tell me what I am doing wrong, what makes MOC fail to retrieve pathfile? And how to fix it?

-------
#!/bin/bash
# Source: <https://github.com/gotbletu/shownotes/blob/master/rofi_locate.md>
# rofi/dmenu & locate required; MOC server running on USB audio output; rofi adds selected track(s) to playlist.
# Make sure MOC server can be run; must be running before selection; clear playlist if needed:
if [[ ! "$(grep USB /proc/asound/cards)" ]]; then
echo "No USB output."
exit
else
if [[ ! -z $(pgrep mocp) ]]; then
echo "MOC already running!"
elif [[ ! -z "$(grep RUNNING /proc/asound/card1/*p/*/status)" ]]; then
echo "No Way: output is busy"
exit
else
echo "Running MOC"
mocp -S && mocp -c
fi
fi
# Select track(s) in external library:
cd /full/path/to/external/library
playlist="$(locate -d $HOME/.external.db -r "\w+\.\|flac\|mp3\|m4a$" | cut -c25- | rofi -width 100 -dmenu -i -multi-select -p " ♪ ")"
# Prevent MOC from fooling if selection cancelled:
if [[ "$playlist" ]]; then
mocp -ya "$playlist"
else
exit
fi
# Start playing if needed:
if [[ ! "$(mocp -i Q | grep STOP)" ]]; then
mocp -p
echo "Playing new playlist"
else
echo "Added to playlist"
fi
-------

It seems to me that you might want to remove the quotes around $playlist being passed to MOC:

mocp -ya $playlist

Hi.
Thanks. The problem is, removing quotes would break the path if there is any blank space inside, I guess.
The script works well as is, anyway. I use it mainly to play different versions of a title.
The stripped-down version as no impact anymore on MOC when displaying newly added tracks (pipe to cut removed). But"cat path" error keeps showing. I'd just really like to make it cleaner.

The problem is, removing quotes would break the path if there is any blank space inside, I guess.

Now how did I know you would probably be saying this. It's the reason why we don't use characters like spaces inside filenames.

I'd just really like to make it cleaner.

Apart from not using spaces in filenames, the answer would be to ask the 'rofi' maintainers to include an option to escape such characters in filenames.

def fib (n): #!/bin/bash # rofi/dmenu & locate required; rofi adds selected track(s) to playlist. # Make sure MOC is running: if [[ -z $(pgrep mocp) ]]; then sh $HOME/.moc/mocp-tee && mocp -c fi # Select track(s) in external library (if plugged): cd /path/to/external/library || exit playlist="$(locate -d "$HOME/.external.db" -b "" | rofi -width 100 -dmenu -i -multi-select -p " ♪ ")" # Prevent MOC from fooling if selection cancelled: if [[ "$playlist" ]]; then mocp -ya "$playlist" else exit fi