The K Shell Program Guide(1)

原创 2004年10月15日 14:28:00
Wildcard Matches
? Any single character
* Any string of characters
[set] Any character in set
[!set] Any character not in set
Expression Matches
[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
Utility Purpose
cat Copy input to output
grep Search for strings in the input
sort Sort lines in the input
cut Extract columns from input
sed Perform editing operations on input
tr Translate characters in the input to other characters
fc -l
fc -e - number
user's environment file is .profile.
6)Built-in Commands and Keywords

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

Command Chapter Summary
: 7 Do nothing (just do expansions of arguments).
. 4 Read file and execute its contents in current shell.
alias 3 Set up shorthand for command or command line.
bg 8 Put job in background.
break 5

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

case 5 Multi-way conditional construct.
cd 1 Change working directory.

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

echo 4 Expand and print arguments (obsolete).
exec 9 Replace shell with given program.
exit 5 Exit from shell.
export 3 Create environment variables.
eval 7 Process arguments as a command line.
fc 2 Fix command (edit history file).
fg 8 Put background job in foreground.
for 5 Looping construct.
function 4 Define function.
getopts 6 Process command-line options.
if 5 Conditional construct.
jobs 1 List background jobs.
kill 8 Send signal to process.
let 6 Arithmetic variable assignment.
newgrp Start new shell with new group ID.
print 1 Expand and print arguments on standard output.
pwd 1 Print working directory.
read 7 Read a line from standard input.
readonly 6 Make variables read-only (unassignable).
return 5 Return from surrounding function or script.
select 5 Menu generation construct.
set 3 Set options.
shift 6 Shift command-line arguments.
time Run command and print execution times.
trap 8 Set up signal-catching routine.
typeset 6 Set special characteristics of variables.
ulimit 10 Set/show process resource limits.
umask 10 Set/show file permission mask.
unalias 3 Remove alias definitions.
unset 3 Remove definitions of variables or functions.
until 5 Looping construct.
wait 8 Wait for background job(s) to finish.
whence 3 Identify source of command.
while 5 Looping construct.
Built-in Shell Variables

Variable Chapter Meaning
# 4 Number of arguments given to current process.
- Options given to shell on invocation.
? 5 Exit status of previous command.
$ 8 Process ID of shell process.
_ Last argument to previous command.
! 8 Process ID of last background command.
CDPATH 3 List of directories for cd command to search.

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


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

ERRNO A Error number of last system call that failed.

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

FCEDIT 2 Default editor for fc command.
FPATH 4 Search path for autoloaded functions.

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

HISTFILE 2 Name of command history file.
HISTSIZE 2 Number of lines kept in history file.
HOME 3 Home (login) directory.
LINENO 9 Number of line in script or function that just ran.
LINES 3 Height of display in lines (for select command).
MAIL 3 Name of file to check for new mail.
MAILCHECK 3 How often (in seconds) to check for new mail.

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

OLDPWD 3 Previous working directory.
OPTARG 6 Argument to option being processed by getopts.
OPTIND 6 Number of first argument after options.
PATH 3 Search path for commands.
PS1 3 Primary command prompt string.
PS2 3 Prompt string for line continuations.
PS3 5 Prompt string for select command.
PS4 9 Prompt string for xtrace option.
PPID 8 Process ID of parent process.
PWD 3 Current working directory.

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


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

SECONDS 3 Number of seconds since shell was invoked.
SHELL 3 Full pathname of shell.

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

VISUAL 2 Used 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.

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

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

-z string string is null.
-G file file's group ID is the same as that of the shell.
-L file file is a symbolic link.
-O file file is owned by the shell's user ID.
-S file file is a socket.
fileA -nt fileB fileA is newer than fileB.
fileA -ot fileB fileA 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 != pattern string 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 exprB exprA is less than exprB.
exprA -gt exprB exprA is greater than exprB.
exprA -le exprB exprA is less than or equal to exprB.
exprA -ge exprB exprA is greater than or equal to exprB.

9)Typeset Options

These are arguments to the typeset command.

Option Meaning
With no option, create local variable within function.
-L Left justify and remove leading blanks.
-R Right justify and remove trailing blanks.
-f With no arguments, prints all function definitions.
-f fname Prints the definition of function fname.
+f Prints all function names.
-ft Turns on trace mode for named function(s).
+ft Turns off trace mode for named function(s).
-fu Defines given name(s) as autoloaded function(s).
-i Declare variable as an integer.
-l Convert all letters to lowercase.
-r Make variable read-only.
-u Convert all letters to uppercase.

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

Substitution Operators
Operator Substitution

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


Returning a default value if the variable is undefined.


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


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


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


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


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.


Catching errors that result from variables being undefined.


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


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


Testing for the existence of a variable.


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

Google Style Guides-Shell Style Guide

  • zhangyifei216
  • zhangyifei216
  • 2016年01月14日 14:46
  • 1950

Quartz 2D Programming Guide

Quartz 2D Programming Guide 官方文档地址:
  • likendsl
  • likendsl
  • 2012年06月16日 17:17
  • 1520

windows shell program(1)

 Shell扩展就是对explorer的扩展。主要分为四个部分:ContexMenu扩展、Property Sheet扩展、Drag and drop扩展、Drop扩展及QueryInfo扩展。Con...
  • yanshen6
  • yanshen6
  • 2007年04月28日 15:20
  • 546

shell program 1

(1)use gedit write the shell program"shell": #! /bin/bash echo please enter something: read qq echo ...
  • gravitation2017
  • gravitation2017
  • 2017年05月18日 23:41
  • 26

Vulkan Programming Guide 第一章(1)

内容 图片说明 表格说明 程序片段清单 关于本书 关于示例代码 错误纠正 致谢 关于作者第一章 Vulkan概述 1.1 介绍 1.2 实例,设备和队列 ...
  • wanghexu09008126
  • wanghexu09008126
  • 2017年03月07日 01:16
  • 951

Vulkan Programming Guide 第一章(3)

  • wanghexu09008126
  • wanghexu09008126
  • 2017年03月26日 23:30
  • 471

Vulkan Programming Guide翻译计划

2017-02-18      这本书出版有一段时间了,国内还没有引进。相关也的材料比较难找,所以,我打算把这本书翻译出来。目前只有两个人参与这个翻译活动。如果有人对这个翻译活动感兴趣,请联系我,...
  • cloudqiu
  • cloudqiu
  • 2017年02月18日 11:39
  • 1599

Shell Program

1) !$:重复前一个命令最后的参数。例如:您用命令 mkdir peter/pan/documents/tinkerbell 新建了一个目录,现在您向用命令‘cd’进入该目录,您可以用 cd !$,...
  • iiisan
  • iiisan
  • 2005年04月05日 10:20
  • 912


 首先说明一个东西机器:0,1序列。 位移操作建立在补码的基础之上。 1.无符号位移 无符号位移:左移,高位截去,低位补零。右移,高位补零,低位截去。 举个无符号位移的例子: 假设in...
  • yueloveme
  • yueloveme
  • 2015年08月03日 15:16
  • 2170

shell program
  • GoodAtJava
  • GoodAtJava
  • 2008年11月26日 14:18
  • 163
您举报文章:The K Shell Program Guide(1)