SlideShare una empresa de Scribd logo
1 de 18
UNIX




       Advance Shell Scripting



                 Presentation By

                           Nihar R Paital
Introduction

Advance features of shell scripting/command
such as:

   Local and Global Shell variable
   Customizing User Environment
   Functions
   User interface
   Conditional execution
   File Descriptors
   traps
   Multiple command line args handling
                                              Nihar R Paital
/dev/null

This is special Linux file which is used to send any
unwanted output from program/command.
Syntax:
command > /dev/nullExample:

$ ls > /dev/null

Run the following two commands
$ ls > /dev/null
$ rm > /dev/null
1) Why the output of last command is not redirected to /dev/null
   device?
                                                       Nihar R Paital
Local and Global Shell variable




Local Shell variable


$a=20
$echo $a
Output : 20
$/bin/sh         # Entering into New Shell
$ echo $a
Output :
Empty Line Printed due to a is not defined in new shell
$ a=50
$ echo $a
Output : 50
$ exit                     #Returned to Old Shell by exiting Old Shell
$echo $a
Output : 20
$

                                                        Nihar R Paital
Local and Global Shell variable



Global Shell Variable

To set global varible you have to use export command.
   Syntax:
   export variable1, variable2,.....variableN
   $a=500         # Create local variable a with value 500
   $echo $a
   Output : 500
   $export a      # a became global variable by export command
   $/bin/sh       # Entering into New Shell
   $ echo $a
   Output : 500   # Value of a is constant from old to new as it is global
   $ exit
   $echo $a
   Output : 500
   $
                                                          Nihar R Paital
Customizing User Environment

The most basic means of customization that the Korn shell provides are

       Aliases
        Synonyms for commands or command strings that you can define
        for convenience.

       Options
        Controls for various aspects of your environment, which you can
        turn on and off.

       Variables
        Place-holders for information that tell the shell and other programs
        how to behave under various circumstances. To customize the
        environment various built-in shell variables are available.
                                                           Nihar R Paital
Customizing User Environment




Customizing User Environment


>To change the values of variables permanently , define it in .profile file.


The .profile File
 This is a file of shell commands, also called a shell script, that the Korn
   shell reads and runs whenever you log in to your system.

   Various environment variables can be defined in this file

   Alias can be defined in .profile file



                                                            Nihar R Paital
Customizing User Environment




Aliases

  Alias is a synonym for a command or command string
 Syntax:
          alias new=original
Ex:-
   alias search=grep
   alias cdnew=‘cd /xyz/x1/x2’

>Quotes are necessary if the string being aliased consists of more than
     one word
>it is possible to alias an alias, aliases are recursive

Ex:-
   alias c=cdnew
 Type alias without any arguments, to get a list of all the aliases you
   have defined as well as several that are built-in.
 The command unalias name removes any alias definition for its argument
                                                           Nihar R Paital
Customizing User Environment




set command.


   set command

    –   Used for display all the environment variables.
    –   Shows the current values of system variables.
    –   Also allows conversion of arguments into positional
        parameters.
    –   Syntax : set




                                                    Nihar R Paital
Customizing User Environment




Set Options

   Options let you change the shell's behaviour
   A shell option is a setting that is either "on" or "off."
   The basic commands that relate to options are set -o optionnames and
    set +o optionnames
where optionnames is a list of option names separated by blanks
The - turns the named option on, while the + turns it off
Option                 Description
emacs                  Enter emacs editing mode
ignoreeof              Don't allow use of [CTRL-D] to log off; require the exit
                       command
noclobber              Don't allow output redirection (>) to clobber an existing file
noglob                 Don't expand filename wildcards like * and ? (wildcard
                                   expansion is sometimes called globbing)
nounset                Indicate an error when trying to use a variable that is
                       undefined
vi                     Enter vi editing mode
xtrace                 traces shell scripting
noexec                 finds syntax error without executing script
   To check the status of an option, type
           set -o                                                      Nihar R Paital
Customizing User Environment




Shell Variables

     Shell variables can specify everything from your prompt string to how
      often the shell checks for new mail
     built-in variables have names in all capital letters
     The syntax for defining variables is
      $ varname=value
     if the value is more than one word, it must be surrounded by quotes
     To delete a variable type the command
      $ unset varname
Ex:
      $ a=20
      $ echo $a
      Output: 20
      $ unset a
      $ echo $a
      Output: Empty Line
                                                           Nihar R Paital
Customizing User Environment




Print Command


  To check value of a variable print built-in command can be
   used
 Print command is strongly recommended over echo because
   its options are the same on all UNIX systems, whereas echo's
   options differ between BSD-derived and System V-derived
   UNIX versions.
Ex:-     print “$x”




                                                 Nihar R Paital
Customizing User Environment




System Variables or Built-in Variables


   PATH
     – Search path referred by Unix for any command.
     – echo $PATH
   HOME
     – Indicates the home directory for the user.
     – echo $HOME


     In the bash shell, command history is controlled by which group of the
     following environment variables.
     HISTCMD, HISTFILE, HISTSIZE, HISTFILESIZE

   HISTFILE
     - Name of history file, on which the editing modes operate.
   HISTSIZE
     – Number of lines kept in history file


                                                                   Nihar R Paital
Customizing User Environment




System Variables (Contd).

   FCEDIT
     – Pathname of editor to use with the fc command.
   PS1
     – Used for displaying & changing the primary prompt.
     – echo $PS1
   PS2
     – Used for changing the secondary prompt.
   MAIL
     – Name of file to check for incoming mail (i.e., your mail file)
   MAILCHECK
     – How often, in seconds, to check for new mail (default 600
       seconds, or 10 minutes)                        Nihar R Paital
Customizing User Environment




System Variables (Contd).


   SHELL
     – Pathname of the shell you are running


   PWD
     – Current directory


   HOME
     – Users home directory




                                                 Nihar R Paital
Customizing User Environment




Environment Variables


   Environment Variables are known to all kinds of subprocesses
   Any variable can become an environment variable. First it must be
    defined as usual; then it must be exported with the command
          $ export varnames
   To find out environment variables and their values ,type
        $ export




                                                      Nihar R Paital
Customizing User Environment




The Environment File

   Although environment variables will always be known to
    subprocesses,
   the shell must define which other variables, options, aliases,
    etc., are to communicated to subprocesses.
    The way to do this is to put all such definitions in a special file
    called the environment file instead of your .profile.
1. Decide which definitions in your .profile you want to propagate
    to subprocesses. Remove them from .profile and put them in a
    file you will designate as your environment file.
2. Put a line in your .profile that tells the shell where your
    environment file is:
    ENV=envfilename
3 . For the changes to take effect, type either . .profile or login. In
    either case, your environment file will be run when the shell
    encounters the ENV= statement.
                                                      Nihar R Paital
Nihar R Paital

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Subroutines in perl
Subroutines in perlSubroutines in perl
Subroutines in perl
 
Awk programming
Awk programming Awk programming
Awk programming
 
Subroutines
SubroutinesSubroutines
Subroutines
 
Syntax
SyntaxSyntax
Syntax
 
Awk essentials
Awk essentialsAwk essentials
Awk essentials
 
PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer.
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
 
Petitparser at the Deep into Smalltalk School 2011
Petitparser at the Deep into Smalltalk School 2011Petitparser at the Deep into Smalltalk School 2011
Petitparser at the Deep into Smalltalk School 2011
 
Mastering Grammars with PetitParser
Mastering Grammars with PetitParserMastering Grammars with PetitParser
Mastering Grammars with PetitParser
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
Perl 101 - The Basics of Perl Programming
Perl  101 - The Basics of Perl ProgrammingPerl  101 - The Basics of Perl Programming
Perl 101 - The Basics of Perl Programming
 
Licão 13 functions
Licão 13 functionsLicão 13 functions
Licão 13 functions
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
 
Practical approach to perl day2
Practical approach to perl day2Practical approach to perl day2
Practical approach to perl day2
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 
String variable in php
String variable in phpString variable in php
String variable in php
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 

Destacado

Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanshipbokonen
 
Trouble shoot with linux syslog
Trouble shoot with linux syslogTrouble shoot with linux syslog
Trouble shoot with linux syslogashok191
 
Karkha unix shell scritping
Karkha unix shell scritpingKarkha unix shell scritping
Karkha unix shell scritpingchockit88
 
Module 13 - Troubleshooting
Module 13 - TroubleshootingModule 13 - Troubleshooting
Module 13 - TroubleshootingT. J. Saotome
 
Advanced Oracle Troubleshooting
Advanced Oracle TroubleshootingAdvanced Oracle Troubleshooting
Advanced Oracle TroubleshootingHector Martinez
 
Linux troubleshooting tips
Linux troubleshooting tipsLinux troubleshooting tips
Linux troubleshooting tipsBert Van Vreckem
 
unix training | unix training videos | unix course unix online training
unix training |  unix training videos |  unix course  unix online training unix training |  unix training videos |  unix course  unix online training
unix training | unix training videos | unix course unix online training Nancy Thomas
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingDan Morrill
 
25 Apache Performance Tips
25 Apache Performance Tips25 Apache Performance Tips
25 Apache Performance TipsMonitis_Inc
 
Fusion Middleware 11g How To Part 2
Fusion Middleware 11g How To Part 2Fusion Middleware 11g How To Part 2
Fusion Middleware 11g How To Part 2Dirk Nachbar
 
Sql server troubleshooting
Sql server troubleshootingSql server troubleshooting
Sql server troubleshootingNathan Winters
 
Linux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA'sLinux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA'sMydbops
 
Oracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention TroubleshootingOracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention TroubleshootingTanel Poder
 
Cloug Troubleshooting Oracle 11g Rac 101 Tips And Tricks
Cloug Troubleshooting Oracle 11g Rac 101 Tips And TricksCloug Troubleshooting Oracle 11g Rac 101 Tips And Tricks
Cloug Troubleshooting Oracle 11g Rac 101 Tips And TricksScott Jenner
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scriptingVIKAS TIWARI
 
Advanced Bash Scripting Guide 2002
Advanced Bash Scripting Guide 2002Advanced Bash Scripting Guide 2002
Advanced Bash Scripting Guide 2002duquoi
 

Destacado (20)

Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanship
 
Trouble shoot with linux syslog
Trouble shoot with linux syslogTrouble shoot with linux syslog
Trouble shoot with linux syslog
 
Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02
 
Karkha unix shell scritping
Karkha unix shell scritpingKarkha unix shell scritping
Karkha unix shell scritping
 
Module 13 - Troubleshooting
Module 13 - TroubleshootingModule 13 - Troubleshooting
Module 13 - Troubleshooting
 
APACHE
APACHEAPACHE
APACHE
 
Advanced Oracle Troubleshooting
Advanced Oracle TroubleshootingAdvanced Oracle Troubleshooting
Advanced Oracle Troubleshooting
 
Linux troubleshooting tips
Linux troubleshooting tipsLinux troubleshooting tips
Linux troubleshooting tips
 
unix training | unix training videos | unix course unix online training
unix training |  unix training videos |  unix course  unix online training unix training |  unix training videos |  unix course  unix online training
unix training | unix training videos | unix course unix online training
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scripting
 
25 Apache Performance Tips
25 Apache Performance Tips25 Apache Performance Tips
25 Apache Performance Tips
 
Fusion Middleware 11g How To Part 2
Fusion Middleware 11g How To Part 2Fusion Middleware 11g How To Part 2
Fusion Middleware 11g How To Part 2
 
Sql server troubleshooting
Sql server troubleshootingSql server troubleshooting
Sql server troubleshooting
 
Tomcat next
Tomcat nextTomcat next
Tomcat next
 
Tomcat
TomcatTomcat
Tomcat
 
Linux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA'sLinux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA's
 
Oracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention TroubleshootingOracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention Troubleshooting
 
Cloug Troubleshooting Oracle 11g Rac 101 Tips And Tricks
Cloug Troubleshooting Oracle 11g Rac 101 Tips And TricksCloug Troubleshooting Oracle 11g Rac 101 Tips And Tricks
Cloug Troubleshooting Oracle 11g Rac 101 Tips And Tricks
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Advanced Bash Scripting Guide 2002
Advanced Bash Scripting Guide 2002Advanced Bash Scripting Guide 2002
Advanced Bash Scripting Guide 2002
 

Similar a UNIX - Class4 - Advance Shell Scripting-P1

Licão 09 variables and arrays v2
Licão 09 variables and arrays v2Licão 09 variables and arrays v2
Licão 09 variables and arrays v2Acácio Oliveira
 
Linux shell env
Linux shell envLinux shell env
Linux shell envRahul Pola
 
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
 of 70UNIX Unbounded 5th EditionAmir Afzal .docx of 70UNIX Unbounded 5th EditionAmir Afzal .docx
of 70UNIX Unbounded 5th EditionAmir Afzal .docxMARRY7
 
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
of 70UNIX Unbounded 5th EditionAmir Afzal .docxof 70UNIX Unbounded 5th EditionAmir Afzal .docx
of 70UNIX Unbounded 5th EditionAmir Afzal .docxadkinspaige22
 
Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell Ahmed El-Arabawy
 
Customizing the unix environment
Customizing the unix environmentCustomizing the unix environment
Customizing the unix environmentDr. Girish GS
 
(Ebook) linux shell scripting tutorial
(Ebook) linux shell scripting tutorial(Ebook) linux shell scripting tutorial
(Ebook) linux shell scripting tutorialjayaramprabhu
 
Shellvariables in Linux
Shellvariables in Linux Shellvariables in Linux
Shellvariables in Linux bhatvijetha
 
101 3.1 gnu and unix commands
101 3.1 gnu and unix commands101 3.1 gnu and unix commands
101 3.1 gnu and unix commandsAcácio Oliveira
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdfharikrishnapolaki
 
Using Unix
Using UnixUsing Unix
Using UnixDr.Ravi
 

Similar a UNIX - Class4 - Advance Shell Scripting-P1 (20)

Licão 09 variables and arrays v2
Licão 09 variables and arrays v2Licão 09 variables and arrays v2
Licão 09 variables and arrays v2
 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Linux shell env
Linux shell envLinux shell env
Linux shell env
 
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
 of 70UNIX Unbounded 5th EditionAmir Afzal .docx of 70UNIX Unbounded 5th EditionAmir Afzal .docx
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
 
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
of 70UNIX Unbounded 5th EditionAmir Afzal .docxof 70UNIX Unbounded 5th EditionAmir Afzal .docx
of 70UNIX Unbounded 5th EditionAmir Afzal .docx
 
Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Customizing the unix environment
Customizing the unix environmentCustomizing the unix environment
Customizing the unix environment
 
21bUc8YeDzZpE
21bUc8YeDzZpE21bUc8YeDzZpE
21bUc8YeDzZpE
 
21bUc8YeDzZpE
21bUc8YeDzZpE21bUc8YeDzZpE
21bUc8YeDzZpE
 
21bUc8YeDzZpE
21bUc8YeDzZpE21bUc8YeDzZpE
21bUc8YeDzZpE
 
(Ebook) linux shell scripting tutorial
(Ebook) linux shell scripting tutorial(Ebook) linux shell scripting tutorial
(Ebook) linux shell scripting tutorial
 
Shellvariables in Linux
Shellvariables in Linux Shellvariables in Linux
Shellvariables in Linux
 
Shellscripting
ShellscriptingShellscripting
Shellscripting
 
101 3.1 gnu and unix commands
101 3.1 gnu and unix commands101 3.1 gnu and unix commands
101 3.1 gnu and unix commands
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Linux And perl
Linux And perlLinux And perl
Linux And perl
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdf
 
Using Unix
Using UnixUsing Unix
Using Unix
 

Más de Nihar Ranjan Paital

Más de Nihar Ranjan Paital (8)

Oracle Select Query
Oracle Select QueryOracle Select Query
Oracle Select Query
 
Useful macros and functions for excel
Useful macros and functions for excelUseful macros and functions for excel
Useful macros and functions for excel
 
Unix - Class7 - awk
Unix - Class7 - awkUnix - Class7 - awk
Unix - Class7 - awk
 
UNIX - Class2 - vi Editor
UNIX - Class2 - vi EditorUNIX - Class2 - vi Editor
UNIX - Class2 - vi Editor
 
UNIX - Class6 - sed - Detail
UNIX - Class6 - sed - DetailUNIX - Class6 - sed - Detail
UNIX - Class6 - sed - Detail
 
Test funda
Test fundaTest funda
Test funda
 
Csql for telecom
Csql for telecomCsql for telecom
Csql for telecom
 
Select Operations in CSQL
Select Operations in CSQLSelect Operations in CSQL
Select Operations in CSQL
 

Último

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Último (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

UNIX - Class4 - Advance Shell Scripting-P1

  • 1. UNIX Advance Shell Scripting Presentation By Nihar R Paital
  • 2. Introduction Advance features of shell scripting/command such as:  Local and Global Shell variable  Customizing User Environment  Functions  User interface  Conditional execution  File Descriptors  traps  Multiple command line args handling Nihar R Paital
  • 3. /dev/null This is special Linux file which is used to send any unwanted output from program/command. Syntax: command > /dev/nullExample: $ ls > /dev/null Run the following two commands $ ls > /dev/null $ rm > /dev/null 1) Why the output of last command is not redirected to /dev/null device? Nihar R Paital
  • 4. Local and Global Shell variable Local Shell variable $a=20 $echo $a Output : 20 $/bin/sh # Entering into New Shell $ echo $a Output : Empty Line Printed due to a is not defined in new shell $ a=50 $ echo $a Output : 50 $ exit #Returned to Old Shell by exiting Old Shell $echo $a Output : 20 $ Nihar R Paital
  • 5. Local and Global Shell variable Global Shell Variable To set global varible you have to use export command. Syntax: export variable1, variable2,.....variableN $a=500 # Create local variable a with value 500 $echo $a Output : 500 $export a # a became global variable by export command $/bin/sh # Entering into New Shell $ echo $a Output : 500 # Value of a is constant from old to new as it is global $ exit $echo $a Output : 500 $ Nihar R Paital
  • 6. Customizing User Environment The most basic means of customization that the Korn shell provides are  Aliases Synonyms for commands or command strings that you can define for convenience.  Options Controls for various aspects of your environment, which you can turn on and off.  Variables Place-holders for information that tell the shell and other programs how to behave under various circumstances. To customize the environment various built-in shell variables are available. Nihar R Paital
  • 7. Customizing User Environment Customizing User Environment >To change the values of variables permanently , define it in .profile file. The .profile File  This is a file of shell commands, also called a shell script, that the Korn shell reads and runs whenever you log in to your system.  Various environment variables can be defined in this file  Alias can be defined in .profile file Nihar R Paital
  • 8. Customizing User Environment Aliases  Alias is a synonym for a command or command string  Syntax: alias new=original Ex:- alias search=grep alias cdnew=‘cd /xyz/x1/x2’ >Quotes are necessary if the string being aliased consists of more than one word >it is possible to alias an alias, aliases are recursive Ex:- alias c=cdnew  Type alias without any arguments, to get a list of all the aliases you have defined as well as several that are built-in.  The command unalias name removes any alias definition for its argument Nihar R Paital
  • 9. Customizing User Environment set command.  set command – Used for display all the environment variables. – Shows the current values of system variables. – Also allows conversion of arguments into positional parameters. – Syntax : set Nihar R Paital
  • 10. Customizing User Environment Set Options  Options let you change the shell's behaviour  A shell option is a setting that is either "on" or "off."  The basic commands that relate to options are set -o optionnames and set +o optionnames where optionnames is a list of option names separated by blanks The - turns the named option on, while the + turns it off Option Description emacs Enter emacs editing mode ignoreeof Don't allow use of [CTRL-D] to log off; require the exit command noclobber Don't allow output redirection (>) to clobber an existing file noglob Don't expand filename wildcards like * and ? (wildcard expansion is sometimes called globbing) nounset Indicate an error when trying to use a variable that is undefined vi Enter vi editing mode xtrace traces shell scripting noexec finds syntax error without executing script  To check the status of an option, type set -o Nihar R Paital
  • 11. Customizing User Environment Shell Variables  Shell variables can specify everything from your prompt string to how often the shell checks for new mail  built-in variables have names in all capital letters  The syntax for defining variables is $ varname=value  if the value is more than one word, it must be surrounded by quotes  To delete a variable type the command $ unset varname Ex: $ a=20 $ echo $a Output: 20 $ unset a $ echo $a Output: Empty Line Nihar R Paital
  • 12. Customizing User Environment Print Command  To check value of a variable print built-in command can be used  Print command is strongly recommended over echo because its options are the same on all UNIX systems, whereas echo's options differ between BSD-derived and System V-derived UNIX versions. Ex:- print “$x” Nihar R Paital
  • 13. Customizing User Environment System Variables or Built-in Variables  PATH – Search path referred by Unix for any command. – echo $PATH  HOME – Indicates the home directory for the user. – echo $HOME In the bash shell, command history is controlled by which group of the following environment variables. HISTCMD, HISTFILE, HISTSIZE, HISTFILESIZE  HISTFILE - Name of history file, on which the editing modes operate.  HISTSIZE – Number of lines kept in history file Nihar R Paital
  • 14. Customizing User Environment System Variables (Contd).  FCEDIT – Pathname of editor to use with the fc command.  PS1 – Used for displaying & changing the primary prompt. – echo $PS1  PS2 – Used for changing the secondary prompt.  MAIL – Name of file to check for incoming mail (i.e., your mail file)  MAILCHECK – How often, in seconds, to check for new mail (default 600 seconds, or 10 minutes) Nihar R Paital
  • 15. Customizing User Environment System Variables (Contd).  SHELL – Pathname of the shell you are running  PWD – Current directory  HOME – Users home directory Nihar R Paital
  • 16. Customizing User Environment Environment Variables  Environment Variables are known to all kinds of subprocesses  Any variable can become an environment variable. First it must be defined as usual; then it must be exported with the command $ export varnames  To find out environment variables and their values ,type $ export Nihar R Paital
  • 17. Customizing User Environment The Environment File  Although environment variables will always be known to subprocesses, the shell must define which other variables, options, aliases, etc., are to communicated to subprocesses. The way to do this is to put all such definitions in a special file called the environment file instead of your .profile. 1. Decide which definitions in your .profile you want to propagate to subprocesses. Remove them from .profile and put them in a file you will designate as your environment file. 2. Put a line in your .profile that tells the shell where your environment file is: ENV=envfilename 3 . For the changes to take effect, type either . .profile or login. In either case, your environment file will be run when the shell encounters the ENV= statement. Nihar R Paital