Jump to content

How do I make a shell script executable?


luvpats
 Share

Recommended Posts

I am attempting to do this:

 

 

Add Copy To Folder to right-click context menu PCManFM:
Thefollowing local action copies the selected file or folder to anotherfolder selected graphically via zenity.
First, create a bashscript called copytofolder.sh in your ~/bin folder with the following content and make the file executable:
#!/bin/bash
folder=$(zenity--file-selection --directory --title="Copy To Folder")
if [[ $folder ]];then
# cp -r $@"$folder"
for var in "$@"
do
cp -r "$var""$folder"
done
fi
Then create thefollowing copy-to-folder.desktop custom menu action:
[Desktop Entry]
Type=Action
ToolbarLabel[en_US]=CopyTo Folder
ToolbarLabel[en]=CopyTo Folder
ToolbarLabel[C]=CopyTo Folder
Name[en_US]=Copy ToFolder
Name[en]=Copy ToFolder
Name[C]=Copy ToFolder
Profiles=profile-zero;
[X-Action-Profileprofile-zero]
Exec=/home/username/bin/copytofolder.sh%F
Name[en_US]=Defaultprofile
Name[en]=Defaultprofile
Name[C]=Defaultprofile
Replace usernamewith your user name. This action will copy all selected files andfolder (hence %F) to another folder of choice. You can define asimilar action Move To Folder by having a similar script using the mvcommand rather than the cp -r one.
I was able to create the .sh script but I cannot seem to make it executable. It still says "shell script" within the /bin folder.
The command: sudo chmod u+x /bin/copytofolder.sh does not make the script executable.
I was able to create the Copy To option within the Context Menu but it does not work apparently unless I make the script executable.
Any assistance would be greatly appreciated. Thank you!
Link to comment
Share on other sites

not sure what distro your using but in suse using dolphin, all i do to make a file executable is right click on it, click properties then click on the permissions tab in the opened window and put a tick in the is executable box.

 

:b33r:

Link to comment
Share on other sites

I am utilizing Lubuntu 14.04 and PCManFm. There is no check box when I click on Properties-Permissions. The only options under Access Control are:

 

View Content-currently set as Anyone;

Change Content-currently set as anyone

Execute-currently set as anyone (no way to make executable as there is no check box)

 

I notice some of the other .sh scripts are under root as the owner however the owner of the copytofolder.sh is the default profile

Link to comment
Share on other sites

 

Execute-currently set as anyone

that to me says it is already executable, otherwise i'd expect it to say currently set as no-one.

 

can you run this command from where the script is located and see what the permissions are.

ls -l copytofolder.sh

they should be something like this "-rwxr-xr-x" where the x's show the file is executable.

 

:b33r:

 

this explains how to read and understand the permissions from that command :- http://www.linux.com/learn/tutorials/309527-understanding-linux-file-permissions

 

the problem may not be that it is not executable, it may be because the Copy to Folder is incorrectly named here :-

 

[Desktop Entry]
Type=Action
ToolbarLabel[en_US]=CopyTo Folder
ToolbarLabel[en]=CopyTo Folder
ToolbarLabel[C]=CopyTo Folder
Name[en_US]=Copy ToFolder
Name[en]=Copy ToFolder
Name[C]=Copy ToFolder
Profiles=profile-zero;

notice the spacing is wrong in the file name, so unless it is exactly the same "Copy to Folder" and not "CopyTo Folder" or "Copy ToFolder" then i don't believe it will work anyway.

 

also is the file in the

/bin/

folder or where it should be

/home/YOURUSERNAMEHERE/bin/

folder, of course "YOURUSERNAMEHERE" is going to be luvpats or whatever your default user name is.

 

and this command

Exec=/home/username/bin/copytofolder.sh%F

should read

Exec=/home/luvpats/bin/copytofolder.sh%F

or whatever your default username is.

 

also not sure what the %F is for at the end of that command or if there should be a space there so if it still doesn't work maybe just try

Exec=/home/luvpats/bin/copytofolder.sh
Edited by terry1966
Link to comment
Share on other sites

how you getting on luvpats?

 

and that last command needs the %F to copy folders it seems after reading first post again but there should be a space so it should read.

Exec=/home/luvpats/bin/copytofolder.sh %F

where of course luvpats is whatever your default user name is.

 

:b33r:

Link to comment
Share on other sites

I very much apologize for the late reply. Thank you so very much for all the advice and guidance.

 

I have been able to add Copy To & Move To within the right-click Context Menu. The functionality is limited but I have been able to get both custom actions to work. It will work-to a point. It is not perfect but somewhat functional. I have found it easier to utilize the Context Menu than going up to the Edit column.

 

Now I wish there was a way to re-order the Context Menu as Move To appears above Copy To and both appear at the end of the Context Menu. If anyone has an answer please let me know. So far I haven't been able to find a configuration file so I can re-order the Context Menu.

 

You do have to create the ~bin folder in the home/username directory. I was able to make both shell scripts executable within the newly created folder.

 

Thank you again for all the assistance. I really appreciate it very much!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...