Assign executation permission for a bash script file

Share this post to your friends !

This entry is part 5 of 6 in the series Writing your first script

WriteBash - In this article, we will learn step 2 that is to assign execution permission for a bash script file. In the previous article, you did step 1 of 3 steps to write a bash script file. That is to write a simple script file.

The chmod command is in Linux

The chmod command in Linux is used to assign permissions to files or directories. You can find out more about the chmod command in the Linux Commands category of this blog.

Limited to this article, I will only say how to use chmod to assign permission to a bash script file.

The chmod command syntax is quite simple as shown below:

chmod [permission] file/folder

Assign execution permission to a bash script file

To make an executable bash script file, use one of the following 3 commands, for example I use hello_world script file in the previous article:

chmod a+x hello_world
chmod 755 hello_world
chmod 700 hello_world
assign-executation-permission-for-a-bash-script-file Assign executation permission for a bash script file
“hello_world” script file before and after assigning executable permission to it.

You see the image above, you will see the file hello_world has changed after running the chmod command. At the very least, you can see the file name changes from white to green. On Linux systems, green is displayed for files or directories with executable permission.

So why are there three chmod commands for a script file? When you look up the syntax for using the chmod command, you can see [permission]. This permission can be used with numbers or letters, you will learn more about these numbers in another article.

In this article, you understand the first and second commands are the same for permissions. It allows everyone to execute that script, remember that on a system that not only has one user, there may be many other users. When using the first and second chmod commands, you allow everyone to use that script.

As for the third chmod command, it assigns execution permission to the file, but only you (the owner) can execute that script. That is the difference between the commands.

So you’ve learned the 2nd step in 3 steps to write a first script, continue with the next article.

Continue reading the series«« Previous part: Format of a bash script fileNext part: Script file location and execute script »»
If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.

Share this post to your friends !
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

single post bottom banner
«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.