How to create the shell script in Linux

We can create the shell script file using any text editor like vim, gedit etc.

But the file extension should be .sh.


Example

vim filename.sh




How to run shell script in Linux

Method 1:

sh filename.sh

Method 2:

./filename.sh




Permission denied error while executing the shell script

While running the shell script, if we get "Permission denied" message we should give executable permission to the file.


Example

We can provide the executable permission by using the below command,

chmod +x filename.sh.


chmod (Change Mode) - Using chmod we can change the access permissions to file system objects.

+x - It makes the file executable.


Topics You Might Like