Basic knowledge of kornshell-general Linux technology-Linux programming and kernel information. The following is a detailed description. Korn Shell command execution sequence
1. keywords, such as if, for, and function
2. Alias (Aliases)
3. Internal commands, such as cd, whence, and functions
4. Function Functions
5. Script Scripts and executable programs in PATH
※Use the following command to find the root cause of the command:
Whence-v command
Or:
Type command
Alias (Alias)
Alias aliasname = command
Cancel an alias:
Unalias aliasname
List all current aliases:
Alias
TIP]
Alias used to explicitly display all directories in the current directory: alias ldir = 'LS-l | grep ^ d'
Question: alias | grep ^ ls: ls =/usr/bin/ls. Why does the system define this alias?
Functions (function)
Location defined:
Function can be defined in the command line,. kshrc (ENV file, see the next article), or in shell script
Method defined:
Function funcname {
Shell commands
}
Or:
Funcname (){
Shell commands
}
List all current functions
Functions
Cancels a function.
Unset-f funcname
Output a function:
Typeset-fx funcname
Cancel the output of a function:
Typeset + fx funcname
※Function is a pre-defined alias of "typeset-f ".
Korn Shell options
Korn Shell has some options. If you set them in. kshrc (ENV file, see the next article), they are global and can be passed to subshell.
List all the Korn Shell options:
Set-o
Set an option
Set-o OptionName
Cancel an option
Set + o OptionName
Significance of the Korn Shell Option
Allexport auto export then defines all the variables (the file name does not include.). (equal to set-)
Errexit if the return value of a command is not 0, it will execute the error trap (ERR trap ). Except for profile files. (Equal to set-e)
The bgnice background process runs at a lower priority. This is the default value.
Emacs uses the emacs-style in-row editor.
Gmacs uses gmacs-style in-row Editor
Ignoreeof does not exit shell in case of a file Terminator. To exit shell, you must use the exit command or press Ctrl-D 11 times.
Keyword is used to maintain compatibility with the Bourne shell. (Set-k)
After the file name is replaced, markdirs adds a slash (/) to the directory name (/).
Monitor Runs background jobs in a separate process and prints a line upon completion. (set-m)
Noclobber cannot overwrite existing files with> redirection. You can only use> | to override an existing file. The noexec READ command only checks its syntax but does not execute it. (Set-n)
Noglob prohibits file name replacement. (Set-f)
Nolog does not store function definitions in history files.
Nounset displays an error message when attempting to extend a variable that is not defined. (Set-u)
Privileged prohibits the execution of the HOME/. profile file and uses the/etc/suid _ profile instead of the ENV file. (Set-p)
Verbose displays the input read by shell. (set-v)
Trackall Designates each command as a tracked alias when first encountered. (set-h)
Vi uses the vi-style in-row Editor
Viraw Processes each character as it is typed in vi mode.
Xtrace displays the command before running the command. (set-x)
※Example: make vi an inline editor.
Set-o vi
Debuging (debugging)
To debug a shell script:
# Set-o xtrace
Then run shell.
Or directly execute
# Ksh-x shellprog args
Or
# Sh-v shellprog args
Debug a function
# Typeset-ft funcname
Prompts (prompt)
PS1 main shell prompt (the default is $ for common users, and the default is # for root users #)
PS2 continue prompt (default>)
What is a continue prompt?
Enter
For I in 11 12 13 14 15 16
Do
Lspv hdisk $ I
Done
Starting from the second line, the leftmost side of the screen is to continue the prompt.
The selection prompt of the PS3 in the selection loop (default #? )
PS4 debugging prompt (+ by default)
Tip: The Host Name and current directory are displayed on the command line.
Export PS1 = "['hostname'-" '$ PWD]'
Note: The command result can be obtained only when "" includes '', and'' includes variables to change the value of the variable at any time.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.