I'm making a program that launches vlc with a set of files saved in a variable.

But it doesn't work it seems to have a problem with the names, what is weird (for me) is that in the end the problem is summed up by this:

#"/home/.../file1.m4a" "/home/.../file2.m4a"

vlc $(echo $LAUNCHER)
#Doesn't work

vlc "/home/.../file1.m4a" "/home/.../file2.m4a"
# Works!!

So what am I doing wrong? By the way I need the quotes for the spaced named files


Here is how I set the LAUNCHER:

I have an array with the selected folders that contain the files you want to reproduce, then I create an array of files of those folders:

for i in "${DIR_LIST[@]}"; do
    while ISF= read -r -d $'\0' file; do
         FILES_LIST+=( "$file" )
    done < <(find "$i" -type f -regextype posix-extended -regex "$EXTENSION_STRING" -print0)

If you want to use a list of files with bash, you are much better off using an array, my guess is vlc is treating the list of files as one argument instead of separate arguments,

"/foo /bar" is not the same as "/foo" "/bar"

try this instead.

LAUNCHER=("/home/foo.mp4" "/home/bar.mp4")

vlc "${LAUNCHER[@]}"

Quoting the array expansion you can avoid misinterpretation of spaced named filenames

The other option is to use xargs. would help if you explain how you get the values for LAUNCHER if I'm even reading that right.

  • The funny thing is that I had them inside an array and I don't know why I made a code to make that variable from the array... It works perfectly. Thanks! – Vndtta Jan 8 '13 at 8:33
  • I now realized why I made it. Because when I tried that with spaced names it went all crazy. the solution is as simple as quoting the array expansion: vlc "${LAUNCHER[@]}" – Vndtta Jan 8 '13 at 12:02
  • 1
    yes always quote paths, its annoying but its the best practice. not just for array but in generally. – strings Jan 8 '13 at 17:37
  • So how do you get the values for LAUNCHER? – Gerhard Burger Jan 11 '13 at 13:18
  • @GerhardBurger I pasted the code in the answer below, here is not well seen – Vndtta Jan 11 '13 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.