This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Help passing filenames w/spaces from service menu to script

Tags: None
(comma "," separated)
User avatar
carlosestensser
Registered Member
Posts
51
Karma
0
OS
I want to learn how to pass a series of filenames with spaces from a kde service menu to a bash script in such a way that the script won't confuse white spaces with delimiters.
I've tried all the usual options (%F, %U, etc.) but with no success.
Any help will be welcome.

Although I want to understand it in principle, the specific script in this case is the following:

Code: Select all
#! /bin/bash
CH1=$(kdialog --inputbox "Search for:")
CH2=$(kdialog --inputbox "Replace with:")

where=$(dirname "$@")               # Here is the 1st. problem, obviously
cd "$where"

for i in "$@"
do
    NN=$(basename "$i" | sed "s/"$CH1"/"$CH2"/")
    mv "$i" "$where"/"$NN"
done
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I am not sure entirely, but if spaces are causing an issue here, you may find it helpful to place quotes around the %f / %F / %u / %U markers you are using in your service menu *.desktop file.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
carlosestensser
Registered Member
Posts
51
Karma
0
OS
I am already doing that. :-\
Thanks anyway.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Hm, if I interpret your original post correctly, it could be the quotes causing the problem. Have you tried without them?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
carlosestensser
Registered Member
Posts
51
Karma
0
OS
If I am not mistaken, that wouldn't work either.
Suppose that I select the following files:
/home/darwin/a b.txt
/home/darwin/a.txt

"%F"
would be
"/home/darwin/a b.txt /home/darwin/a.txt"

%F
would be
"/home/darwin/a"
which doesn't exist.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I'm not sure exactly, but I think KDE programatically launches Service Menus, so the quotes are not needed (as the arguments are handled differently from shells).


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
carlosestensser
Registered Member
Posts
51
Karma
0
OS
Damn!
For years I was absolutely sure that that wouldn't work.
Where the hell did you get that information from?

A million thanks!!!!! :) :) :) :)


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft