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 am trying to develop a nautilus script which read selected filepath and en-queue in vlc player. Problem is if filename is space separated then we need to add extra '\' in file name. But when i run the vlc with filename, vlc can not read file.

When run in terminal:

vlc --playlist-enqueue filename\ space\ name.extension

it just works well

but when i try to give same command from bash file then vlc can not read file. My script works for non-space filename. What is the problem? Please help. At least give resource. I googled but can not find suitable solution.

Thanks in advance

Edited : my script

#!/bin/sh
path=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
result=""
cnt=0
for i in $path
do
if [ $cnt -eq 0 ]
then
result=$i
else
result=$result'\ '$i
fi
cnt=`expr $cnt + 1`
done
#vlc --playlist-enqueue "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
vlc --playlist-enqueue "$result"
share|improve this question
    
Why don't you enclose the filename in double quotes instead of escaping the spaces? If I understood you right, that should be the solution. –  Patrick T. Oct 29 '11 at 16:11
    
Why don't you enclose the filename in double quotes instead of escaping the spaces? If I understood you right, that should be the solution. –  Patrick T. Oct 29 '11 at 16:11
    
I tried this "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" but vlc read this like this Barcelona%20-%20Panathinaikos%20%285-1%29%2015.09.2010%20all%20goals.flv%0A org name is: Barcelona - Panathinaikos (5-1) 15.09.2010 all goals.flv and also tried "filename\ space.ext" which cause same result –  shantanu Oct 29 '11 at 17:44
    
The problem related to this question is very specific. Too Localized. –  Luis Alvarado Apr 9 '12 at 19:25
    
Is there a specific reason why you use the for construct? From my point of view there are more straight forward alternatives. –  qbi Apr 9 '12 at 21:57

1 Answer 1

up vote 2 down vote accepted

Your source file runs with bin/sh not bin/bash

/bin/sh and /bin/bash are not the same thing. You lose a lot of functionality when you switch to /bin/sh, but it does protect you from some shell expansion concerns.

I would switch the shell from #!/bin/sh to #!/bin/bash and see if that doesn't fix it.

share|improve this answer

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.