MilesWeb
MilesWeb Hosting Forum

Please login or register.

Login with username, password and session length

 

News:

SMF - Just Installed!


Author Topic: How to write Shell Script ?  (Read 3803 times)

0 Members and 1 Guest are viewing this topic.

Offline saurabhj

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
How to write Shell Script ?
« on: July 17, 2015, 06:28:18 PM »
Following steps are required to write shell script:

(1) Use any editor like vi or mcedit to write shell script.

(2) After writing shell script set execute permission for your script as follows
Quote
syntax:
chmod permission your-script-name

Quote
Examples:
$ chmod +x your-script-name
$ chmod 755 your-script-name
Note: This will set read write execute(7) permission for owner, for group and other permission is read and execute only(5).

(3) Execute your script as
Quote
Syntax:
$ bash your-script-name
$ sh your-script-name
$ ./your-script-name

Quote
Examples:
$ bash bar
$ sh bar
$ ./bar

Note: In the last syntax ./ means current directory, But only . (dot) means execute given command file in current shell without starting the new copy of shell, The syntax for . (dot) command is as follows

Quote
Syntax:
. command-name

Quote
Example:
$ . foo


Now you are ready to write first shell script that will print "Milesweb Hosting Services" on screen. See the common vi command list , if you are new to vi.
Quote
$ vi first
#
# My first shell script
#
clear
echo "Milesweb Hosting Services"

After saving the above script, you can run the script as follows:
Quote
$ ./first

This will not run script since we have not set execute permission for our script first; to do this type command
Quote
$ chmod 755 first
$ ./first

First screen will be clear, then following output will appear on screen.
Quote
Output :
Milesweb Hosting Services

MilesWeb Hosting Forum

How to write Shell Script ?
« on: July 17, 2015, 06:28:18 PM »