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