⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t2

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻
📖 第 1 页 / 共 2 页
字号:
.DS	ps a >/tmp/ps$$	\*(ZZ	rm /tmp/ps$$.DE.IP \fB$\|!\fP 8The process number of the last processrun in the background (in decimal)..IP \fB$\(mi\fP 8The current shell flags, such as\fB\(mix\fR and \fB\(miv\|.\fR.RE.LPSome variables have a special meaning to theshell and should be avoided for generaluse..RS.IP \fB$\s-1MAIL\s0\fP 8When used interactivelythe shell looks at the filespecified by this variablebefore it issues a prompt.If the specified file has been modifiedsince itwas last looked at the shellprints the message\fIyou have mail\fP before promptingfor the next command.This variable is typically setin the file \fB.profile,\fPin the user's login directory.For example,.DS	\s-1MAIL\s0=/usr/mail/fred.DE.IP \fB$\s-1HOME\s0\fP 8The default argumentfor the \fIcd\fP command.The current directory is used to resolvefile name references that do not begin witha \fB/\|,\fRand is changed using the \fIcd\fP command.For example,.DS	cd /usr/fred/bin.DEmakes the current directory \fB/usr/fred/bin\|.\fR.DS	cat wn.DEwill print on the terminal the file \fIwn\fPin this directory.The command\fIcd\fP with no argumentis equivalent to.DS	cd $\s-1HOME\s0.DEThis variable is also typically set in thethe user's login profile..IP \fB$\s-1PATH\s0\fP 8A list of directories that contain commands (the \fIsearch path\fR\|).Each time a command is executed by the shella list of directories is searchedfor an executable file..ne 5If \fB$\s-1PATH\s0\fP is not setthen the current directory,\fB/bin\fP, and \fB/usr/bin\fP are searched by default..ne 5Otherwise \fB$\s-1PATH\s0\fP consists of directorynames separated by \fB:\|.\fPFor example,.DS	\s-1PATH\s0=\fB:\fP/usr/fred/bin\fB:\fP/bin\fB:\fP/usr/bin.DEspecifies that the current directory(the null string before the first \fB:\fP\|),\fB/usr/fred/bin, /bin \fRand\fP /usr/bin\fRare to be searched in that order.In this way individual userscan have their own `private' commandsthat are accessible independentlyof the current directory.If the command name contains a \fB/\fR then this directory searchis not used; a single attemptis made to execute the command..IP \fB$\s-1PS1\s0\fP 8The primary shell prompt string, by default, `\fB$\ \fR'..IP \fB$\s-1PS2\s0\fP 8The shell prompt when further input is needed,by default, `\fB>\ \fR'..IP \fB$\s-1IFS\s0\fP 8The set of characters used by \fIblankinterpretation\fR (see section 3.4)..RE.SH2.5\ The\ test\ command.LPThe \fItest\fP command, although not part of the shell,is intended for use by shell programs.For example,.DS	test \(mif file.DEreturns zero exit status if \fIfile\fPexists and non-zero exit status otherwise.In general \fItest\fP evaluates a predicateand returns the result as its exit status.Some of the more frequently used \fItest\fParguments are given here, see \fItest\fP (1)for a complete specification..DS	test s		true if the argument \fIs\fP is not the null string	test \(mif file	true if \fIfile\fP exists	test \(mir file	true if \fIfile\fP is readable	test \(miw file	true if \fIfile\fP is writable	test \(mid file	true if \fIfile\fP is a directory.DE.SH2.6\ Control\ flow\ -\ while.LPThe actions ofthe \fBfor\fP loop and the \fBcase\fPbranch are determined by data available to the shell.A \fBwhile\fP or \fBuntil\fP loopand an \fBif then else\fP branchare also provided whoseactions are determined by the exit statusreturned by commands.A \fBwhile\fP loop has the general form.DS	\fBwhile\fP \fIcommand-list\*1\fP	\fBdo\fP \fIcommand-list\*2\fP	\fBdone\fP.DE.LPThe value tested by the \fBwhile\fP commandis the exit status of the last simple commandfollowing \fBwhile.\fPEach time round the loop\fIcommand-list\*1\fP is executed;if a zero exit status is returned then\fIcommand-list\*2\fPis executed;otherwise, the loop terminates.For example,.DS	while test $1	do \*(ZZ	\*(DOshift	done.DEis equivalent to.DS	for i	do \*(ZZ	done.DE\fIshift\fP is a shell command thatrenames the positional parameters\fB$2, $3, \*(ZZ\fR as \fB$1, $2, \*(ZZ\fRand loses \fB$1\|.\fP.LPAnother kind of use for the \fBwhile/until\fPloop is to wait until someexternal event occurs and then runsome commands.In an \fBuntil\fP loopthe termination condition is reversed.For example,.DS	until test \(mif file	do sleep 300; done	\fIcommands\fP.DEwill loop until \fIfile\fP exists.Each time round the loop it waits for5 minutes before trying again.(Presumably another processwill eventually create the file.).SH2.7\ Control\ flow\ -\ if.LPAlso available is ageneral conditional branchof the form,.DS	\fBif\fP \fIcommand-list	\fBthen	\fIcommand-list	\fBelse	\fIcommand-list	\fBfi\fR.DEthat tests the value returned by the last simple commandfollowing \fBif.\fP.LPThe \fBif\fP command may be usedin conjunction with the \fItest\fP commandto test for the existence of a file as in.DS	if test \(mif file	then	\fIprocess file\fP	else	\fIdo something else\fP	fi.DE.LPAn example of the use of \fBif, case\fPand \fBfor\fP constructions is given insection 2.10\|..LPA multiple test \fBif\fP commandof the form.DS	if \*(ZZ	then	\*(ZZ	else	if \*(ZZ		then	\*(ZZ		else	if \*(ZZ			\*(ZZ			fi		fi	fi.DEmay be written using an extension of the \fBif\fPnotation as,.DS	if \*(ZZ	then	\*(ZZ	elif	\*(ZZ	then	\*(ZZ	elif	\*(ZZ	\*(ZZ	fi.DE.LPThe following example is the \fItouch\fP commandwhich changes the `last modified' time for a listof files.The command may be used in conjunctionwith \fImake\fP (1) to force recompilation of a listof files..DS	flag=	for i	do case $i in	\*(DC\(mic)	flag=N ;;	\*(DC\*(ST)	if test \(mif $i	\*(DC	then	ln $i junk$$; rm junk$$	\*(DC	elif test $flag	\*(DC	then	echo file \\\\\'$i\\\\\' does not exist	\*(DC	else	>$i	\*(DC	fi	\*(DO esac	done.DEThe \fB\(mic\fP flag is used in this command toforce subsequent files to be created if they do not already exist.Otherwise, if the file does not exist, an error message is printed.The shell variable \fIflag\fPis set to some non-null string if the \fB\(mic\fPargument is encountered.The commands.DS	ln \*(ZZ; rm \*(ZZ.DEmake a link to the file and then remove itthus causing the last modified date to be updated..LPThe sequence.DS	if command1	then	command2	fi.DEmay be written.DS	command1 && command2.DEConversely,.DS	command1 \*(VT\*(VT command2.DEexecutes \fIcommand2\fP only if \fIcommand1\fPfails.In each case the value returnedis that of the last simple command executed..SH2.8\ Command\ grouping.LPCommands may be grouped in two ways,.DS	\fB{\fI command-list\fB ; }\fR.DEand.DS	\fB(\fI command-list\fB )\fR.DE.LPIn the first \fIcommand-list\fP is simply executed.The second form executes \fIcommand-list\fPas a separate process.For example,.DS	(cd x; rm junk ).DEexecutes \fIrm junk\fP in the directory\fBx\fP without changing the currentdirectory of the invoking shell..LPThe commands.DS	cd x; rm junk.DEhave the same effect but leave the invokingshell in the directory \fBx.\fP.SH2.9\ Debugging\ shell\ procedures.LPThe shell provides two tracing mechanismsto help when debugging shell procedures.The first is invoked within the procedureas.DS	set \(miv.DE(\fBv\fP for verbose) and causes lines of theprocedure to be printed as they are read.It is useful to help isolate syntax errors.It may be invoked without modifying the procedureby saying.DS	sh \(miv proc \*(ZZ.DEwhere \fIproc\fP is the name of the shell procedure.This flag may be used in conjunctionwith the \fB\(min\fP flag which preventsexecution of subsequent commands.(Note that saying \fIset \(min\fP at a terminalwill render the terminal uselessuntil an end-of-file is typed.).LPThe command.DS	set \(mix.DEwill produce an executiontrace.Following parameter substitutioneach command is printed as it is executed.(Try these at the terminal to seewhat effect they have.)Both flags may be turned off by saying.DS	set \(mi.DEand the current setting of the shell flags is available as \fB$\(mi\|.\fR.SH2.10\ The\ man\ command.LPThe following is the \fIman\fP commandwhich is used to print sections of the UNIX manual.It is called, for example, as.DS		man sh		man \(mit ed		man 2 fork.DEIn the first the manual section for \fIsh\fPis printed.Since no section is specified, section 1 is used.The second example will typeset (\fB\(mit\fP option)the manual section for \fIed.\fPThe last prints the \fIfork\fP manual pagefrom section 2..sp 2.DS	cd /usr/man	: \'colon is the comment command\'	: \'default is nroff ($N), section 1 ($s)\'	N=n\ s=1	for i	do case $i in.sp .5	\*(DC[1\(mi9]\*(ST)	s=$i ;;.sp .5	\*(DC\(mit)	N=t ;;.sp .5	\*(DC\(min)	N=n ;;.sp .5	\*(DC\(mi\*(ST)	echo unknown flag \\\\\'$i\\\\\' ;;.sp .5	\*(DC\*(ST)	if test \(mif man$s/$i.$s	\*(DC	then	${N}roff man0/${N}aa man$s/$i.$s	\*(DC	else	: \'look through all manual sections\'	\*(DC		found=no	\*(DC		for j in 1 2 3 4 5 6 7 8 9	\*(DC		do if test \(mif man$j/$i.$j	\*(DC		\*(DOthen man $j $i	\*(DC		\*(DO\*(THfound=yes	\*(DC		\*(DOfi	\*(DC		done	\*(DC		case $found in	\*(DC		\*(Cano) echo \\'$i: manual page not found\\'	\*(DC		esac	\*(DC	fi	\*(DOesac	done.DE.ce.ft BFigure 1. A version of the man command.ft R

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -