+ All Categories
Home > Documents > Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the...

Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the...

Date post: 29-Jan-2016
Category:
Upload: christian-robertson
View: 217 times
Download: 0 times
Share this document with a friend
Popular Tags:
16
Shell Advanced Features
Transcript
Page 1: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

Shell Advanced Features

Page 2: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

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

Page 3: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

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…

Page 4: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

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…

Page 5: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

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…

Page 6: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

Shell Advanced Features

♦ Tilde Substitution

A tilde is replaced for the quick reference of home directory.

Syntax: <command> ~

Example: ls ~

Shell Substitution Capabilities

Page 7: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

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

Page 8: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

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.

Page 9: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

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…

Page 10: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

Shell Advanced Features

Contd…

♦ Backslash ( \ )Backslash removes the special meaning of the character immediately following the backslash.

Quoting Characters

Page 11: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

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

Page 12: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

Shell Advanced Features

Quoting Characters

♦ Double quotes ( “ ” )

Double quotes removes the special meaning of all the characters except \ , $ (variable name), $ (command).

Page 13: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

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

Page 14: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

Shell Advanced Features

File Name Generation

♦ Usage of the special character ‘?’

Contd…

Page 15: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

Shell Advanced Features

File Name Generation

♦ Usage of the special character ‘*’

Page 16: Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.

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


Recommended