Difference between revisions of "BASH"

From Script | Spoken-Tutorial
Jump to: navigation, search
(BASH Shell Scripting)
(BASH Shell Scripting)
Line 22: Line 22:
 
==BASH Shell Scripting==
 
==BASH Shell Scripting==
 
# Introduction to BASH Shell Scripting   
 
# Introduction to BASH Shell Scripting   
#*The bash shell  
+
#*The bash shell  
#**Bash Shell is a Command language interpreter that executes commands.
+
#**commands are read from input device.
+
#**input can be your keyboard or from a external file. 
+
 
#*Bash Shell Script
 
#*Bash Shell Script
#**Series of BASH commands written seqentially in plain text file
 
#*Hello, World! Tutorial
 
#**creating a simple 'hello_world.sh' file using vim editor.
 
#*Shebang [#!/bin/bash]
 
#**The first line of every script is called a shebang.
 
#**It consists of a number sign and an exclamation point character (#!), followed by the full path to the interpreter such as /bin/bash.
 
#*Shell Comments
 
#**adding comments in your BASH programs, to make it more readable using '#'
 
#*echo Statement
 
#**printing a message on the screen using ECHO statement.
 
#*exit status
 
#**terminating your script using EXIT command and returning a numerical value
 
#*Execute a script
 
#**making the script executable using CHMOD command.
 
#*Debug a script
 
#**turning on the debug mode using 'set -x'
 
#*Shell Commands
 
#**Already explained in 'Introduction to linux' section
 
 
# Basics of Shell Scripting  
 
# Basics of Shell Scripting  
#*Variable in a shell
+
#*Variable in a shell.  
#**System Variable      -These are created and maintained by linux bash shell itself.Commonly used system variables HOSTNAME, HOME, USER.
+
#*Command Line arguments .
#**User Defined Variables-These variables are created and maintained by users.
+
#*Variable Declaration
+
#**Global variable -By default all the variables are global, i.e their values remains the same in and outside the function. 
+
#**Local variable  -To declare variables locally use local.The syntax is local variable=value
+
#*Getting user input via Keyboard
+
#**We can accept input from the keyboard and assing an input value to a user defined variable using 'read' command.  
+
#*Command Line arguments  
+
#**A Command line argument is an arguments passed to a program which is been called.
+
#*Quoting
+
#**They are three types of quotes
+
#***1)Double quote
+
#***2)Single quote
+
#***3)Backslash
+
 
#*Globbing
 
#*Globbing
#**Filename expansion carried by BASH is known as Globbing.
 
 
#*The export statement
 
#*The export statement
#**The export command makes available variables to all child processes of the running script or shell
 
 
# Arrays  
 
# Arrays  
 
#*Declaring an Array and Assigning values.
 
#*Declaring an Array and Assigning values.

Revision as of 15:10, 2 May 2013

Bash is the shell, or command language interpreter, that will appear in the GNU operating system. Bash is an sh-compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh). It offers functional improvements over sh for both programming and interactive use. In addition, most sh scripts can be run by Bash without modification. The improvements offered by Bash include: Command line editing, Unlimited size command history, Job Control, Shell Functions and Aliases, Indexed arrays of unlimited size, Integer arithmetic.


In this tutorial we would mainly concentrate on how to use the wide variety of commands of Linux to handle files,directories,processes etc. These tutorials are created using Ubuntu version 12.04 and above. Please see the associated text box of individual spoken tutorials on the website to decide the versions of Linux OS to which it is applicable.

The Spoken Tutorial Effort for Linux is being contributed by Ms. Ashwini Patil and Ms. Lavitha Pereira and Mr. Sachin Patil from IIT Bombay.

Linux Slide Template (TEX Format)                                                                                                                               Glossary
                                         (PPT Format)
                                         (ODP Format)


BASH Shell Scripting

  1. Introduction to BASH Shell Scripting
    • The bash shell
    • Bash Shell Script
  2. Basics of Shell Scripting
    • Variable in a shell.
    • Command Line arguments .
    • Globbing
    • The export statement
  3. Arrays
    • Declaring an Array and Assigning values.
    • Initializing an Array during declaration
    • To find length of Bash Array and length of nth element
    • To print whole Bash Array
  4. More on Arrays
    • Extraction of Array elements
    • Search and replace in an Array element
    • To Add an element to an Array
    • To remove an Element from an Array
  5. Special operations on Arrays
  6. Conditional execution
    • test
    • if...then
    • if...then...else...if
  7. More on If loops
    • nested if
    • Multilevel if-then-else
  8. Logical Operations
    • logical AND
    • logical OR
    • logical NOT
    • Conditional expression using [
    • Conditional expression using [[
  9. Bash comparison- Arithmetic comparison
    • Arithmetic comparison
  10. Bash comparison- String & File attributes
    • String comparison
    • File attributes comparisons
  11. Loops
    • The for loop statement
    • The while loop statement
  12. More on Loops
    • Use of : to set infinite while loop
    • The until loop statement
    • The select loop statement
    • Exit the select loop statement
    • Using the break statement
    • Using the continue statement
  13. The case statement
    • using case
    • creating menus using case
    • multiple options in case
  14. Functions
    • Writing your first shell function
    • Displaying functions
    • Removing functions
    • Defining functions
    • Writing functions
    • Calling functions
    • Pass arguments into a function
    • Local variable
    • Returning from a function
    • Source command
    • Recursive function
    • Putting functions in background
  15. Redirections (error handling)
    • Input and Output
    • Standard input
    • Standard output
    • Standard error
    • Redirection of both standard error and output
    • Appending redirected output
    • Empty file creation
    • Here documents
    • Here strings
    • Assigns the file descriptor (fd) to file for output
    • Assigns the file descriptor (fd) to file for input
    • Closes the file descriptor (fd)
  16. Pipes and filters
    • Linking Commands
    • Multiple commands
    • Putting jobs in background
    • Pipes
    • How to use pipes to connect programs
    • Input redirection in pipes
    • Output redirection in pipes
    • Why use pipes
    • Filters
  17. Signals, process and traps
    • Signals
    • What is a Process?
    • How to view Processes
    • Sending signal to Processes
    • Terminating Processes
    • Shell signal values
    • The trap statement
    • How to clear trap
    • Include trap statements in a script
    • Use the trap statement to catch signals and handle errors
    • What is a Subshell?
    • Compound command
    • Exec command
  18. Making you shell script interactive (using dialog box)
    • Menu driven scripts
    • Getting information about your system
    • Bash display dialog boxes
    • Dialog customisation with configuration file
    • A yes/no dialog box
    • An input dialog box
    • A password box
    • A menu box
    • A progress bar (gauge box)
    • The form dialog for input

Contributors and Content Editors

Ashwini, Lavitha Pereira, Nancyvarkey, PoojaMoolya