the basics of ksh (Korn shell)
alias
used as convenient names for commands. for example, if ll command not found, you can typealias ll='ls -l'
in environment file of current user.options
one way of changing the behavior of shell, the basic command of related to it areset -o optionnames
andset +o optionnames
. some options like
(1)allexport
(2)ignoreeof #if on, do not allow Ctrl+D to exit
(3)noglob
note: most have one-letter counterpart as its abbr.scripts
A script/file is a shell program that contains some shell commands. In files of the kind, the#!/usr/bin/ksk
line is generally used as Shebang one. Three methods of running scripts:
(1)[user@host ~]$./script_name [&]
orscript_name [&]
#run included commands in the subshell/subprocess but no need to wait until subshell is done
(2)[user@host ~]$[.|source] script_name
#run in current/same shell
(3)[user@host ~]$[ksh|bash|sh] script_name
#same as (1)functions
a sort of a script-within-a-script by which to define some shell code by name and store it in shell’s memory , to invoke and run it later as if it were a shell script. two forms of function definition:
function func_name {
...
shell code/chunk
...
} #as one
func_name () {
...
shell code/chunk
...
} #as the other
autoload functions
putautoload func_name
in profile or environment file of specific login user
. Doing like this make it that shell will not read in definitions of function until it is actually called. for example, in your profile file:
FPATH=~/kshfuncs
autoload testf
When you invoke the command testf , the shell will look in the directory ~/kshfuncs for a file called testf that has the definition of function testf . If it doesn’t find the file, or if the file exists but doesn’t contain the proper function definition, the shell will complain with a “not found” message, just as if the command didn’t exist at allstring operator
curly-bracket(花括號) syntax allows for string operators which manipulates values of variables in various useful ways. generally you can do:
(1)test for variable existence
(2)set default value of variables
(3)catch errors that result from variables not being set
use syntax:${var_name:[-|=|+|?][word|msg]}
regular expression and pattern-matching operator
syntax format looks like:
[*|+|?|!](exp) #
@(exp1|exp2|...) #or
${var_name#pattern} #
${var_name##pattern} #
${var_name%pattern} #
${var_name%%pattern} #
extra points
typeset -f[u]
print functions defined in current login session while -u opt outputs autoload oneswhence
alias totype -a
, it prints extra source(準確來源) or pathname of a command/function whose name as argument. an example looks like
[user@host ~]$ whence cd
[user@host ~]$ cd is a shell buitin
[user@host ~]$ whence man
[user@host ~]$ man is /usr/bin/man