shell advanced features. module 8 shell advanced features ♦ introduction in linux systems, the...
TRANSCRIPT
Shell Advanced Features
Shell Advanced Features
Module 8 Shell Advanced Features
♦ IntroductionIn Linux systems, the shells are often referred to as command line interfaces. The shell capabilities provide a configurable environment allowing the users to modify commands and prompts.
♦ Topics► Shell Substitution Capabilities► Setting Shell Variables► Quoting Characters► File Name Generationss
Shell Advanced Features
Shell Substitution Capabilities
♦ Substitution capabilities are used to speed up command line typing and execution.
♦ The shell substitutions are of three types:
► Variable Substitution► Command substitution► Tilde Substitution
Contd…
Shell Advanced Features
Shell Substitution Capabilities
♦ Variable Substitution► Variable substitution is assigning the absolute path of a file or directory to
any variable. This allows the user to access the directory or file from anywhere in the file hierarchy.
Syntax: <new variable>=$<system variable> <arguments>
Example: myfile=$HOME/file1
Contd…
Shell Advanced Features
Shell Substitution Capabilities
♦ Command substitution► Command substitution is the mechanism used to replace a command with
its output, within the same command line.
Syntax: <new variable>=$(command)
Example: mydir=$ (pwd)
Contd…
Shell Advanced Features
♦ Tilde Substitution
A tilde is replaced for the quick reference of home directory.
Syntax: <command> ~
Example: ls ~
Shell Substitution Capabilities
Shell Advanced Features
♦ The new variable can be created and assigned to an existing environmental variable such as path.
♦ The new value replaces the old value in the environment and the same can be displayed by using the display value commands.
Syntax
<variable name>=<arguments>Example
myfile_name=/root/file1
Contd…
Setting Shell Variables
Shell Advanced Features
Setting Shell Variables
♦ Displaying variable values
► The variables can be displayed by using $ <variable>. ► It can be local variable (assigned by the user) or environmental variable
(default variable). ► All setting variables can be displayed by using the command set.
Shell Advanced Features
Quoting Characters
♦ There are some characters in the Unix system and each has the meaning for the shell and is called as special characters. The special characters are:► - ► $► #► *► < >
♦ Quoting removes the special meaning of the above characters. The quoting characters are:► \ Backslash ► ‘ ’ Single quotes► “ ” Double quotes Contd…
Shell Advanced Features
Contd…
♦ Backslash ( \ )Backslash removes the special meaning of the character immediately following the backslash.
Quoting Characters
Shell Advanced Features
♦ Single quotes ( ‘ ’)
The single quote is used to preserve the literal value of special character enclosed within the quotes.
Contd…
Quoting Characters
Shell Advanced Features
Quoting Characters
♦ Double quotes ( “ ” )
Double quotes removes the special meaning of all the characters except \ , $ (variable name), $ (command).
Shell Advanced Features
♦ The file name generation has the timesaving feature for typing the filenames. This feature is called file name generation or filename expansion.
► Advantages of file name generation• File name generating characters are interpreted by the shell.• The command operates on the generated file names.• The shell will generate file names that satisfy the requested pattern.• File name generation is done before the command is executed.
♦ The special characters that are interpreted by the shell for file name generation are:
• ? Matches any single character except a leading dot• * Matches zero or more characters except a leading dot
Contd…
File Name Generation
Shell Advanced Features
File Name Generation
♦ Usage of the special character ‘?’
Contd…
Shell Advanced Features
File Name Generation
♦ Usage of the special character ‘*’
Shell Advanced Features
Lab Exercise
♦ Give one example on usage of single quotes command with the variable substitution
♦ Display the files which has 9 characters and with the extension .jpg