Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
pathnames with spaces in servicemenu scripts?!
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
JeroenV
Guru
Guru


Joined: 16 Jul 2002
Posts: 447
Location: Amsterdam / Hamburg

PostPosted: Sat Feb 18, 2006 11:47 pm    Post subject: pathnames with spaces in servicemenu scripts?! Reply with quote

Hi,

I'm writing a script that is called from the service menu (konqueror right click action for multiple selected files).
It should concatenate all selected video files to a chosen filename. The filename is chosen with a "save as" dialog that has to default to the directory the selected files are in.

Now, it looks like this:
Code:

#! /bin/bash

esc() {
   echo $@ | sed -e s/[]\[\{\}\'\ \$\?\"\(\)]/\\\\\&/g
}

unesc() {
   echo $@ | sed -e s/\\\\//g
}

# kdialog --msgbox "\$1: $1"
# kdialog --msgbox "esc \$1: $(esc $1)"
CWD="$(dirname "$(esc $1)")"
# kdialog --msgbox "CWD: $CWD"
# kdialog --msgbox "unesc CWD: $(unesc $CWD)"
# shift
# OFILE="$(kdialog --getsavefilename \\\"$WD\\\" \"*.*\")"
OFILE="$(kdialog --getsavefilename "$(unesc $CWD)" \*)"
if [ "x${OFILE}" = "x" ]; then
   kdialog --error "Invalid filename: \"${OFILE}\""
else
   kdialog --msgbox "Executing \"mencoder -o $(esc ${OFILE}) -oac copy -ovc copy $@\""
   mencoder -o $(esc ${OFILE}) -oac copy -ovc copy $@
fi


As you can see, I've been messing to solve the trouble that escaping/not escaping spaces (and other strange characters) give me. Now everything seems to work, until the last $@
This is the list of files to concatenate, and the path of these files is not escaped, but this is not easy to do, because if I would use my esc function, it would also escape the spaces between the filenames.

Isn't there any sane way of doing stuff like this :?: :!:

P.S. the above bash script is called from my service menu desktop file:
Code:

[Desktop Entry]
ServiceTypes=video/*
Actions=Join video

[Desktop Action Join video]
Name=Join video
Exec=/home/jeroen/bin/videojoin.sh %F


TIA :!:
_________________
Cheers 8)
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you!
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Sun Feb 19, 2006 12:14 am    Post subject: Reply with quote

"$@" should do?
Back to top
View user's profile Send private message
JeroenV
Guru
Guru


Joined: 16 Jul 2002
Posts: 447
Location: Amsterdam / Hamburg

PostPosted: Sun Feb 19, 2006 11:17 am    Post subject: Reply with quote

Unfortunately it doesn't :(

But I tested this on the commandline, and it can't work because
Code:

process -o my\ file.ext  -i "my file part1.ext my file part2.ext my file part3.ext"

is not the same as
Code:

process -o my\ file.ext  -i "my file part1.ext" "my file part2.ext" "my file part3.ext"

(the latter would be correct)

I'm sure this problem must have been encountered by many, but I wasn't able to find usable clues googling around :?: :!:

Any more ideas :?:
_________________
Cheers 8)
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you!
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Sun Feb 19, 2006 12:14 pm    Post subject: Reply with quote

But according to bash manpage, "$@" expands to "a" "b" "c", not "a b c". It works in my scripts...
Back to top
View user's profile Send private message
JeroenV
Guru
Guru


Joined: 16 Jul 2002
Posts: 447
Location: Amsterdam / Hamburg

PostPosted: Sun Feb 19, 2006 2:44 pm    Post subject: Reply with quote

:oops:
You are right...

Apparently the correct solution is the only one I didn't try, probably things went wrong in two places ($OFILE and $@)...
now it's working, and the script is as simple as it should be:

Code:

#! /bin/bash
CWD="$(dirname "$1")"
OFILE="$(kdialog --getsavefilename "$CWD" \*)"

if [ "x$OFILE" = "x" ]; then
   kdialog --error "Invalid filename: \"${OFILE}\""
else
   mencoder -v -o "$OFILE" -oac copy -ovc copy "$@"
fi


Thanks for the inspiration :wink:
_________________
Cheers 8)
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum