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

📄 ash.1

📁 操作系统设计与实现源码
💻 1
📖 第 1 页 / 共 3 页
字号:
     pairs  from all the exported shell variables, and then modifying this set
     by the assignments which precede the command, if any.

  Expansion

     The process of evaluating words when a shell  procedure  is  executed  is
     called   expansion.    Expansion   consists   of  four  steps:   variable
     substitution,  command  substitution,  word  splitting,  and  file   name
     generation.   If  a  word  is the expression following the word case in a
     case statement, the file name which follows a redirection symbol,  or  an
     assignment to the environment of a command, then the word cannot be split
     into multiple words.  In these cases, the last two steps of the expansion
     process are omitted.

  Variable Substitution

     To be written.

  Command Substitution

     Ash accepts two syntaxes for command substitution:

         `list`

     and

         $(list)

     Either  of  these  may  be  included  in  a  word.   During  the  command
     substitution process, the command (syntactly a list) will be executed and
     anything that the command writes to the standard output will be  captured
     by  the shell.  The final newline (if any) of the output will be deleted;
     the rest of the output will be substituted for the command in the word.

  Word Splitting


7BSD                              March 7, 1991                              6



SH(1)                     Minix Programmer's Manual                      SH(1)


     When the value of a variable or the output of a command  is  substituted,
     the  resulting  text is subject to word splitting, unless the dollar sign
     introducing the variable or backquotes containing the text were  enclosed
     in  double  quotes.   In addition, ``$@'' is subject to a special type of
     splitting, even in the presence of double quotes.

     Ash uses two different splitting algorithms.  The normal approach,  which
     is  intended  for splitting text separated by which space, is used if the
     first character of the shell variable  IFS  is  a  space.   Otherwise  an
     alternative   experimental  algorithm,  which  is  useful  for  splitting
     (possibly empty) fields separated by a separator character, is used.

     When performing splitting, the shell scans the replacement  text  looking
     for  a  character (when IFS does not begin with a space) or a sequence of
     characters (when IFS does begin with a space), deletes the  character  or
     sequence  of  characters,  and  spits  the  word into two strings at that
     point.  When IFS begins with a space, the shell  deletes  either  of  the
     strings  if they are null.  As a special case, if the word containing the
     replacement text is the null string, the word is deleted.

     The variable ``$@'' is special in two ways.  First, splitting takes place
     between the positional parameters, even if the text is enclosed in double
     quotes.  Second, if the word containing the replacement text is the  null
     string  and there are no positional parameters, then the word is deleted.
     The result of these rules is that "$@" is equivalent  to  "$1"  "$2"  ...
     "$n",  where  n  is the number of positional parameters.  (Note that this
     differs from the System V shell.  The System V documentation claims  that
     "$@"  behaves  this way; in fact on the System V shell "$@" is equivalent
     to "" when there are no positional paramteters.)

  File Name Generation

     Unless the -f flag is set, file name generation is performed  after  word
     splitting  is  complete.   Each  word  is viewed as a series of patterns,
     separated by slashes.  The process of expansion replaces  the  word  with
     the  names  of  all existing files whose names can be formed by replacing
     each pattern with a string that matches the specified pattern.  There are
     two  restrictions  on  this:   first,  a  pattern  cannot  match a string
     containing a slash, and second, a pattern cannot match a string  starting
     with a period unless the first character of the pattern is a period.

     If a word fails to match any files and the -z flag is not set,  then  the
     word  will  be  left  unchanged  (except that the meta-characters will be
     converted to normal characters).  If the -z flag is set, then the word is
     only  left unchanged if none of the patterns contain a character that can
     match anything besides itself.  Otherwise the -z flag forces the word  to
     be  replaced  with  the names of the files that it matches, even if there
     are zero names.

  Patterns


7BSD                              March 7, 1991                              7



SH(1)                     Minix Programmer's Manual                      SH(1)


     A pattern consists of normal  characters,  which  match  themselves,  and
     meta-characters.  The meta-characters are ``!'', ``*'', ``?'', and ``[''.
     These characters lose there special meanings if they  are  quoted.   When
     command or variable substitution is performed and the dollar sign or back
     quotes are not double quoted, the value of the variable or the output  of
     the  command  is  scanned  for  these characters and they are turned into
     meta-characters.

     Two exclamation points at the  beginning  of  a  pattern  function  as  a
     ``not''  operator,  causing  the  pattern  to  match  any string that the
     remainder of the pattern does not match.  Other occurances of exclamation
     points in a pattern match exclamation points.  Two exclamation points are
     required rather than one to decrease the incompatibility with the  System
     V shell (which does not treat exclamation points specially).

     An asterisk (``*'') matches any string of characters.   A  question  mark
     matches  any  single  character.   A  left  bracket  (``['') introduces a
     character class.  The end of the character class is indicated by a ``]'';
     if  the  ``]''  is  missing  then  the  ``['' matches a ``['' rather than
     introducing a character class.  A character  class  matches  any  of  the
     characters  between  the  square  brackets.  A range of characters may be
     specified using a minus sign.  The character class may be complemented by
     making an exclamation point the first character of the character class.

     To include a ``]'' in a character class,  make  it  the  first  character
     listed  (after  the ``!'', if any).  To include a minus sign, make it the
     first or last character listed.

  The /u Directory

     By convention, the name ``/u/user'' refers to the home directory  of  the
     specified  user.   There  are  good  reasons  why  this feature should be
     supported by the file system (using a feature  such  as  symbolic  links)
     rather  than  by the shell, but ash is capable of performing this mapping
     if the file system doesn't.  If the mapping is done by ash,  setting  the
     -f flag will turn it off.

  Character Set

     Ash silently discards  nul  characters.   Any  other  character  will  be
     handled  correctly  by  ash, including characters with the high order bit
     set.

  Job Names and Job Control

     The term job refers to a process created by a shell command,  or  in  the
     case of a pipeline, to the set of processes in the pipeline.  The ways to
     refer to a job are:

         %number


7BSD                              March 7, 1991                              8



SH(1)                     Minix Programmer's Manual                      SH(1)


         %string
         %%
         process_id

     The first form identifies a job by job number.  When a  command  is  run,
     ash  assigns it a job number (the lowest unused number is assigned).  The
     second form identifies a job by giving a prefix of the  command  used  to
     create  the  job.   The prefix must be unique.  If there is only one job,
     then the null prefix will identify the job, so you can refer to  the  job
     by writing ``%''.  The third form refers to the current job.  The current
     job is the last job to be stopped while it was in the  foreground.   (See
     the  next  paragraph.)   The  last  form  identifies  a job by giving the
     process id of the last process in the job.

     If the operating system that ash is running on supports job control,  ash
     will  allow  you  to  use it.  In this case, typing the suspend character
     (typically ^Z) while running a command will return you to  ash  and  will
     make  the  suspended  command the current job.  You can then continue the
     job in the background by typing  bg,  or  you  can  continue  it  in  the
     foreground by typing fg.

  Atty

     If the shell variable ATTY is set, and the shell variable TERM is not set
     to  ``emacs'', then ash generates appropriate escape sequences to talk to
     atty(1).

  Exit Statuses

     By tradition, an exit status of zero means that a command  has  succeeded
     and  a  nonzero  exit  status indicates that the command failed.  This is
     better than no convention at all, but in practice it is extremely  useful
     to  allow  commands  that  succeed  to  use  the  exit  status  to return
     information to the caller.  A variety of  better  conventions  have  been
     proposed,  but  none  of  them  has  met  with  universal  approval.  The
     convention used  by  ash  and  all  the  programs  included  in  the  ash
     distribution is as follows:
                 0           Success.
                 1           Alternate success.
                 2           Failure.
                 129-...     Command terminated by a signal.
     The alternate success return is used  by  commands  to  indicate  various
     conditions which are not errors but which can, with a little imagination,
     be conceived of as less successful than plain success.  For example, test
     returns  1  when the tested condition is false and getopts returns 1 when
     there  are  no  more  options.   Because  this  convention  is  not  used
     universally, the -e option of ash causes the shell to exit when a command
     returns 1 even though that contradicts the convention described here.




7BSD                              March 7, 1991                              9



SH(1)                     Minix Programmer's Manual                      SH(1)


     When a command is terminated by a signal, the uses 128  plus  the  signal
     number as the exit code for the command.

  Builtin Commands

     This concluding section lists the  builtin  commands  which  are  builtin
     because  they need to perform some operation that can't be performed by a
     separate process.  In addition to these, there are several other commands
     (catf,  echo,  expr,  line,  nlecho,  test,  ``:'',  and  true) which can
     optionally be compiled into the shell.  The  builtin  commands  described
     below that accept options use the System V Release 2 getopt(3) syntax.


  bg [ job ] ...
     Continue the specified jobs (or the current job if no jobs are given)  in
     the  background.   This command is only available on systems with Bekeley
     job control.

  command command arg...
     Execute the specified builtin command.  (This is useful when you  have  a
     shell function with the same name as a builtin command.)

  cd [ directory ]
     Switch to the specified directory (default $HOME).  If the an  entry  for
     CDPATH appears in the environment of the cd command or the shell variable
     CDPATH is set and the directory name does not begin with  a  slash,  then
     the  directories  listed  in  CDPATH  will  be searched for the specified
     directory.  The format of CDPATH is the same as  that  of  PATH.   In  an
     interactive  shell,  the  cd  command  will  print  out  the  name of the
     directory that it actually switched to if this is different from the name
     that  the  user  gave.   These may be different either because the CDPATH
     mechanism was used or because a symbolic link was crossed.

  . file
     The commands in the specified file are read and executed by the shell.  A
     path  search is not done to find the file because the directories in PATH
     generally contain files that are intended to be executed, not read.

  eval string...
     The strings are parsed as shell commands  and  executed.   (This  differs
     from  the  System V shell, which concatenates the arguments (separated by
     spaces) and parses the result as a single command.)

  exec [ command arg...  ]
     Unless command is  omitted,  the  shell  process  is  replaced  with  the
     specified  program  (which must be a real program, not a shell builtin or
     function).  Any redirections on the exec command are marked as permanent,
     so  that  they  are  not  undone  when the exec command finishes.  If the
     command is not found, the exec command causes the shell to exit.



7BSD                             March 7, 1991                              10



SH(1)                     Minix Programmer's Manual                      SH(1)


  exit [ exitstatus ]
     Terminate the shell process.  If exitstatus is given it is  used  as  the
     exit  status  of  the  shell;  otherwise the exit status of the preceding
     command is used.

  export name...
     The specified names  are  exported  so  that  they  will  appear  in  the
     environment of subsequent commands.  The only way to un-export a variable
     is to unset it.  Ash allows the value of a variable to be set at the same
     time it is exported by writing

         export name=value

     With no arguments the export command lists  the  names  of  all  exported
     variables.

  fg [ job ]
     Move the specified job or  the  current  job  to  the  foreground.   This
     command is only available on systems with Bekeley job control.

  getopts optstring var
     The System V getopts command.

  hash -rv command...
     The shell maintains  a  hash  table  which  remembers  the  locations  of
     commands.   With no arguments whatsoever, the hash command prints out the
     contents of this table.  Entries which have not been looked at since  the
     last  cd  command  are  marked with an asterisk; it is possible for these
     entries to be invalid.

     With arguments, the hash command removes the specified commands from  the
     hash  table  (unless they are functions) and then locates them.  With the
     -v option, hash prints the locations of the commands as  it  finds  them.
     The  -r  option  causes the hash command to delete all the entries in the
     hash table except for functions.

⌨️ 快捷键说明

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