• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
UNIX - Class4 - Advance Shell Scripting-P1
 

UNIX - Class4 - Advance Shell Scripting-P1

on

  • 1,097 views

Advance Shell Scripting

Advance Shell Scripting

Statistics

Views

Total Views
1,097
Views on SlideShare
1,097
Embed Views
0

Actions

Likes
0
Downloads
40
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    UNIX - Class4 - Advance Shell Scripting-P1 UNIX - Class4 - Advance Shell Scripting-P1 Presentation Transcript

    • UNIX Advance Shell Scripting Presentation By Nihar R Paital
    • IntroductionAdvance features of shell scripting/commandsuch 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/nullThis is special Linux file which is used to send anyunwanted output from program/command.Syntax:command > /dev/nullExample:$ ls > /dev/nullRun the following two commands$ ls > /dev/null$ rm > /dev/null1) Why the output of last command is not redirected to /dev/null device? Nihar R Paital
    • Local and Global Shell variableLocal Shell variable$a=20$echo $aOutput : 20$/bin/sh # Entering into New Shell$ echo $aOutput :Empty Line Printed due to a is not defined in new shell$ a=50$ echo $aOutput : 50$ exit #Returned to Old Shell by exiting Old Shell$echo $aOutput : 20$ Nihar R Paital
    • Local and Global Shell variableGlobal Shell VariableTo 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 EnvironmentThe 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 EnvironmentCustomizing 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 EnvironmentAliases Alias is a synonym for a command or command string Syntax: alias new=originalEx:- 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 recursiveEx:- 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 Environmentset 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 EnvironmentSet Options Options let you change the shells 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 optionnameswhere optionnames is a list of option names separated by blanksThe - turns the named option on, while the + turns it offOption Descriptionemacs Enter emacs editing modeignoreeof Dont allow use of [CTRL-D] to log off; require the exit commandnoclobber Dont allow output redirection (>) to clobber an existing filenoglob Dont expand filename wildcards like * and ? (wildcard expansion is sometimes called globbing)nounset Indicate an error when trying to use a variable that is undefinedvi Enter vi editing modextrace traces shell scriptingnoexec finds syntax error without executing script To check the status of an option, type set -o Nihar R Paital
    • Customizing User EnvironmentShell 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 varnameEx: $ a=20 $ echo $a Output: 20 $ unset a $ echo $a Output: Empty Line Nihar R Paital
    • Customizing User EnvironmentPrint 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 echos options differ between BSD-derived and System V-derived UNIX versions.Ex:- print “$x” Nihar R Paital
    • Customizing User EnvironmentSystem 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 EnvironmentSystem 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 EnvironmentSystem Variables (Contd). SHELL – Pathname of the shell you are running PWD – Current directory HOME – Users home directory Nihar R Paital
    • Customizing User EnvironmentEnvironment 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 EnvironmentThe 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=envfilename3 . 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