Skip to content

dv-sharma/Scripting

Repository files navigation

Scripting

This project is for the purpose of learning & implementing Shell Scripting

DAY 1 BASICS

#!/bin/bash is the basic syntax to begin shell scripts

firstscript.sh is the example of first script i created to echo some sentence onto the terminal

VARIABLES

  • Storage location having name or name value pair

  • Case sensitive

  • No spaces before or after = sign

  • Uppercase

  • Syntax: VAR_NAME="value"

    e.g. SHELL_NAME="bash"

  • use the $ sign to use the value of the variable

NOT VALID

  • cannot start with number
  • no special charactetrs
  • only "_" is allowed

OPERATORS

  • 5 types of operators

image

image

image

image

image

CONDITIONAL STATEMENTS/ TESTS

image

TESTS

  • SYNTAX : [Test-condition]

  • Example: [-e /etc/passwd] : This would check if this exists or not and then return TRUE OR FALSE.

  • Mostly used in if else & conditional statements.

UNDERSTANDING nested If

image

image

EXIT CODES

0 means successfull, other number means error

e.g. ls /no/such/folder echo "$?"

here there is no such folder present so exit code will be non zero number

=======

Scripting

This project is for the purpose of learning & implementing Shell Scripting

DAY 1 BASICS

#!/bin/bash is the basic syntax to begin shell scripts

firstscript.sh is the example of first script i created to echo some sentence onto the terminal

VARIABLES

  • Storage location having name or name value pair

  • Case sensitive

  • No spaces before or after = sign

  • Uppercase

  • Syntax: VAR_NAME="value"

    e.g. SHELL_NAME="bash"

  • use the $ sign to use the value of the variable

NOT VALID

  • cannot start with number
  • no special charactetrs
  • only "_" is allowed

OPERATORS

  • 5 types of operators

image

image

image

image

image

CONDITIONAL STATEMENTS/ TESTS

image

TESTS

  • SYNTAX : [Test-condition]

  • Example: [-e /etc/passwd] : This would check if this exists or not and then return TRUE OR FALSE.

  • Mostly used in if else & conditional statements.

UNDERSTANDING nested If

image

image

DAY 2 EXIT CODES

  • 0 means successfull, other number means error

e.g. ls /no/such/folder echo "$?"

  • here there is no such folder present so exit code will be non zero number.

FUNCTIONS

SYNTAX image

  • Good practise to call functions at top
  • Can't operate on exit status code
  • scope of global variable is outside the brackets.

image

image

LOGGING

image

DEBUGGING

image

SED EDITOR

image

About

This project is for the purpose of learning & implementing Shell Scripting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages