Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a script.sh file and type of this file is shellscript file. I want to make this file as application/x-executable file. How can I make it?

share|improve this question
    
related to How do I run .sh files in Terminal? –  TuKsn Jun 18 at 8:02

3 Answers 3

up vote 9 down vote accepted

well you can make it by doing as

chmod +x filename.sh

so it will execute when you call it will

./filename.sh

and you can access that script as application also .

open your terminal and type as below from your home directory .

gedit .bashrc

then in the opened file , type this at last line.

alias <Name_with which you wanna call it >='./filename.sh'

save and close .

Then type this in your terminal source ~/.bashrc to apply the changes you made . then simply type the name you have given there after alias to access your script .

make sure that you have placed in the home directory .

else

alias <Name_with which you wanna call it >='./<path to your script >.sh'

Hope that helps.

share|improve this answer
3  
I think relogin/restart is unnecessary. Either just close the terminal and open new or use source ~/.bashrc in the same terminal. –  Amey Jah Dec 16 '12 at 12:35
    
@AmeyJah yes that thing also work & simple.I forgot that . Thank you . –  AgentCool Dec 16 '12 at 12:36

There are two ways of making a file executable:

GUI Method:

Go to the permissions tab, then tick the box `Execute: [ ] Allow executing file as program.

enter image description here

Terminal / Command method:

You can either use:

cd /to/my/required/directory

Then run

chmod +x filename.extension

Or just run:

chmod +x /path/to/your/filename.extension

chmod does also have some more advanced options:

The spaces are to show that it is split up: - rwx --- ---

The first set of --- is User. The second is Group and the last is Other (anyone else)

r stands for Read, w for Write and x for eXecute.

So to allow everyone to read it, but only Group to execute and User to read and write it (but for some reason not execute) would be:

-rw- rx- r-- But this would be added to the command as:

chmod +rw-rx-r-- /path/to/file.extension

chmod also can do this in numbers. It is based on binary (I think, as it is 1,2 and 4)

So there are these numbers:

Execute by user is 100. Execute by group is 010. Execute by other is 001

Write by user is 200. Write by group is 020. Write by other is 002.

Read by user is 400. Read by group is 040. Read by other is 004.

Then you add these together to get the desired combination.

So to allow everyone to read it, but only Group to execute and User to write it (but for some reason not execute) would be:

400 + 040 + 004 and 010 and 200

That adds up to 600 + 050 + 004 = 654.

You could then run the command.

chmod +654 /path/to/file.extension to set it.

And to set all permissions you can type:

chmod +rwxrwxrwx /path/to/file.extension

Or (this is a bit easier to write, but harder to remember each one):

chmod +777 /path/to/file.extension

Finally, you can do:

chmod -777 /path/to/file.extension

To take all permissions away from everyone.

And:

chmod +300 /path/to/file.extension

To add read and write for user, without affecting any other permissions (e.g. Execute permissions).

This website has a very useful little grid checkbox thing, whereby you can tick the options you want and it gives you the command:

enter image description here

However, not all the possible combinations are sensible to use; the main ones that are used are the following:

755 - Owner has all, and Group and Other can read and execute

700 - Owner has all

644 - Owner can read and write, and Group and Other can read

600 - Owner can read and write

And, if you're using non-trivial user groups:

775 - Owner can read and write, and Group and Other can read

770 - Owner and Group have all, and Other can read and execute

750 - Owner has all, and Group can read and execute

664 - Owner and Group can read and write, and Other can just read

660 - Owner and Group can read and write

640 - Owner can read and write, and Group can read

777 and 666 are rarely used, except in /tmp.

Thanks Ilmari Karonen for pointing out the ones in common usage!

share|improve this answer

Run:

chmod +x /path/to/file.sh

To make it un-executable, run:

chmod -x /path/to/file.sh

For example i created .sh file:

vi tester12.sh

After i write some code on vi editor, i'll exit from vi editor:

:wq!
chmod +x tester12.sh
./tester12.sh
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.