Quantcast
Channel: Unix Scripting – wikiconsole
Viewing all articles
Browse latest Browse all 10

How To Run a Script In Linux

$
0
0

There are two ways you can execute your shell scripts. Once you have created a script file:

Method 1

Pass the file as an argument to the shell that you want to interpret your script. 

Step 1 :  create the script using vi, ex or ed

For example, the script file show has the following lines

echo Here is the date and time

date  

<span style="color: #000000;"><strong>Step 2</strong> : To run the script, pass the filename as an argument to the sh (shell ) </span>

$ sh show

Here is the date and time

Sat jun 03 13:40:15 PST 2006

<span style="color: #000000;"><strong><span style="text-decoration: underline;">Method 2</span>:</strong></span>

Make your script executable using the chmod command. 

When we create a file, by default it is created with read and write permission turned on and execute permission turned off. A file can be made executable using chmod.

Step 1 :  create the script using vi, ex or ed

For example, the script file show has the following lines

echo Here is the date and time

date 

Step 2 : Make the file executable

             $ chmod u+x script_file

            $ chmod u+x show

Step 3 : To run the script, just type the filename 

            $ show

Here is the date and time

Sat jun 03 13:40:15 PST 2006


Viewing all articles
Browse latest Browse all 10

Trending Articles