Everything Shell Script

  • Home
  • Home

Friday, 7 October 2016

My First Shell Script.

 Niraj Bhagchandani     08:47:00     No comments   

My First Shell script


We are about to write a script for Hello World. After that we will have some flavors of Hello World Program. First let us create a shell script file named. HelloWorld.sh

#!/bin/sh
#This is a comment line!
echo Hello World    #This is also Comment line. 

In this the first line says Unix that the file is to be executed using /bin/sh. This is where Bourne Shell is located.

The Second line is an comment which begins with a special symbol #. This marks the line as a comment, and it is ignored completely by the shell.

The only exception is when the very first line of the file starts with #! - as ours does and this is special derivative. So, if you are using csh, ksh or any other shell it would be interpreted by the Bourne Shell (/bin/sh).

The third line runs a command named echo, with two parameters, or argument i.e. "Hello" and the second is "World".

Now let us give permission to first.sh and then run by following way
Giving Permission: chmod 777 first.sh
Running Shell Script: ./first.sh
or you may also run as: sh first.sh

sh-4.3$ chmod 777 first.sh                                                                                                                                        
sh-4.3$ sh first.sh                                                                                                                                               
Hello World! 
 
You may probably expect the output from terminal itself as...
sh-4.3$ echo Hello World
Hello World
sh-4.3$
 
Now Let us View some more examples on echo ...

#!/bin/sh
#This is a comment!

echo "Hello World"  #This is a comment, Too! 
echo "Too many                  Space"
echo Too many                       Space 
echo "Star * Between"
echo Star * Between
echo "quotes" noquotes
echo Spaces  "                  " Between
echo "Quotes"*"Star"
echo `hello` world
echo 'hello' world
 
You May run the above program on the following link given below. 

Program Link : https://goo.gl/qgNoMp

This is Just the beginning... If you want know more about it do comment me.. Also, we might use more powerful command than echo in future.

Regards,
Niraj Bhagchandani 
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Home

0 comments:

Post a Comment

Amazon Ads

Popular Posts

  • 12 differnet examples of For Loop in Shell Script
    The Link to programs given in this tutorial is:  https://goo.gl/akbcTw Well, to begin with FOR LOOP, I would tell that there are 2 diff...
  • Powerline – Adds Powerful Statuslines and Prompts to Vim Editor and Bash Terminal
    Powerline is a great statusline plugin for Vim editor , which is developed in Python and provides statuslines and prompts for many other...
  • How to install Docker and run Docker containers on Linux Mint 18/18.1
         How to install Docker and run Docker containers on Linux Mint 18/18.1 So, now before going through all the steps update and upg...
  • While Loop in Shell Script
    To run the given example live online please visit the following link: https://goo.gl/mD69Gj There are basic loops in shell script. For ...
  • Until Loop in Shell Script.
    To run these programs online I request you to go to following link: https://goo.gl/xKheU3 The until loop is similar to while loop in shel...
  • Variables in Shell Script - Part 1
      Every Programming language in existence has the concepts of variable – It can be termed as a chunk of memory which can be assigned valu...
  • Escape character in Shell Script
    Okay!! uptil now we have seen a lot of stuffs regarding Shell Script. But how about escape characters Example: What if you want to displa...
  • Wildcards
     A wildcard is a character that can be used as a substitute for any of a class of characters in a search, thereby greatly increasin...
  • My First Shell Script.
    My First Shell script We are about to write a script for Hello World. After that we will have some flavors of Hello World Program. Fir...

Recent Posts

Categories

  • Docker in Mint 18.1
  • Docker Linux Mint
  • Install Docker
  • Install Docker in Mint 18
  • Install Docker Linux Mint
  • tecmint

Pages

  • Home

Text Widget

Blog Archive

  • ►  2017 (1)
    • ►  June (1)
  • ▼  2016 (8)
    • ►  November (1)
    • ▼  October (7)
      • Until Loop in Shell Script.
      • While Loop in Shell Script
      • 12 differnet examples of For Loop in Shell Script
      • Escape character in Shell Script
      • Wildcards
      • Variables in Shell Script - Part 1
      • My First Shell Script.

Page Views:

About Me

Niraj Bhagchandani
View my complete profile

Search Here:

Powered by Blogger.

Sample Text

Copyright © Everything Shell Script | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates