View previous topic :: View next topic |
Author |
Message |
JeroenV Guru
Joined: 16 Jul 2002 Posts: 447 Location: Amsterdam / Hamburg
|
Posted: Sat Feb 18, 2006 11:47 pm Post subject: pathnames with spaces in servicemenu scripts?! |
|
|
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
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you! |
|
Back to top |
|
|
frostschutz Advocate
Joined: 22 Feb 2005 Posts: 2977 Location: Germany
|
Posted: Sun Feb 19, 2006 12:14 am Post subject: |
|
|
"$@" should do? |
|
Back to top |
|
|
JeroenV Guru
Joined: 16 Jul 2002 Posts: 447 Location: Amsterdam / Hamburg
|
Posted: Sun Feb 19, 2006 11:17 am Post subject: |
|
|
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
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you! |
|
Back to top |
|
|
frostschutz Advocate
Joined: 22 Feb 2005 Posts: 2977 Location: Germany
|
Posted: Sun Feb 19, 2006 12:14 pm Post subject: |
|
|
But according to bash manpage, "$@" expands to "a" "b" "c", not "a b c". It works in my scripts... |
|
Back to top |
|
|
JeroenV Guru
Joined: 16 Jul 2002 Posts: 447 Location: Amsterdam / Hamburg
|
Posted: Sun Feb 19, 2006 2:44 pm Post subject: |
|
|
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 _________________ Cheers
Jeroen
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
May The Source be with you! |
|
Back to top |
|
|
|