Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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:

echo $LAUNCHER
#"/home/.../file1.m4a" "/home/.../file2.m4a"

vlc $LAUNCHER
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

Thanks.


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:

EXTENSION_STRING=".*(m4a|mp3|wma|flac)$"
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)
done
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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