1 |
199 |
simons |
.TH SH 1
|
2 |
|
|
.SH NAME
|
3 |
|
|
sh, ., break, case, cd, continue, eval, exec, exit, export, for, if, read, readonly, set, shift, trap, umask, wait, while \- shell
|
4 |
|
|
.SH SYNOPSIS
|
5 |
|
|
\fBsh\fR [\fB\-eiknqstvxu\fR] [\fB\-c \fIstr\fR] \fB[\fIfile\fR]\fR
|
6 |
|
|
.br
|
7 |
|
|
.de FL
|
8 |
|
|
.TP
|
9 |
|
|
\\fB\\$1\\fR
|
10 |
|
|
\\$2
|
11 |
|
|
..
|
12 |
|
|
.de EX
|
13 |
|
|
.TP 20
|
14 |
|
|
\\fB\\$1\\fR
|
15 |
|
|
# \\$2
|
16 |
|
|
..
|
17 |
|
|
.SH OPTIONS
|
18 |
|
|
.FL "\-c" "Execute the commands in \fIstr\fR"
|
19 |
|
|
.FL "\-e" "Quit on error"
|
20 |
|
|
.FL "\-i" "Interactive mode; ignore QUIT, TERMINATE, INTERRUPT"
|
21 |
|
|
.FL "\-k" "Look for name=value everywhere on command line"
|
22 |
|
|
.FL "\-n" "Do not execute commands"
|
23 |
|
|
.FL "\-q" "Change qflag from sig_ign to sig_del"
|
24 |
|
|
.FL "\-s" "Read commands from standard input"
|
25 |
|
|
.FL "\-t" "Exit after reading and executing one command"
|
26 |
|
|
.FL "\-v" "Echo input lines as they are read"
|
27 |
|
|
.FL "\-x" "Trace"
|
28 |
|
|
.FL "\-u" "Unset variables"
|
29 |
|
|
.SH EXAMPLES
|
30 |
|
|
.EX "sh script" "Run a shell script"
|
31 |
|
|
.SH DESCRIPTION
|
32 |
|
|
.PP
|
33 |
|
|
.I Sh
|
34 |
|
|
is the shell, which forms the user's main interface with the system.
|
35 |
|
|
On startup, the shell reads /etc/profile and $HOME/.profile, if they exist,
|
36 |
|
|
and executes any commands they contain. The Minix shell has most of the
|
37 |
|
|
features of the V7 (Bourne) shell, including redirection of input and output,
|
38 |
|
|
pipes, magic characters, background processes, and shell scripts. A brief
|
39 |
|
|
summary follows, but whole books have been written on shell programming alone.
|
40 |
|
|
.LP
|
41 |
|
|
Some of the more common notations are:
|
42 |
|
|
.PP
|
43 |
|
|
.in +2.45i
|
44 |
|
|
.ta 2i 2.2i
|
45 |
|
|
.ti -2.2i
|
46 |
|
|
date # Regular command
|
47 |
|
|
.ti -2.2i
|
48 |
|
|
sort
|
49 |
|
|
.ti -2.2i
|
50 |
|
|
sort file2 # Redirect \fIstdin\fR and \fIstdout\fR
|
51 |
|
|
.ti -2.2i
|
52 |
|
|
cc file.c 2>error # Redirect \fIstderr\fR
|
53 |
|
|
.ti -2.2i
|
54 |
|
|
a.out >f 2>&1 # Combine standard output and standard error
|
55 |
|
|
.ti -2.2i
|
56 |
|
|
sort >file2 # Append output to \fIfile2\fR
|
57 |
|
|
.ti -2.2i
|
58 |
|
|
sort file2 & # Background job
|
59 |
|
|
.ti -2.2i
|
60 |
|
|
(ls \-l; a.out) & # Run two background commands sequentially
|
61 |
|
|
.ti -2.2i
|
62 |
|
|
sort
|
63 |
|
|
.ti -2.2i
|
64 |
|
|
sort
|
65 |
|
|
.ti -2.2i
|
66 |
|
|
ls \-l *.c # List all files ending in \fI.c\fR
|
67 |
|
|
.ti -2.2i
|
68 |
|
|
ls \-l [\fIa-c\fR]* # List all files beginning with \fIa\fR, \fIb\fR, or \fIc\fR
|
69 |
|
|
.ti -2.2i
|
70 |
|
|
ls \-l ? # List all one-character file names
|
71 |
|
|
.ti -2.2i
|
72 |
|
|
ls \e? # List the file whose name is question mark
|
73 |
|
|
.ti -2.2i
|
74 |
|
|
ls \(fm???\(fm # List the file whose name is three question marks
|
75 |
|
|
.ti -2.2i
|
76 |
|
|
v=/usr/ast # Set shell variable \fIv\fR
|
77 |
|
|
.ti -2.2i
|
78 |
|
|
ls \-l $v # Use shell variable \fIv\fR
|
79 |
|
|
.ti -2.2i
|
80 |
|
|
PS1=\(fmHi! \(fm # Change the primary prompt to \fIHi!\fR
|
81 |
|
|
.ti -2.2i
|
82 |
|
|
PS2=\(fmMore: \(fm # Change the secondary prompt to \fIMore:\fR
|
83 |
|
|
.ti -2.2i
|
84 |
|
|
ls \-l $HOME # List the home directory
|
85 |
|
|
.ti -2.2i
|
86 |
|
|
echo $PATH # Echo the search path
|
87 |
|
|
.ti -2.2i
|
88 |
|
|
echo $? # Echo exit status of previous command in decimal
|
89 |
|
|
.ti -2.2i
|
90 |
|
|
echo $$ # Echo shell's pid in decimal
|
91 |
|
|
.ti -2.2i
|
92 |
|
|
echo $! # Echo PID of last background process
|
93 |
|
|
.ti -2.2i
|
94 |
|
|
echo $# # Echo number of parameters (shell script)
|
95 |
|
|
.ti -2.2i
|
96 |
|
|
echo $2 # Echo second parameter (shell script)
|
97 |
|
|
.ti -2.2i
|
98 |
|
|
echo "$2" # Echo second parameter without expanding spaces
|
99 |
|
|
.ti -2.2i
|
100 |
|
|
echo $* # Echo all parameters (shell script)
|
101 |
|
|
.ti -2.2i
|
102 |
|
|
echo $@ # Echo all parameters (shell script)
|
103 |
|
|
.ti -2.2i
|
104 |
|
|
echo "$@" # Echo all parameters without expanding spaces
|
105 |
|
|
.in -2.45i
|
106 |
|
|
.LP
|
107 |
|
|
The shell uses the following variables for specific purposes:
|
108 |
|
|
.PP
|
109 |
|
|
.in +2.25i
|
110 |
|
|
.ta 2i
|
111 |
|
|
.ti -2i
|
112 |
|
|
SHELL the path of the current shell
|
113 |
|
|
.ti -2i
|
114 |
|
|
HOME the default value for the cd(1) command
|
115 |
|
|
.ti -2i
|
116 |
|
|
PATH the directories to be searched to find commands
|
117 |
|
|
.ti -2i
|
118 |
|
|
IFS the internal field separators for command strings
|
119 |
|
|
.ti -2i
|
120 |
|
|
PS1 the primary shell prompt
|
121 |
|
|
.ti -2i
|
122 |
|
|
PS2 the secondary shell prompt
|
123 |
|
|
.in -2.25i
|
124 |
|
|
.LP
|
125 |
|
|
There are various forms of substitution on the shell command line:
|
126 |
|
|
.PP
|
127 |
|
|
.in +2.25i
|
128 |
|
|
.ta 2i
|
129 |
|
|
.ti -2i
|
130 |
|
|
`...` Command string between back-quotes is replaced by its output
|
131 |
|
|
.ti -2i
|
132 |
|
|
"..." Permits variable substitution between quotes
|
133 |
|
|
.ti -2i
|
134 |
|
|
\&'...' Inhibits variable substitution between quotes
|
135 |
|
|
.ti -2i
|
136 |
|
|
$VAR Replaced by contents of variable VAR
|
137 |
|
|
.ti -2i
|
138 |
|
|
${VAR} Delimits variable VAR from any following string
|
139 |
|
|
.in -2.25i
|
140 |
|
|
.LP
|
141 |
|
|
The expressions below depend on whether or not VAR has ever been set.
|
142 |
|
|
If VAR has been set, they give:
|
143 |
|
|
.PP
|
144 |
|
|
.in +2.25i
|
145 |
|
|
.ta 2i
|
146 |
|
|
.ti -2i
|
147 |
|
|
${VAR-str} Replace expression by VAR, else by str
|
148 |
|
|
.ti -2i
|
149 |
|
|
${VAR=str} Replace expression by VAR, else by str and set VAR to str
|
150 |
|
|
.ti -2i
|
151 |
|
|
${VAR?str} Replace expression by VAR, else print str and exit shell
|
152 |
|
|
.ti -2i
|
153 |
|
|
${VAR+str} Replace expression by str, else by null string
|
154 |
|
|
.in -2.25i
|
155 |
|
|
.LP
|
156 |
|
|
If a colon is placed after VAR, the expressions depend on whether or not
|
157 |
|
|
VAR is currently set and non-null.
|
158 |
|
|
.LP
|
159 |
|
|
The shell has a number of built-in commands:
|
160 |
|
|
.PP
|
161 |
|
|
.in +2.25i
|
162 |
|
|
.ta 2i
|
163 |
|
|
.ti -2i
|
164 |
|
|
: return true status
|
165 |
|
|
.ti -2i
|
166 |
|
|
\&. fn execute shell script fn on current path
|
167 |
|
|
.ti -2i
|
168 |
|
|
break [n] break from a for, until or while loop; exit n levels
|
169 |
|
|
.ti -2i
|
170 |
|
|
continue [n] continue a for, until or while loop; resume nth loop
|
171 |
|
|
.ti -2i
|
172 |
|
|
cd [dir] change current working directory; move to $HOME
|
173 |
|
|
.ti -2i
|
174 |
|
|
eval cmd rescan cmd, performing substitutions
|
175 |
|
|
.ti -2i
|
176 |
|
|
eval rescan the current command line
|
177 |
|
|
.ti -2i
|
178 |
|
|
exec cmd execute cmd without creating a new process
|
179 |
|
|
.ti -2i
|
180 |
|
|
exec <|> with no command name, modify shell I/O
|
181 |
|
|
.ti -2i
|
182 |
|
|
exit [n] exit a shell program, with exit value n
|
183 |
|
|
.ti -2i
|
184 |
|
|
export [var] export var to shell's children; list exported variables
|
185 |
|
|
.ti -2i
|
186 |
|
|
pwd print the name of the current working directory
|
187 |
|
|
.ti -2i
|
188 |
|
|
read var read a line from stdin and assign to var
|
189 |
|
|
.ti -2i
|
190 |
|
|
readonly [var] make var readonly; list readonly variables
|
191 |
|
|
.ti -2i
|
192 |
|
|
set -f set shell flag (+f unsets flag)
|
193 |
|
|
.ti -2i
|
194 |
|
|
set str set positional parameter to str
|
195 |
|
|
.ti -2i
|
196 |
|
|
set show the current shell variables
|
197 |
|
|
.ti -2i
|
198 |
|
|
shift reassign positional parameters (except ${0}) one left
|
199 |
|
|
.ti -2i
|
200 |
|
|
times print accumulated user and system times for processes
|
201 |
|
|
.ti -2i
|
202 |
|
|
trap arg sigs trap signals sigs and run arg on receipt
|
203 |
|
|
.ti -2i
|
204 |
|
|
trap list trapped signals
|
205 |
|
|
.ti -2i
|
206 |
|
|
umask [n] set the user file creation mask; show the current umask
|
207 |
|
|
.ti -2i
|
208 |
|
|
wait [n] wait for process pid n; wait for all processes
|
209 |
|
|
.in -2.25i
|
210 |
|
|
.LP
|
211 |
|
|
The shell also contains a programming language, which has the following
|
212 |
|
|
operators and flow control statements:
|
213 |
|
|
.PP
|
214 |
|
|
.in +3.50i
|
215 |
|
|
.ta 2i 3.25i
|
216 |
|
|
.ti -3.25i
|
217 |
|
|
# Comment The rest of the line is ignored
|
218 |
|
|
.ti -3.25i
|
219 |
|
|
= Assignment Set a shell variable
|
220 |
|
|
.ti -3.25i
|
221 |
|
|
&& Logical AND Execute second command only if first succeeds
|
222 |
|
|
.ti -3.25i
|
223 |
|
|
|| Logical OR Execute second command only if first fails
|
224 |
|
|
.ti -3.25i
|
225 |
|
|
(...) Group Execute enclosed commands before continuing
|
226 |
|
|
.in -3.50i
|
227 |
|
|
.PP
|
228 |
|
|
.in +2.25i
|
229 |
|
|
.ta 2i
|
230 |
|
|
.ti -2i
|
231 |
|
|
for For loop (for ... in ... do ... done)
|
232 |
|
|
.ti -2i
|
233 |
|
|
case Case statement ((case ... ) ... ;; ... esac)
|
234 |
|
|
.ti -2i
|
235 |
|
|
esac Case statement end
|
236 |
|
|
.ti -2i
|
237 |
|
|
while While loop (while ... do ... done)
|
238 |
|
|
.ti -2i
|
239 |
|
|
do Do/For/While loop start (do ... until ...)
|
240 |
|
|
.ti -2i
|
241 |
|
|
done For/While loop end
|
242 |
|
|
.ti -2i
|
243 |
|
|
if Conditional statement (if ... else ... elif ... fi)
|
244 |
|
|
.ti -2i
|
245 |
|
|
in For loop selection
|
246 |
|
|
.ti -2i
|
247 |
|
|
then Conditional statement start
|
248 |
|
|
.ti -2i
|
249 |
|
|
else Conditional statement alternative
|
250 |
|
|
.ti -2i
|
251 |
|
|
elif Conditional statement end
|
252 |
|
|
.ti -2i
|
253 |
|
|
until Do loop end
|
254 |
|
|
.ti -2i
|
255 |
|
|
fi Conditional statement end
|
256 |
|
|
.in -2.25i
|
257 |
|
|
.SH "SEE ALSO"
|
258 |
|
|
.BR echo (1),
|
259 |
|
|
.BR expr (1),
|
260 |
|
|
.BR pwd (1),
|
261 |
|
|
.BR true (1).
|