.TH SH 1 .SH NAME sh, ., break, case, cd, continue, eval, exec, exit, export, for, if, read, readonly, set, shift, trap, umask, wait, while \- shell .SH SYNOPSIS \fBsh\fR [\fB\-eiknqstvxu\fR] [\fB\-c \fIstr\fR] \fB[\fIfile\fR]\fR .br .de FL .TP \\fB\\$1\\fR \\$2 .. .de EX .TP 20 \\fB\\$1\\fR # \\$2 .. .SH OPTIONS .FL "\-c" "Execute the commands in \fIstr\fR" .FL "\-e" "Quit on error" .FL "\-i" "Interactive mode; ignore QUIT, TERMINATE, INTERRUPT" .FL "\-k" "Look for name=value everywhere on command line" .FL "\-n" "Do not execute commands" .FL "\-q" "Change qflag from sig_ign to sig_del" .FL "\-s" "Read commands from standard input" .FL "\-t" "Exit after reading and executing one command" .FL "\-v" "Echo input lines as they are read" .FL "\-x" "Trace" .FL "\-u" "Unset variables" .SH EXAMPLES .EX "sh script" "Run a shell script" .SH DESCRIPTION .I Sh is the shell, which forms the user's main interface with the system. On startup, the shell reads /etc/profile and $HOME/.profile, if they exist, and executes any commands they contain. The Minix shell has most of the features of the V7 (Bourne) shell, including redirection of input and output, pipes, magic characters, background processes, and shell scripts. A brief summary follows, but whole books have been written on shell programming alone. .LP Some of the more common notations are: .PP .in +2.45i .ta 2i 2.2i .ti -2.2i date # Regular command .ti -2.2i sort file2 # Redirect \fIstdin\fR and \fIstdout\fR .ti -2.2i cc file.c 2>error # Redirect \fIstderr\fR .ti -2.2i a.out >f 2>&1 # Combine standard output and standard error .ti -2.2i sort >file2 # Append output to \fIfile2\fR .ti -2.2i sort file2 & # Background job .ti -2.2i (ls \-l; a.out) & # Run two background commands sequentially .ti -2.2i sort with no command name, modify shell I/O .ti -2i exit [n] exit a shell program, with exit value n .ti -2i export [var] export var to shell's children; list exported variables .ti -2i pwd print the name of the current working directory .ti -2i read var read a line from stdin and assign to var .ti -2i readonly [var] make var readonly; list readonly variables .ti -2i set -f set shell flag (+f unsets flag) .ti -2i set str set positional parameter to str .ti -2i set show the current shell variables .ti -2i shift reassign positional parameters (except ${0}) one left .ti -2i times print accumulated user and system times for processes .ti -2i trap arg sigs trap signals sigs and run arg on receipt .ti -2i trap list trapped signals .ti -2i umask [n] set the user file creation mask; show the current umask .ti -2i wait [n] wait for process pid n; wait for all processes .in -2.25i .LP The shell also contains a programming language, which has the following operators and flow control statements: .PP .in +3.50i .ta 2i 3.25i .ti -3.25i # Comment The rest of the line is ignored .ti -3.25i = Assignment Set a shell variable .ti -3.25i && Logical AND Execute second command only if first succeeds .ti -3.25i || Logical OR Execute second command only if first fails .ti -3.25i (...) Group Execute enclosed commands before continuing .in -3.50i .PP .in +2.25i .ta 2i .ti -2i for For loop (for ... in ... do ... done) .ti -2i case Case statement ((case ... ) ... ;; ... esac) .ti -2i esac Case statement end .ti -2i while While loop (while ... do ... done) .ti -2i do Do/For/While loop start (do ... until ...) .ti -2i done For/While loop end .ti -2i if Conditional statement (if ... else ... elif ... fi) .ti -2i in For loop selection .ti -2i then Conditional statement start .ti -2i else Conditional statement alternative .ti -2i elif Conditional statement end .ti -2i until Do loop end .ti -2i fi Conditional statement end .in -2.25i .SH "SEE ALSO" .BR echo (1), .BR expr (1), .BR pwd (1), .BR true (1).