The K Shell Program Guide(1)

1)
WildcardMatches
?Any single character
*Any string of characters
[set]Any character in set
[!set]Any character not in set
2)
ExpressionMatches
[abc]a, b, or c
[.,;]Period, comma, or semicolon
[-_]Dash and underscore
[a-c]a, b, or c
[a-z]All lowercase letters
[!0-9]All non-digits
[0-9!]All digits and exclamation point
[a-zA-Z]All lower- and uppercase letters
[a-zA-Z0-9_-]All letters, all digits, underscore, and dash
3)
UtilityPurpose
catCopy input to output
grepSearch for strings in the input
sortSort lines in the input
cutExtract columns from input
sedPerform editing operations on input
trTranslate characters in the input to other characters
4)
fc -l
fc -e - number
5)
user's environment file is .profile.
6)Built-in Commands and Keywords

Here is a summary of all built-in commands and keywords.

CommandChapterSummary
:7Do nothing (just do expansions of arguments).
.4Read file and execute its contents in current shell.
alias3Set up shorthand for command or command line.
bg8Put job in background.
break5

Exit from surrounding for, select, while, or until loop.

case5Multi-way conditional construct.
cd1Change working directory.
continue

Skip to next iteration of for, select, while, or until loop.

echo4Expand and print arguments (obsolete).
exec9Replace shell with given program.
exit5Exit from shell.
export3Create environment variables.
eval7Process arguments as a command line.
fc2Fix command (edit history file).
fg8Put background job in foreground.
for5Looping construct.
function4Define function.
getopts6Process command-line options.
if5Conditional construct.
jobs1List background jobs.
kill8Send signal to process.
let6Arithmetic variable assignment.
newgrpStart new shell with new group ID.
print1Expand and print arguments on standard output.
pwd1Print working directory.
read7Read a line from standard input.
readonly6Make variables read-only (unassignable).
return5Return from surrounding function or script.
select5Menu generation construct.
set3Set options.
shift6Shift command-line arguments.
timeRun command and print execution times.
trap8Set up signal-catching routine.
typeset6Set special characteristics of variables.
ulimit10Set/show process resource limits.
umask10Set/show file permission mask.
unalias3Remove alias definitions.
unset3Remove definitions of variables or functions.
until5Looping construct.
wait8Wait for background job(s) to finish.
whence3Identify source of command.
while5Looping construct.
7)
Built-in Shell Variables

VariableChapterMeaning
#4Number of arguments given to current process.
-Options given to shell on invocation.
?5Exit status of previous command.
$8Process ID of shell process.
_Last argument to previous command.
!8Process ID of last background command.
CDPATH3List of directories for cd command to search.
COLUMNS3

Width of display in columns (for editing modes and select).

EDITOR2

Used to set editing mode; also used by mail and other programs.

ERRNOAError number of last system call that failed.
ENV3

Name of file to run as environment file when shell is invoked.

FCEDIT2Default editor for fc command.
FPATH4Search path for autoloaded functions.
IFS7

Internal field separator: list of characters that act as word separators. Normally set to SPACE, TAB, and NEWLINE.

HISTFILE2Name of command history file.
HISTSIZE2Number of lines kept in history file.
HOME3Home (login) directory.
LINENO9Number of line in script or function that just ran.
LINES3Height of display in lines (for select command).
MAIL3Name of file to check for new mail.
MAILCHECK3How often (in seconds) to check for new mail.
MAILPATH3

List of file names to check for new mail, if MAIL is not set.

OLDPWD3Previous working directory.
OPTARG6Argument to option being processed by getopts.
OPTIND6Number of first argument after options.
PATH3Search path for commands.
PS13Primary command prompt string.
PS23Prompt string for line continuations.
PS35Prompt string for select command.
PS49Prompt string for xtrace option.
PPID8Process ID of parent process.
PWD3Current working directory.
RANDOM9

Random number between 0 and 32767 (2215-1).

REPLY5,7

User's response to select command; result of read command if no variable names given.

SECONDS3Number of seconds since shell was invoked.
SHELL3Full pathname of shell.
TMOUT10

If set to a positive integer, number of seconds between commands after which shell automatically terminates.

VISUAL2Used to set editing mode.

8)Test Operators

These are the operators that are used with the [[...]] construct. They can be logically combined with && ("and") and || ("or") and grouped with parenthesis.

OperatorTrue If...
-a filefile exists.
-b filefile is a block device file.
-c filefile is a character device file.
-d filefile is a directory.
-f filefile is a regular file.
-g filefile has its setgid bit set.
-k filefile has its sticky bit set.
-n stringstring is non-null.
-o optionoption is set.
-p filefile is a pipe or named pipe (FIFO file).
-r filefile is readable.
-s filefile is not empty.
-t NFile descriptor N points to a terminal.
-u filefile has its setuid bit set.
-w filefile is writeable.
-x file

file is executable, or file is a directory that can be searched.

-z stringstring is null.
-G filefile's group ID is the same as that of the shell.
-L filefile is a symbolic link.
-O filefile is owned by the shell's user ID.
-S filefile is a socket.
fileA -nt fileBfileA is newer than fileB.
fileA -ot fileBfileA is older than fileB.
fileA -ef fileB

fileA and fileB point to the same file.

string = pattern

string matches pattern (which can contain wildcards).

string != patternstring does not match pattern.
stringA < stringB

stringA comes before stringB in dictionary order.

stringA > stringB

stringA comes after stringB in dictionary order.

exprA -eq exprB

Arithmetic expressions exprA and exprB are equal.

exprA -ne exprB

Arithmetic expressions exprA and exprB are not equal.

exprA -lt exprBexprA is less than exprB.
exprA -gt exprBexprA is greater than exprB.
exprA -le exprBexprA is less than or equal to exprB.
exprA -ge exprBexprA is greater than or equal to exprB.

9)Typeset Options

These are arguments to the typeset command.

OptionMeaning
With no option, create local variable within function.
-LLeft justify and remove leading blanks.
-RRight justify and remove trailing blanks.
-fWith no arguments, prints all function definitions.
-f fnamePrints the definition of function fname.
+fPrints all function names.
-ftTurns on trace mode for named function(s).
+ftTurns off trace mode for named function(s).
-fuDefines given name(s) as autoloaded function(s).
-iDeclare variable as an integer.
-lConvert all letters to lowercase.
-rMake variable read-only.
-uConvert all letters to uppercase.
-x

Export variable, i.e., put in environment so that it is passed to subshells

10)
Substitution Operators
OperatorSubstitution
${varname:-word}

If varname exists and isn't null, return its value; otherwise return word.

Purpose:

Returning a default value if the variable is undefined.

Example:

${count:-0} evaluates to 0 if count is undefined.

${varname:=word}

If varname exists and isn't null, return its value; otherwise set it to word and then return its value.[7]

Purpose:

Setting a variable to a default value if it is undefined.

Example:

${count:=0} sets count to 0 if it is undefined.

${varname:?message}

If varname exists and isn't null, return its value; otherwise print varname: followed by message, and abort the current command or script. Omitting message produces the default message parameter null or not set.

Purpose:

Catching errors that result from variables being undefined.

Example:

{count:?" undefined!" } prints "count: undefined!" and exits if count is undefined.

${varname:+word}

If varname exists and isn't null, return word; otherwise return null.

Purpose:

Testing for the existence of a variable.

Example:

${count:+1} returns 1 (which could mean "true") if count is defined.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值