Tilde Character with a Username (~user1) Represents home directory of specified user. The tilde is not available in the Bourne shell. Dash Character ... – PowerPoint PPT presentation
Korn shell metacharacters are specific characters, usually symbols, that have special meaning to the shell
There are three types
Path Name
File Name Substitution
Redirection
Note Never use any of the shell metacharacters when naming files and directories
4 Pathname Metacharacters
Tilde Character ()
Represents home directory of current user
Tilde Character with a Username (user1)
Represents home directory of specified user
The tilde is not available in the Bourne shell
Dash Character (-)
Represents the previous working directory
5 File Name Substitution Metacharacters
File name substitution metacharacters are also known as Wildcards
Metacharacters allow the user to specify parts of filenames and let the shell find the rest
The metacharacters we will cover
Asterisk
Question Mark ?
Square Brackets
Exclamation Point !
6 The Asterisk Character
Used to represent zero or more characters (except the leading period . of a hidden file)
Used with various commands to represent all files
cp dir2 Copies all files from pwd to dir2
ls f Lists all files that begin with f
ls f1 Lists all files that begin with f and end with 1
DOS used . to represent all files
7 The Question Mark ? Character
Used to represent any single character (except the leading period . of a hidden file)
ls dir?
ls empty?
ls ?a
ls j???a
ls .
ls dir2/b
ls /etc/d
8 The Square Bracket Characters
The square bracket characters represent a set or range of characters for a single character position
ls ejt
ls a-f
ls A-Z0-9
ls e0-9
ls j???ac14
ls ?ua0-9
9 The Exclamation Point ! Character
The exclamation point (also called bang) is used to exclude the pattern. It means not
ls e!0-9
ls !A-Z
ls !e
ls junk!0-9
ls j???!ac14
ls !A-Z0-9
ls ?!m1
10 Introducing Korn Shell Variables
A variable refers to a temporary storage area in memory. Variables contain
Information needed for customizing the shell
Information needed by other processes to function properly
Korn shell programming uses two types of variables
Environment variables
Variables that are passed to child processes
Local variables
Variables that are not passed to child processes
11 Korn Shell Commands for Variables 12 Displaying Variables
To list all shell variables with their current values, use set
set
Use echo or print to display the value that is stored inside a variable
print PS1
echo PWD
echo PWD
The sign tells the shell that what follows is a variable
13 Setting and Unsetting Variables
Syntax for setting variables
varvalue or VARvalue
rockdir/export/home/user1/Music/Types/Rock
set
cd rockdir
Syntax for unsetting variables
unset var or unset VAR
unset rockdir
set
14 Exporting Variables to Sub-Shells
All shells have built-in commands, such at the cd and ls commands
Any process in UNIX that is not a built-in command (like a shell script) is forked into a child process (sub-shell) and runs independently of the parent shell
You may need to execute a command within another command
echo Today's date is date.
echo Today's date is date.
Uses backtics to enclose command
Syntax command command
echo Today's date is (date).
Uses ( ) to enclose command
Syntax command (command)
20 Using the History Command
Syntax for history command history option
By default, the history command displays the last 16 commands
history
Your history file (.sh_history) contains up to 999 commands
cat .sh_history
Specify how many commands to display, not counting the history command itself
history -10
Actually displays last 11 commands
21 Displaying Previous Commands
Finding a previous command
history ls
history cat ls
Using SSH
ltctrlgt p
Using the r command
r cat
r ls
r c
r history
22 Understanding Command Redirection
Typically, the shell receives or reads command input from the keyboard and displays or writes the command output to the screen
There are two redirection metacharacters
Greater than gt
Less than lt
Both of these can be used with the pipe
23 The File Descriptors File descriptors determine where the input to the command originates and where the output and error messages are sent 24 Redirection Examples
cat
Takes you to a blank line
Hi!
Input received from stdin and sent to stdout
cat lt dante
Tells cat command to receive input from dante file instead of keyboard
ls l gt lsfile
Redirects stdout from screen to a file
echo This is a long list gtgt lsfile cat lsfile
Appends to lsfile instead of overwriting
25 Redirecting Error Messages
You can redirect error message using the stderr file descriptor number (2) and the greater than symbol (gt)
ls lR /etc
There are a few error messages due to file permissions
ls lR /etc 2gt etc-errors
The command still runs, but no error messages are displayed
cat etc-errors
The file containing our redirected error messages
26 The Pipe Character
The pipe command redirects the stdout of one command to the stdin of another
ls lR more
cat dante wc w
27 User Initialization Files 28 Korn Shell Initialization Files
Initialization files are used to customize your working environment
The /.profile file is run by the login process
The /.kshrc file contains shell variables and aliases. To use it, the ENV variable must be defined in the .profile file
Changes to .profile and .kshrc take effect upon next login.
Run . /.profile or . /.kshrc to update immediately
PowerShow.com is a leading presentation sharing website. It has millions of presentations already uploaded and available with 1,000s more being uploaded by its users every day. Whatever your area of interest, here you’ll be able to find and view presentations you’ll love and possibly download. And, best of all, it is completely free and easy to use.
You might even have a presentation you’d like to share with others. If so, just upload it to PowerShow.com. We’ll convert it to an HTML5 slideshow that includes all the media types you’ve already added: audio, video, music, pictures, animations and transition effects. Then you can share it with your target audience as well as PowerShow.com’s millions of monthly visitors. And, again, it’s all free.
About the Developers
PowerShow.com is brought to you by CrystalGraphics, the award-winning developer and market-leading publisher of rich-media enhancement products for presentations. Our product offerings include millions of PowerPoint templates, diagrams, animated 3D characters and more.