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

Passing Multiple Folders to Bash Script via %U

Tags: None
(comma "," separated)
Xplorer4x4
Registered Member
Posts
206
Karma
0
OS
I am trying to write a bash script that can be passed multiple folders, find(recursively) rar files and extract them. The problem is passing multiple selected folders to the script. The exec line of the service menu is:
Exec=konsole --hold --workdir %f -e searchforarchives.sh %U
Note: I am only using konsole for debugging, and will be running the final script from directly in the service menu, the script is in /usr/local/bin/ which shows up in my path.

The script itself looks like this:
Code: Select all
#!/bin/bash
searchextractrar() {
    input="${1}"
    echo "${input}"

    if ${input} -type f -name '*.part01.rar' -exec ark --batch --autodestination --autosubfolder '{}' '+' ';' ; then
        kdialog --passivepopup "Extracting ${file} complete." 60
    else if ${input} -type f -name '*.rar' -exec ark --batch --autodestination --autosubfolder '{}' '+' ';' ; then
        kdialog --passivepopup "Extracting ${file} complete." 60
    else
   kdialog --passivepopup --icon error "No archive found or failed to extract ${file}." 60
      return 1  Change to exit 1 to stop the script on first failure
      fi
   fi
}

for file in ${@} ; do
    searchextractrar ${file}
done

I have added an echo on line 4 to see what folders are passed to Konsole. If I select 1 folder, it echos back the path and handles extraction as it should. If I try to select 2 folders, and pass them to the script, I get no response from echo and simply launches a Konsole defaulting to ~/Documents.

How come %U is not passing multiple folders?


Intel Core i7 2600K CPU
MSI P67A-G45 Mobo
2x4GB Corsair Vengance RAM
Sapphire Raedon 4890HD Vapor-X GPU
1x180 GB Intel 330 SSD
1x80GB Intel X25-M G2 SSD
2x1TB Western Digital HDDs
2x2TB Wester Digital HDDS
Corsair HX520W PSU
Thermaltake Mozart TX Case
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Is your script invoked at all? (ie. can you add test echo lines with fixed strings).


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Xplorer4x4
Registered Member
Posts
206
Karma
0
OS
bcooksley wrote:Is your script invoked at all? (ie. can you add test echo lines with fixed strings).

Well I can't imagine why the script wouldn't be invoked but I suppose it is possible since konsole does't echo anything for ${input} if multiple folders are selected. If a single folder is selected, then it echos the folder name just fine.

As for the echo lines, I am not sure what you mean in this case?


Intel Core i7 2600K CPU
MSI P67A-G45 Mobo
2x4GB Corsair Vengance RAM
Sapphire Raedon 4890HD Vapor-X GPU
1x180 GB Intel 330 SSD
1x80GB Intel X25-M G2 SSD
2x1TB Western Digital HDDs
2x2TB Wester Digital HDDS
Corsair HX520W PSU
Thermaltake Mozart TX Case
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I would suggest adding something like the following:
Code: Select all
echo "This is a test"


To see if your script is actually being executed or if something else is causing the script to not be invoked by Konsole (which sounds like it could be the case).


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Xplorer4x4
Registered Member
Posts
206
Karma
0
OS
Ahh I thought you meant a more elaborate type of echo response. In this case I am not sure how I would provide an echo to see if the script fails to pass to konsole.


Intel Core i7 2600K CPU
MSI P67A-G45 Mobo
2x4GB Corsair Vengance RAM
Sapphire Raedon 4890HD Vapor-X GPU
1x180 GB Intel 330 SSD
1x80GB Intel X25-M G2 SSD
2x1TB Western Digital HDDs
2x2TB Wester Digital HDDS
Corsair HX520W PSU
Thermaltake Mozart TX Case
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
If you add the echo line into your script, then you should see it above the shell which gets launched in Konsole.
Another thing you could try doing is watching the content of ~/.xsession-errors when performing this to see if anything else relevant is output there.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Xplorer4x4
Registered Member
Posts
206
Karma
0
OS
bcooksley wrote:If you add the echo line into your script, then you should see it above the shell which gets launched in Konsole.
Another thing you could try doing is watching the content of ~/.xsession-errors when performing this to see if anything else relevant is output there.


Edit: The answer was in the op. I was using %f and %U in the .desktop file.


Intel Core i7 2600K CPU
MSI P67A-G45 Mobo
2x4GB Corsair Vengance RAM
Sapphire Raedon 4890HD Vapor-X GPU
1x180 GB Intel 330 SSD
1x80GB Intel X25-M G2 SSD
2x1TB Western Digital HDDs
2x2TB Wester Digital HDDS
Corsair HX520W PSU
Thermaltake Mozart TX Case


Bookmarks



Who is online

Registered users: Bing [Bot], gfielding, Google [Bot], markhm, sethaaaa, Sogou [Bot], Yahoo [Bot]