]> err.no Git - sash/blob - sash.1
Stop stripping during build. Also thanks to Helmut Grohne. Closes: #852771
[sash] / sash.1
1 .TH SASH 1
2 .SH NAME
3 sash \- stand-alone shell with built-in commands
4 .SH SYNOPSYS
5 .B sash [-c command] [-f fileName ] [-p prompt] [-q] [-a]
6 .SH DESCRIPTION
7 The
8 .B sash
9 program is a stand-alone shell which is useful for recovering from certain
10 types of system failures.
11 In particular, it was created in order to cope with the problem of
12 missing shared libraries or important executables.
13 .PP
14 .B Sash
15 can execute external programs, as in any shell.  There are no restrictions
16 on these commands, as the standard shell is used to execute them if there
17 are any non-wildcard meta-characters in the command.
18 .PP
19 More importantly, however,
20 is that many of the standard system commands are built-in to
21 .BR sash .
22 These built-in commands are:
23 .PP
24 .nf
25      -ar, -chattr, -chgrp, -chmod, -chown, -chroot, -cmp,
26      -cp, -dd, -echo, -ed, -grep, -file, -find, -gunzip,
27      -gzip, -kill, -losetup, -ln, -ls, -lsattr, -mkdir,
28      -mknod, -more, -mount, -mv, -pivot_root, -printenv, -pwd,
29      -rm, -rmdir, -sum, -sync, -tar, -touch, -umount, -where
30 .fi
31 .PP
32 These commands are generally similar to the standard programs with similar
33 names.  However, they are simpler and cruder than the external programs,
34 and so many of the options are not implemented.  The restrictions for each
35 built-in command are described later.
36 .PP
37 The built-in commands which correspond to external programs begin with a
38 dash character in order to distinguish them from the external programs.
39 So typing "ls", for example, will attempt to run the real
40 .B ls
41 program.
42 If "-ls" is typed, then the built-in command which mimics
43 .B ls
44 is called.
45 .PP
46 For the built-in commands, file names are expanded so that asterisks,
47 question marks, and characters inside of square brackets are recognised
48 and are expanded.
49 Arguments can be quoted using single quotes, double quotes, or backslashes.
50 However, no other command line processing is performed.
51 This includes specifying of file redirection, and the specifying of a pipeline.
52 .PP
53 If an external program is non-existant or fails to run correctly, then
54 the "alias" built-in command may be used to redefine the standard command
55 so that it automatically runs the built-in command instead.  For example,
56 the command "alias ls -ls" redefines "ls" to run the built-in command.
57 This saves you the pain of having to remember to type the leading dash
58 all of the time.
59 If many external programs will not run, then the "aliasall" command may
60 be useful to create multiple aliases.
61 .PP
62 The "help" command will list all of the built-in commands in
63 .B sash .
64 If an argument is given, it will list only those built-in commands
65 which contain the given argument as a sub-string.
66 Each built-in command is described below in more detail.
67 .PP
68 .TP
69 .B alias [name [command]]
70 If
71 .I name
72 and
73 .I command
74 are provided, this defines an alias for a command with the specified name
75 which executes the specified command with possible arguments.
76 Arguments containing wildcards can be quoted in order to defer their
77 expansion until the alias is invoked.
78 If just
79 .I name
80 is provided, then the definition
81 of the specified command alias is displayed.  If nothing is provided,
82 then the definitions of all aliases are displayed.
83 .TP
84 .B aliasall
85 This defines aliases for all of the built-in commands that start with
86 dashes to the corresponding names without the dashes.
87 This may be useful when the system is so corrupted that no external
88 programs may be executed at all.
89 .TP
90 .B -ar [txp][v] arfile [filename]...
91 List or extract files from an ar archive.
92 The arfile argument specifies a file name which contains the archive.
93 If no additional filenames are specified, then all files in the archive are
94 operated on.
95 Otherwise, only those archive members which have the same name 
96 as one of the additional filenames are operated on.
97 Filenames which do not appear in the archive are ignored.
98 Archives cannot be created or modified.
99 The archiver correctly handles 4.0BSD archives,
100 and understands both the SysV and 4.4BSD extensions for long file names.
101 The extended pseudo-BSD formats are not supported;
102 nor are the two antediluvian binary formats derived from V7 and earlier.
103 (The GNU archiver normally creates archives in the 4.0BSD format with
104 SysV extensions.)
105 .TP
106 .B cd [dirName]
107 If
108 .I dirName
109 is provided, then the current directory is changed to the
110 dirName.  If
111 .I dirName
112 is absent, then the current directory is changed
113 to the user's home directory (value of the $HOME environment variable).
114 .TP
115 .B -chattr [+i] [-i] [+a] [-a] fileName ...
116 Change the attributes of the specified files on an ext2 or ext3 file system.
117 Using a plus sign adds the specified attribute for the files.
118 Using a minus sign removes the specified attributes for the files.
119 The 'i' attribute makes a file immutable so that it cannot be changed.
120 The 'a' attribute makes a file append-only.
121 This command is only available on Linux.
122 .TP
123 .B -chgrp gid fileName ...
124 Change the group id for the specified list of files.  The
125 .I gid
126 can
127 either be a group name, or a decimal value.
128 .TP
129 .B -chmod mode fileName ...
130 Change the mode of the specified list of files.  The
131 .I mode
132 argument
133 can only be an octal value.
134 .TP
135 .B -chown uid fileName ...
136 Change the owner id for the specified list of files.  The
137 .I uid
138 can
139 either be a user name, or a decimal value.
140 .TP
141 .B -chroot path
142 Changes  the  root  directory to that specified in
143 .I path.
144 This directory
145 will be used for path  names  beginning with /. The root directory is
146 inherited by all children of the current process.
147 .TP
148 .B -cmp fileName1 fileName2
149 Determines whether or not the specified file names have identical data.
150 This says that the files are links to each other, are different sizes,
151 differ at a particular byte number, or are identical.
152 .TP
153 .B -cp srcName ... destName
154 Copies one or more files from the
155 .I srcName
156 to the
157 .IR destName .
158 If more
159 than one srcName is given, or if destName is a directory, then all
160 the srcNames are copied into the destName directory with the same
161 names as the srcNames.
162 .TP
163 .B -dd if=name of=name [bs=n] [count=n] [skip=n] [seek=n]
164 Copy data from one file to another with the specified parameters.
165 The
166 .I if
167 and
168 .I of
169 arguments must be provided, so stdin and stdout cannot
170 be specified.  The
171 .I bs
172 argument is the block size, and is a numeric
173 value (which defaults to 512 bytes).
174 .I Count
175 is the number of blocks
176 to be copied (which defaults to end of file for the input file).
177 .I Skip
178 is the number of blocks to ignore before copying (seek is used
179 if possible, and the default is 0).
180 .I Seek
181 is the number of blocks to
182 seek in the output file before writing (and defaults to 0).  Any of
183 the numeric decimal values can have one or more trailing letters
184 from the set 'kbw', which multiplies the value by 1024, 512, and 2
185 respectively.  The command reports the number of full blocks read
186 and written, and whether or not any partial block was read or written.
187 .TP
188 .B -echo [args] ...
189 Echo the arguments to the -echo command.  Wildcards are expanded,
190 so this is a convenient way to get a quick list of file names in a directory.
191 The output is always terminated with a newline.
192 .TP
193 .B -ed [fileName]
194 Edit the specified file using line-mode commands.  The following
195 .B ed
196 commands are provided: = c r w i a d p l s f k z and q.
197 Line numbers can be constants, ".", "$", "'x", 
198 .RI / string /
199 and simple
200 arithmetic combinations of these.  The substitute command and the
201 search expression can only use literal strings.  There are some
202 small differences in the way that some commands behave.
203 .TP
204 .B exec fileName [args]
205 Execute the specified program with the specified arguments.
206 This replaces
207 .B sash
208 completely by the executed program.
209 .TP
210 .B exit
211 Quit from
212 .BR sash .
213 .TP
214 .B -file fileName ...
215 Examine the specified files and print out their file type.
216 This indicates whether the files are regular files or not,
217 whether they contain printable text or shell scripts,
218 are executables, or contain binary data.
219 .TP
220 .B -find dirName [-xdev] [-type chars] [-name pattern] [-size minSize]
221 Find all files contained within the specified directory
222 tree which meet all of the specified conditions.
223 The -xdev option prevents crossing of mount points.
224 The -name option specifies a wildcard pattern to match the last
225 component of the file names.
226 The -type option specifies that the files must have a type
227 matching the specified list from the set: f d c b p s l.
228 These represent regular files, directories, character devices,
229 block devices, named pipes, sockets, and symbolic links.
230 The -size option specifies that the files must be regular files or
231 directories which contain at least the specified number of bytes.
232 .TP
233 .B -grep [-in] word fileName ...
234 Display lines of the specified files which contain the given word.
235 If only one file name is given, then only the matching lines are
236 printed.  If multiple file names are given, then the file names are
237 printed along with the matching lines.
238 .I Word
239 must be a single word,
240 (ie, not a regular expression).  If -i is given, then case is
241 ignored when doing the search.  If -n is given, then the line
242 numbers of the matching lines are also printed.
243 .TP
244 .B -gunzip inputFileName ... [-o outputPath]
245 Uncompress one or more files that had been compressed using the
246 .I gzip
247 or
248 .I compress
249 algorithms.
250 If the -o option is not given,
251 then each of the input file names must have one of the
252 extensions ".gz", ".tgz", or ".Z",
253 and those files will be replaced by the uncompressed versions of those files.
254 The original files will be deleted after the output files have been
255 successfully created.
256 The uncompressed versions of the files have the same names as the original
257 file names, except for a simple modification of their extensions.
258 If an extension is ".tgz", then the extension is replaced by ".tar".
259 Otherwise, the ".gz" or ".Z" extension is removed.
260 .sp
261 If the -o option is given, then the input files will not be deleted,
262 and the uncompressed versions of the files will be created as specified
263 by
264 .IR outputPath .
265 If the output path is a directory, then the uncompressed versions of the
266 input files will be placed in that directory with their file names
267 modified as described above, or with the same name if the input file name
268 does not have one of the special extensions.
269 If the output path is a regular file, then only one input file is allowed,
270 and the uncompressed version of that input file is created as the output
271 path exactly as specified.
272 If the output path is a block or character device, then the uncompressed
273 versions of the input files are concatenated to the device.
274 .sp
275 This command is only available if
276 .B sash
277 was compiled to use the gzip library.
278 .TP
279 .B -gzip inputFileName ... [-o outputPath]
280 Compresses one or more files using the
281 .I gzip
282 algorithm.
283 If the -o option is not given,
284 then each of the input file names will be replaced by the compressed
285 versions of those files,
286 The original files will be deleted after the output files have been
287 successfully created.
288 The compressed versions of the files have the same names as the original
289 file names, except for a simple modification of the extensions.
290 If an extension is ".tar", then the extension is replaced by ".tgz".
291 Otherwise, the ".gz" extension is added.
292 .sp
293 If the -o option is given, then the input files will not be deleted,
294 and the compressed versions of the files will be created as specified
295 by
296 .IR outputPath .
297 If the output path is a directory, then the compressed versions of the
298 input files will be placed in that directory with their file names
299 modified as described above.
300 If the output path is not a directory, then only one input file is allowed,
301 and the compressed version of that input file is created as the output
302 path exactly as specified.
303 .sp
304 This command is only available if
305 .B sash
306 was compiled to use the gzip library.
307 .TP
308 .B help [word]
309 Displays a list of built-in commands along with their usage strings.
310 If a word is given,
311 then just those commands whose name or usage contains the word is displayed.
312 If a word is specified which exactly matches a built-in command name,
313 then a short description of the command and its usage is given.
314 .TP
315 .B -kill [-signal] pid ...
316 Sends the specified signal to the specified list of processes.
317 .I Signal
318 is a numeric value, or one of the special values HUP, INT,
319 QUIT, KILL, TERM, STOP, CONT, USR1 or USR2.
320 If no signal is specified then SIGTERM is used.
321 .TP
322 .B -losetup [-d] loopDev [file]
323 Associates loopback devices with files on the system. If
324 .I -d
325 is not given,
326 the loopback device
327 .I loopDev
328 is associated with
329 .I file.
330 If
331 .I -d
332 is given,
333 .I loopDev
334 is unassociated with the file it's currently configured for.
335 .TP
336 .B -ln [-s] srcName ... destName
337 Links one or more files from the
338 .I srcName
339 to the specified
340 .IR destName .
341 If there are
342 multiple srcNames, or destName is a directory, then the link is
343 put in the destName directory with the same name as the source name.
344 The default links are hard links.  Using -s makes symbolic links.
345 For symbolic links, only one srcName can be specified.
346 .TP
347 .B -ls [-lidFC] fileName ...
348 Display information about the specified list of file names.
349 The normal listing is simply a list of file names, one per line.
350 The options available are -l, -n, -i, -d, and -F.
351 The -l option produces a long listing giving the normal 'ls' information.
352 The -n option is like -l except that numeric user and group ids are shown.
353 The -i option displays the inode numbers of the files.
354 The -d option displays information about a directory, instead of the
355 files within it.
356 The -F option appends a slash or asterisk to the file name if the file
357 is a directory or is executable.
358 The -C option displays the file names in a multi-column format.
359 The width of the output is calculated using the COLS environment variable.
360 .TP
361 .B -lsattr fileName ...
362 Display attributes for the specified files on an ext2 or ext3 file system.
363 The letter 'i' indicates that the file is immutable and cannot change.
364 The letter 'a' indicates that the file is append-only.
365 Dashes are shown where the attributes are not set.
366 This command is only available on Linux.
367 .TP
368 .B -mkdir dirName ...
369 Creates the specified directories.  They are created with the
370 default permissions.
371 .TP
372 .B -mknod fileName type major minor
373 Creates a special device node, either a character file or a block
374 file.
375 .I Filename
376 is the name of the node.
377 .I Type
378 is either 'c' or 'd'.
379 .I Major
380 is the major device number.
381 .I Minor
382 is the minor device number.
383 Both of these numbers are decimal.
384 .TP
385 .B -more fileName ...
386 Type out the contents of the specified file names, one page at a
387 time.  For each page displayed, you can type 'n' and a return to go
388 to the next file, 'q' and a return to quit the command completely,
389 or just a return to go to the next page.  The environment variables
390 LINES and COLS can be used to set the page size.
391 .TP
392 .B -mount [-t type] [-r] [-s] [-e] [-m] devName dirName
393 Mount a filesystem on a directory name.
394 The -t option specifies the type of filesystem being mounted,
395 and defaults to "ext3" for Linux and "ffs" for BSD.
396 The -r option indicates to mount the filesystem read-only.
397 The -s option indicates to mount the filesystem no-suid.
398 The -e option indicates to mount the filesystem no-exec.
399 The -m option indicates to remount an already mounted filesystem.
400 The -m option is only available on Linux.
401 .TP
402 .B -mv srcName ... destName
403 Moves one or more files from the
404 .I srcName
405 to the
406 .IR destName .
407 If multiple srcNames are given, or if destName is a directory, then
408 the srcNames are copied into the destination directory with the
409 same names as the srcNames.  Renames are attempted first, but if
410 this fails because of the files being on different filesystems,
411 then copies and deletes are done instead.
412 .TP
413 .B -pivot_root newRoot putOld
414 Moves the root file system of the current process to the directory
415 .I putOld
416 and makes
417 .I newRoot
418 the  new root file system of the current process.
419 .TP
420 .B -printenv [name]
421 If
422 .I name
423 is not given, this prints out the values of all the current
424 environment variables.  If
425 .I name
426 is given, then only that environment variable value is printed.
427 .TP
428 .B prompt [word] ...
429 Sets the prompt string that is displayed before reading of a
430 command.  A space is always added to the specified prompt.
431 .TP
432 .B -pwd
433 Prints the current working directory.
434 .TP
435 .B quit
436 Exits from
437 .BR sash .
438 .TP
439 .B -rm fileName ...
440 Removes one or more files.
441 .TP
442 .B -rmdir dirName ...
443 Removes one or more directories.  The directories must be empty
444 for this to be successful.
445 .TP
446 .B setenv name value
447 Set the value of an environment variable.
448 .TP
449 .B source fileName
450 Execute commands which are contained in the specified file name.
451 .TP
452 .B -sum fileName ...
453 Calculates checksums for one or more files.
454 This is the 16 bit checksum compatible with the BSD sum program.
455 .TP
456 .B -sync
457 Do a "sync" system call to force dirty blocks out to the disk.
458 .TP
459 .B -tar [ctxv]f tarFileName [fileName] ...
460 Create, list or extract files from a tar archive.
461 The f option must be specified, and accepts a device or file name
462 argument which contains the tar archive.
463 When creating, at least one file name must be specified to be stored.
464 If a file name is a directory, then all the files and directories
465 within the directory are stored.
466 Linked files and other special file types are not handled properly.
467 When listing or extracting files, only those files starting with
468 the specified file names are processed.
469 If no file names are specified, then all files in the archive are processed.
470 Leading slashes in the tar archive file names are always removed so that you
471 might need to cd to "/" to restore files which had absolute paths.
472 .TP
473 .B -touch fileName ...
474 Updates the modify times of the specifed files.  If a file does not
475 exist, then it will be created with the default protection.
476 .TP
477 .B umask [mask]
478 If
479 .I mask
480 is given, sets the "umask" value used for initializing the
481 permissions of newly created files.  If
482 .I mask
483 is not given, then the
484 current umask value is printed.  The mask is an octal value.
485 .TP
486 .B -umount [-f] fileName
487 Unmounts a file system.  The file name can either be the device name
488 which is mounted, or else the directory name which the file system
489 is mounted onto.
490 The -f option unmounts the filesystem even if it is being used.
491 The -f option is only available on BSD.
492 .TP
493 .B unalias name
494 Remove the definition for the specified alias.
495 .TP
496 .B -where program
497 Prints out all of paths defined by the PATH environment variable where the
498 specified program exists.  If the program exists but cannot be executed,
499 then the reason is also printed.
500 .SH OPTIONS
501 There are several command line options to
502 .BR sash .
503 .PP
504 The -c option executes the next argument as a command (including embedded
505 spaces to separate the arguments of the command), and then exits.
506 .PP
507 The -f option executes the commands contained in the file name specified
508 by the next argument, and then exits.
509 This feature can be used to create executable scripts for
510 .B sash
511 by starting the script file with a line similar to:
512 .nf
513         #! /bin/sash -f
514 .fi
515 .PP
516 The -p option takes the next argument as the prompt string to be used
517 when prompting for commands.
518 .PP
519 The -q option makes
520 .B sash
521 quiet, which simply means that it doesn't print its introduction line
522 when it starts.
523 This option is also implied if the -c or -f options are used.
524 .PP
525 The -a option creates aliases for the built-in commands so
526 that they replace the corresponding standard commands.
527 This is the same result as if the 'aliasall' command was used.
528 .SH SYSTEM RECOVERY
529 This section contains some useful information about using
530 .B sash
531 with
532 .B lilo
533 to perform system recovery in some situations.
534 Similar concepts should exist for other boot loaders and operating systems.
535 .PP
536 When important shared libraries are being upgraded,
537 it might be a good idea to have
538 .B sash
539 already running on a console by itself.
540 Then if there is a problem with the shared libraries
541 .B sash
542 will be unaffected and you may be able to use it to fix the problem.
543 .PP
544 If a problem with the system shows up at boot time so that you cannot
545 enter multi-user mode and log in,
546 then you can first try booting into single-user mode by adding the
547 .I single
548 keyword after your kernel image name at the
549 .B lilo
550 prompt.
551 If you manage to reach a shell prompt, then you can run
552 .B sash
553 from that shell (if necessary).
554 One reason for doing this is that you might need to use the
555 .B -mount
556 command with the -m option to remount the root file system
557 so that it can be modified.
558 .PP
559 If you cannot reach the shell in single-user mode,
560 then you can try running sash directly as a replacement for the init process.
561 This is done by adding the
562 .I init=/bin/sash
563 keyword after your kernel image name at the
564 .B lilo
565 prompt.
566 When this is done, then the use of the
567 .B aliasall
568 command might be useful to reduce attempts to access the root file system
569 when running commands.
570 .PP
571 If your root file system is so corrupted that you cannot get
572 .B sash
573 to run at all, then you will have to resort to a system recovery floppy.
574 .SH WARNINGS
575 .B Sash
576 should obviously be linked statically, otherwise its purpose is lost.
577 Note that even if the rest of the program is linked statically, the
578 password and group lookup routines in the C library can still be dynamic.
579 For that reason, if there are problems then it might be necessary to
580 only use numeric ids for the -chown and -chgrp commands and to use
581 the -n option instead of -l for the -ls command.
582 .PP
583 Several other system commands might be necessary for system recovery,
584 but aren't built-in to
585 .BR sash .
586 .SH AUTHOR
587 .nf
588 David I. Bell
589 dbell@tip.net.au
590 5 March 2014
591 .fi