Search:
+subject: akanga - rc based shell

AKANGA(1)                                               AKANGA(1)



NAME
       akanga - rc based shell

SYNOPSIS
       akanga [-eixvldnpo] [-c command] [arguments]

DESCRIPTION
       akanga  is  an rc(1) based shell.  For a complete descrip-
       tion see that man page.  This one describes only the addi-
       tional commands.

       New commands have been added to rc to simplify the writing
       of reliable and robust shell programs.

   Temporary Files
       The mktemp command creates temporary  files  as  they  are
       needed.   These  filenames  are  usually unique but mktemp
       doesn't verify this.  The filename generation scheme  sug-
       gets that if such a file already exists it's out of age.
       Normally  the  temporary  files  are automatically removed
       when  the  shell  terminates.   It  does  this  using   an
       atexit(3)  handler.   There  are  however situations where
       this doesn't work, e.g. when the shell is terminated  with
       the exec command or inside ``inline subshells''.

   Lockfiles
       Lockfiles  generated with lock are also removed on exit of
       the shell if they still exist.  There are however the same
       restrictions for lockfiles as for temporary files.
       lock uses the open(3) system call with a special parameter
       combination.  This system call is usually atomic and if it
       is it's reliable that there is no second process succeding
       in creating the lock the same time.

   Reading Standard Input
       The read command is alomost compatible to the one found in
       other shells like e.g. bash(1).  But notice that it cannot
       be used with redirection as in

            read uptime idletime </proc/uptime

       because rc forks each time it's sees input/ouput  redirec-
       tion.   read  would work in that constellation but set the
       variables in a subshell.
       The read command can also create an array variable as in

            read -n args

       This will read the next line, split it completly into it's
       parts  using  $ifs and create one element in args for each
       part.


   Reading Configuration Data
       readvars reads assignment from it's input.  E.g.

            readvars var. <<--
            x = Variable with assignment character.
            y  One without.
            --

       would  define  two  variables,  $(var.x)   and   $(var.y).
       readvars  takes the first word from each line, puts a pre-
       fix infront to get  the  variable  name  and  assigns  the
       remainder of the line as it's value.  The assignment char-
       acter ``='' is optional but can be  made  mandantory  with
       the  -d  option.   Variable name, assignment character and
       value may be surrounded by white space like in

            readvars -d : cpu. /proc/cpuinfo

       Notice that variable names that contain a ``.'' have to be
       quoted like $(var.x) or $'var.y'.
       The  $()  construct is nice to read but doesn't work under
       all circumstances.  If a function  is  exported  into  the
       environment  it's stored without the parentheses and read-
       ing it later from the environment again, e.g.  in  a  sub-
       shell, will access different code.

       The  readvars  command is useful when a configuration file
       has to be read where usually the dot command  ``.''  would
       have been used.  In opposite to this readvars accepts only
       assignments and not accidently inserted commands.

       Another way to store configuration settings  is  to  store
       them in one file that contains different sections like in

            [localhost]
            address = 127.0.0.1
            pop3login = myAccount
            pop3passwd = myPasswd

            [pop3server]
            address = pop.server.tld
            pop3login = anotherAccount
            pop3passwd = anotherPasswd

       If   the   example  data  above  is  stored  in  the  file
       /etc/pop3.conf the localhost section can be read with

            readconf config. /etc/pop3.conf localhost

       readconf creates the variables  $'config.address',  $'con-
       fig.pop3login' and $'config.pop3passwd'.

   Initializing Variables
       One difference between rc and bash is that

            x=''
            rc -c 'echo $#*' $x

       prints ``1'' and the analog example with bash echos ``0''.
       So even if a variable is empty in rc it is an  argument  -
       as  long  the variable is initialized.  If in the previous
       example $x wouldn't have been initialized  with  an  empty
       string rc would also have echoed ``0''.
       The  initvars command initializes a list of variables with
       a given value if  they  aren't  already  set.   The  empty
       string counts as ``set'' in this context.

       The  initialization  of  variables  is also important when
       variables are read with readvars or readconf and  the  set
       of configured variables is not known in advance.

   Arithmetic Expressions
       The expr and let command are a substitute for the external
       expr(1) and the builtin let  and  test  known  from  other
       shells.    With   a   modified   rc   grammer   arithmetic
       substitution becomes also available:

            $:expr

       returns the result if expr.  For  a  complete  description
       see akangaexpr(1).

COMMANDS
       The  following commands have been added to the original rc
       interpreter.

       expr [-n|-e] expression ...
              Evaluates each of the given expressions and  prints
              their  result.  For a description of the expression
              syntax see akangaexpr(1).

       initvars [-s] value var [var2 ...]
              Checks if each of the given  variables  is  defined
              (the  empty  string is a defined value) and assigns
              value if not.  If -s is given value  the  check  is
              omitted and value is assigned to each var.

       let [-n|-e] expression ...
              Similiar  to  expr:  evaluates  each  of  the given
              expressions but doesn't print their  results.   See
              akangaexpr(1)  for  a description of the expression
              syntax.

       lock [-s stale] [-w wait] filename
              Creates a lockfile with the name ``filename.lock''.
              If a file with this name already exists and if it's
              older than stale seconds (default 300) it  will  be
              ignored  and  removed.   Otherwise akanga will wait
              wait seconds (default 30) for the lockfile to  dis-
              appear.  If the lockfile still exists after waiting
              akanga fails returning an error code.

       mktemp var [var2] [...]
              Creates an unique temporary filename for each vari-
              able  name var and assigns the filename to the cor-
              responding variable.  Variable names  may  be  pre-
              fixed  with  a -.  In this case the file is created
              in the current directory and not in /tmp.
              mktemp uses the value of the tmpprefix variable  to
              put  it  into the name of the temporary file if the
              variable is set.
              After a filename is generated mktemp  checks  if  a
              file  with  this  name  already  exists.  If mktemp
              finds one it tries to  remove  it  and  returns  an
              error if it cannot remove one of the already exist-
              ing files.
              The temporary files created with mktemp are usually
              automatically  removed  when  akanga terminates but
              see section about temporary files above.

       parseopt var optstring parameters
              Similiar to getopt(1), reorders option strings from
              optstring and parameters for easy shell parsing and
              assigns the resulting list to var.  optstring  enu-
              merates the option letters.  If an option letter is
              followed by a ``:'' this  option  has  a  parameter
              that  follows  the option immediatly in $var.  When
              processing the parameters an argument starting with
              a ``-'' is completly interpreted as option list, no
              option argument is taken from  it.   The  following
              parameter list return the same $x:

                   parseopt x abc:d -a -b -c 'Hello World!' -d AB
                   parseopt x abc:d -abcd 'Hello World!' AB
                   parseopt x abc:d -ab -cd 'Hello World!' AB

              which is equivalent to

                   -a -b -c 'Hello World!' -d -- AB

              Interpretation of the parameters stops  if  a  non-
              option  argument  is  recognized or the argument is
              either ``-'' or ``--''.  If ``--'' is found in  the
              parameter  list  no  additional  ``--'' is inserted
              into var.  ``*'' can be used for var but it has  to
              be  quoted.  parseopt needs no special handling for
              arguments containing white space.

       read var [var2 ...]
              Reads a line from the standard input and splits  it
              into  parts using the characters found in $ifs. The
              first part is assigned to the  first  variable  var
              and  so on until the last variable is reached which
              recieves the unprocessed remainder of the line.

       read -n var
              Is similiar  to  the  read  above  but  instead  of
              assigning  the  input  to named variables the input
              line is splitted into  it's  part  using  $ifs  and
              assigned to var creating an array.

       readconf prefix configfile [section ...]
              reads the set of configuration values found in sec-
              tion section in the configuration file  configfile.
              The  variable  names are made of the prefix and the
              variable name in the assignment.
              If more than one section is given  on  the  command
              line  readconf ignores the prefix argument and uses
              the section name for it.  If  no  section  name  is
              given readconf read all sections from configfile.

       readvars [-d delim] [prefix [filename]]
              reads a set of variable assignments of the form

                   var = value

              from  file filename. Each variable name var is pre-
              fixed with prefix. If prefix is not  given  on  the
              command  line  rc will use ``rv.''.  The assignment
              character ``='' is optional.  Both is changed  with
              the -d option.
              filename  can be a filename in which case the whole
              file is read.  If filename is missing rc reads it's
              standard  input  until  the end of file is reached.
              If filename is - the standard input is  read  until
              an  empty line is found in the input skipping blank
              lines infront of an assignment block.
              readvars doesn't assign lists.

       shift var [n]
              Deletes n elements (default 1) from  the  beginning
              of var and shifts the other elements down by n.
              Both  version  of  shift  are  distinguished by the
              first argument to shift.  If it  is  a  number  the
              standard shift is used

       unlock file [file2 ...]
              Removes  the  previously placed locks for the given
              files.

CREDITS
       rc was written by Byron Rakitzis, with valuable help  from
       Paul  Haahr,  Hugh  Redelmeier  and  David Sanderson.  The
       design of this shell has been copied from the rc that  Tom
       Duff wrote at Bell Labs.

SEE ALSO
       rc(1), akangaexpr(1).



                          7 August 1999                 AKANGA(1)