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
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
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.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.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.