Difference between revisions of "BASH/C2/Introduction-to-BASH-Shell-Scripting/English"
(→Bourne Shell- /bin/sh) |
(→Bourne Shell- /bin/sh) |
||
Line 109: | Line 109: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us know different types of '''Shells '''available | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us know different types of '''Shells '''available | ||
− | + | Bourne Shell- /bin/sh | |
* == This was original UNIX shell written by Stephen Bourne. == | * == This was original UNIX shell written by Stephen Bourne. == | ||
Revision as of 12:49, 26 July 2013
Title of script: Introduction to BASH shell scripting
Author: FOSSEE and Spoken-tutorial Team
Keywords: video tutorial, Bash shell, hello world, execute a script
|
|
---|---|
Display Slide | Dear friends, welcome to the spoken tutorial on Introduction to BASH shell scripting. |
Display Slide
Learning Objectives |
In this tutorial, we will learn
|
Display Slide
Prerequisites
|
To follow this tutorial you should be familiar with Linux Operating System
If not, then for relevant Linux tutorials, please visit our website. |
Display slide | For this tutorial I am using
GNU bash version 4 or above is recommended to practice this tutorial. |
Display slide
Bash Shell |
Let us see what a Bash Shell is.
|
Let me show you what is a Bash Shell. | |
Press Ctrl+Alt+T | Open the terminal by pressing
Ctrl+Alt+T keys simultaneously . This will open the 'Gnome-terminal'. |
On the Terminal, type -
echo $SHELL
|
To check which type of shell we are using, type:
echo space dollar sign SHELL('shell' in capital)
|
Highlight
/bin/bash |
You will see the output printed on the next line as:
slash bin slash bash This indicates that we are using the Bash Shell. |
Display Slide
Different Types of Shells Bourne Shell- /bin/sh |
Let us know different types of Shells available
Bourne Shell- /bin/sh
|
C Shell- /bin/csh | C Shell- /bin/csh
It provides features lacking in Bourne Shell |
K Shell- /bin/ksh
|
K Shell- /bin/ksh
It was created by David KornIt has features of both B Shell and C Shell, along with some additional features. |
Bash Shell- /bin/bash | Bash Shell- /bin/bash
|
Display Slide
TC Shell- /bin/tcsh
|
TC Shell- /bin/tcsh
|
Z Shell- /bin/zsh | Z shell- /bin/zsh
|
Display Slide
Bash Shell script |
Now let us see what a Bash Shell script is.
The Bash Shell script
|
Let us see how to write a simple Bash script.
Let us test the echo command, which will print Hello World on the terminal. | |
Switch to the terminal >> type
echo “Hello World”
|
Let's go to the terminal and type:
echo space open double quotes Hello space world close double quotes
|
Output: Hello World | This prints Hello World on the terminal. |
The command worked as expected. | |
Highlight echo “Hello World” | Now, what if we want to use this command in a file? |
Just put this command in a file and execute that file. | |
So, let us write a simple “hello world” script. | |
We will use gedit text-editor for this purpose.
You are free to use your favourite text-editor. | |
Switch to the terminal >> type cd Desktop >> press Enter | I want to create my file on the Desktop.
cd space Desktop
|
Type gedit hello_world.sh >> press Enter | Now type
gedit space hello underscore world dot sh
|
Point to the header of the gedit window | We have opened a new file named hello_world.sh using gedit. |
Type #!/bin/bash
>> press Enter |
In this file, type
hash exclamation slash bin slash bash
|
Highlight this line | This is the first line of every bash script.
It is called shebang or bang line. |
Type # my first Bash script
>> press Enter |
Now, let's add a comment to the file by typing:
hash my space first space Bash space script
|
Highlight #
|
Remember that any line after hash, is treated as a comment.
|
Type echo “Hello World”
>> press Enter
|
Now we can add the command which we used earlier.
echo space open double quotes Hello space world close double quotes
|
Type echo $SHELL
>>Press Enter |
Also in the next line, type:
echo space dollar sign SHELL And press Enter. |
Type echo `date`
>> Press Enter |
Then type:
echo space backtick date backtick
|
Press CTRL+S | Press CTRL+S to save this file.
We will close this file using ALT+F4. |
Switch to the terminal | Now, let's go back to the terminal and make this file executable. |
Type
chmod +x hello_world.sh >> press Enter |
So, type
chmod space plus x space hello underscore world dot sh
|
Type
./ hello_world.sh >> press Enter
|
Now execute this file by typing
dot slash hello underscore world dot sh Press Enter. |
Output: Hello World
|
You can see Hello World displayed on the terminal. |
Output: /bin/bash | The shell type is displayed on the next line. ie slash bin slash bash |
Output: Wed May 8 15:59:36 IST 2013 | We can see that Day, Month, Time, Time zone and Year are displayed.
The output may vary depending on the system. |
Display Slide | Summary
In this tutorial we have learnt about
We also wrote a simple Shell script and executed it. |
Display Slide
Assignment |
Write a simple Bash shell script to display the message -
on separate lines. |
Display Slide
Acknowledgement Slide |
Watch the video available at the following link
It summarises the Spoken Tutorial project If you do not have good bandwidth, you can download and watch it |
Display Slide
Spoken Tutorial Workshops |
The Spoken Tutorial Project Team
Conducts workshops using spoken tutorials Gives certificates to those who pass an online test
contact@spoken-tutorial.org |
Display Slide
Acknowledgement |
Spoken Tutorial Project is a part of the Talk to a Teacher project
It is supported by the National Mission on Education through ICT, MHRD, Government of India More information on this Mission is available at: http://spoken-tutorial.org\NMEICT-Intro |
The script for this tutorial was written by the FOSSEE and Spoken Tutorial Teams, IIT Bombay.
Thank you for joining. |