Linux Stall
  • Home
  • Android
  • How to
  • Perl
  • Tips
  • Tutorials
No Result
View All Result
Linux Stall
No Result
View All Result
Home How to

How to run a Linux Shell Script?

Ayush Goyal by Ayush Goyal
January 5, 2012
in How to
42 3
0
15
SHARES
751
VIEWS
Share on FacebookShare on Twitter

Have you ever wondered how you can run a script in Linux?
Every script that needs to run should have a execute permission. By default it is refrained from such permission. One has to assign execute bit manually. In order to do so execute following command:

#chmod +x SomeScriptFile
OR
#chmod 0755 SomeScriptFile

ls command can be used to check permissions on files:
# ls -l /bin/uname

Output:
-rwxr-xr-x. 1 root root 25948 Feb 8 2011 /bin/uname

[uname is being used for an example, it can be replaced with any script]

To run script:
$ ./SomeScriptFile [Enter]

You can also execute by specifying its full path
$ /full/path/here/SomeScriptFile.sh

For executing it in ksh shell:
$ ksh SomeScriptFile

For executing in bash shell :
$ bash SomeScriptFile

Illustration:

Creating a test shell script test.sh, any text editor can be used.
#!/bin/bash
echo “ Hello, Free World”
echo “ You are at : $(pwd)”

After saving this file, set the execute bit:
$ chmod +x test.sh
$ ./test.sh

./ can be omitted if current directory has its entry in PATH variable. It is advised to have your own bin directory. Add this directory to PATH variable using export command. Move your recently created script in this directory and save all the hassle of writing whole path, now you can execute this command from anywhere. This procedure is shown below:

$ mkdir $HOME/bin
$ export PATH=$PATH:$HOME/bin
$ mv test.sh $HOME/bin
$ test.sh

Tags: bashchmodexporthow tolsshell script
Previous Post

How to install RPM package on Ubuntu?

Next Post

Understanding file permissions and access rights in Linux

Ayush Goyal

Ayush Goyal

Yet another geek!

Related Posts

The three-dimensional network topology infographics with ip addresses 3d illustration
How to

Identifying and Resolving IP Address Conflicts with Linux

July 23, 2020
procmon
How to

Microsoft releases ProcMon (Process Monitor) utility for Linux

July 21, 2020
searching file
How to

How to find files by size in Linux

July 12, 2020
Blue padlock icon computer security system vector
How to

How To Enable TLS Encryption On Postfix

July 12, 2020
Blue padlock icon computer security system Encryption
How to

Running Commands Automatically Over SSH

July 12, 2020
sar command output
How to

How to Install And Enable SAR (SYSSTAT) On Linux Servers

July 12, 2020
Next Post
Understanding file permissions and access rights in Linux

Understanding file permissions and access rights in Linux

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Terms and Conditions
  • Contact Us
  • About Us

© 2012 - 2020 Linux Stall - A place for all your Linux needs.

No Result
View All Result
  • Home
  • Android
  • How to
  • Perl
  • Tips
  • Tutorials

© 2012 - 2020 Linux Stall - A place for all your Linux needs.

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In