home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / unix / csh4.arc / SHELL.DOC < prev    next >
Encoding:
Text File  |  1985-09-05  |  15.2 KB  |  462 lines

  1.         shell.exe 
  2.  
  3.  
  4.         command processor for ms.dos 
  5.  
  6.  
  7.         This is  yet  another  command.com  replacement.    It implements
  8.         unix-like shell commands (ls, mv, fgrep, rm, chdir,  chmod)  etc.
  9.         Other features include: 
  10.  
  11.  
  12.         1. Command line expansion of ambiguous file names.  
  13.  
  14.  
  15.         Programs  invoked  from  shell   never see '*.*' as an argument -
  16.         they see  the  list  of  all  matching  files  in    the  current
  17.         directory.  
  18.  
  19.  
  20.         2. History substitution - ala C-shell.  
  21.  
  22.  
  23.         History substitution is a powerful means to save retyping of long 
  24.         command lines.It allows you to do things like re-execute the last 
  25.         command,  re-execute  the  last  command but redirect output to a
  26.         file, or execute a  new  command  with  arguments  from  previous
  27.         command  lines.    The  last  20  commands  are saved, and can be
  28.         reviewed by typing the 'history' command.  
  29.  
  30.  
  31.         Previous commands can be referred to by their number, or relative 
  32.         to the  current  command's  number.    Parameters  from  previous
  33.         commands can be seperated out and used individually.  
  34.  
  35.  
  36.         History  substitutions  specifications  come  in  two parts - the
  37.         command number  specifier and the argument  specifier,  seperated
  38.         by a  colon.    The  argument    specifier  is optional; if it is
  39.         omitted, the entire command line is specified.  
  40.  
  41.  
  42.             <command specifier> ::= !! | !n | !-n 
  43.             !!  = last command
  44.             !n  = nth command
  45.             !-n = command n commands before current command number
  46.  
  47.  
  48.             <argument specifier> ::= :[^$*] | :n | :n* | <empty>
  49.             n   = number of argument (0 being the command name)
  50.             ^   = first argument (i.e. argv[1])
  51.             $   = last argument
  52.             *   = ^-$, or nothing if only one word on command line
  53.             n*  = arguments n through $
  54.  
  55.  
  56.             <history subst specification> ::= <command specifier><argument specifier>
  57.  
  58.  
  59.         This is not as complicatated as  it  may  appear.    Here  is  an
  60.         example session.  
  61.  
  62.  
  63.             0% ls *.c
  64.             *.c
  65.             foo.c bar.c
  66.             1% more foo.c
  67.             /* edit the last argument of the last command */
  68.             2% edit !!:$            
  69.             /* go off and edit */
  70.             /* reference last argument of last command */
  71.             3% fgrep foo !!:$ bar.c 
  72.             FOO.C : foo
  73.             BAR.C : foo
  74.             /* edit the second thru the last args of command 3 */
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.             4% edit !3:2*            
  85.             (go off and edit)
  86.             /* repeat last command */
  87.             %5 !!
  88.             (go off and edit)
  89.             /* remove the 1st argument of the command 2 before the current one */
  90.             %6 rm !-6:^
  91.  
  92.  
  93.         History  substitution here is a compatible subset of the C-shells
  94.         history substitution  facility.    Cshell  allows  even   weirder
  95.         combinations.  
  96.  
  97.  
  98.         3.  Multiple  commands  on  one  command line - Command lines are
  99.         split at  semicolons.  
  100.  
  101.  
  102.         example 
  103.  
  104.  
  105.             %0 ls -l *.c ; make shell.exe ; exit
  106.  
  107.  
  108.         4. Character escapes and argument quoting - i.e.  '\;' suppresses 
  109.         the command  parser  from  seeing  the  semicolon  as  a  command
  110.         seperator.  
  111.  
  112.  
  113.         Quotes are handles thusly: 
  114.  
  115.  
  116.             1.  String  surrounded  by  single quotes are stripped of the
  117.             single quotes, and passed without wild-card expansion to  the
  118.             invoked program.  
  119.  
  120.  
  121.             2.  Strings  surrounded  by double quotes are passed complete
  122.             with quotes to the calling program.   This  was  done  for  a
  123.             version  of grep that I have that accepts regular expressions
  124.         with embedded blanks within double quotes.  
  125.  
  126.  
  127.         5. Many builtin commands.  
  128.  
  129.  
  130.             a:              b:              c:              cat             
  131.             cd              chdir           chmod           cls             
  132.             commands        copy            cp              copy            
  133.             d:              del             dir             e:              
  134.             echo            era             erase           error           
  135.             exit            f:              fgrep           g:              
  136.             h:              hist            history         i:              
  137.             j:              ls              md              mkdir           
  138.             more            mv              no history      popd            
  139.             pushd           pwd             rd              rm              
  140.             rmdir           set             tee             touch           
  141.             y               
  142.  
  143.  
  144.         There are many that are simply aliases, e.g.    'copy'  and  'cp'
  145.         invoke the same program.  
  146.  
  147.  
  148.         6. commands description syntax 
  149.  
  150.  
  151.             terms used in syntax explanations :
  152.             
  153.             fname ::= PC-DOS ambiguous or unambiguous file or directory name.
  154.             
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.             uname ::= unambiguous PC-DOS file or directory name
  165.             
  166.             string ::= any string of printable characters of arbitrary(<512) length.
  167.             
  168.             filelist ::= filename [filename .. filename]
  169.             
  170.             noargs ::= no arguments at all
  171.             
  172.             {arg} ::= term is optional
  173.             
  174.             envstring ::=    <string>=<string> 
  175.  
  176.  
  177.         7. command syntax 
  178.  
  179.  
  180.         drive
  181.             a: | b: | c: | d: | e: | f: | g: | h: | i: | j: <noargs> 
  182.  
  183.  
  184.             changes default  drive.    If  you  don't  have such a drive,
  185.             nothing happens.  
  186.  
  187.  
  188.         cat
  189.             cat {<filelist>} 
  190.  
  191.  
  192.             copies specified files to  standard  output.    If  none  are
  193.             given, copies standard input to standard output 
  194.  
  195.  
  196.         cp
  197.             cp | copy <filelist> <uname> 
  198.  
  199.  
  200.             copies specified  files  to  destination  file or device.  If
  201.             more than one file is in the file list,  <uname>  must  be  a
  202.             directory.  
  203.  
  204.  
  205.         cd
  206.             cd | chdir <dirname> 
  207.  
  208.  
  209.             makes <dirname> the current default directory.  
  210.  
  211.  
  212.         chmod
  213.             chmod {-|+[rwh]*} <filelist> 
  214.  
  215.  
  216.             change file permissions for specified files 
  217.  
  218.  
  219.             +r, -r turn on or off read permission - i.e. hide the file.
  220.             +w, -w turn on or off write permission.
  221.             +h, -h turn on or off hidden attribute - converse of r
  222.             +a, -a turn on or off archive attribute
  223.  
  224.  
  225.             Note  that '-r' or '+rwh' are both valid syntax for switches.
  226.             Also new permission switches  are  permissable  between  file
  227.             names  with  the  following  warning: I don't reset the masks
  228.             between file names - if you have a second batch of  attribute
  229.             changes on  the  command  line,  the  effect is additive.  If
  230.             you're not  careful,  you  could  make  a  mess  of  a  files
  231.             attributes.  
  232.  
  233.  
  234.             If  you don't specify any attribute switches, file attributes
  235.             will be set  to  0,  which  means  read,write,not  hidden,not
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.             system, not  modified since last backup.  
  246.  
  247.  
  248.         cls
  249.             cls | clear <noargs> 
  250.  
  251.  
  252.             clears the screen and homes the cursor.  
  253.  
  254.  
  255.         commands
  256.             commands <noargs> 
  257.  
  258.  
  259.             prints a table of available built-in commands.  
  260.  
  261.  
  262.         del
  263.             del 
  264.  
  265.  
  266.             synonym for rm.  
  267.  
  268.  
  269.         dir
  270.             dir 
  271.  
  272.  
  273.             synonym for ls.  
  274.  
  275.  
  276.         echo
  277.             echo <anything> 
  278.  
  279.  
  280.             echos argument list to screen.  
  281.  
  282.  
  283.         era
  284.             era 
  285.  
  286.  
  287.             synonym for rm.  
  288.  
  289.  
  290.         error
  291.             error <noargs> 
  292.  
  293.  
  294.             prints returned value of last command to the screen.  
  295.  
  296.  
  297.         exit
  298.             exit <noargs> 
  299.  
  300.  
  301.             terminates execution of the shell.  
  302.  
  303.  
  304.         fgrep
  305.             fgrep <pattern> <filelist> 
  306.  
  307.  
  308.             looks for unambiguous pattern <pattern> in <filelist>.  echos 
  309.             lines matching to the screen.  
  310.  
  311.  
  312.         hist
  313.             hist | history <noargs> 
  314.  
  315.  
  316.             prints history list to standard output.  
  317.  
  318.  
  319.         ls
  320.             ls | dir {-[alqcr]} <filelist> 
  321.  
  322.  
  323.             Lists files that match <filelist> 
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.             -a all  files,  including  system  files are listed.  '.' and
  335.             '..' are suppressed, but you know they're there if  you  need
  336.             them, don't you?  
  337.             -l prints out file times, permissions, etc 
  338.             -q suppresses header line from display - useful when you want 
  339.             to pipe stuff into another program.  
  340.             -c print as one column.  
  341.             -r recurse through all encountered subdirectories.  
  342.  
  343.  
  344.         md
  345.             md | mkdir <uname> 
  346.  
  347.  
  348.             make a directory.  Prints an error if it can't be done 
  349.  
  350.  
  351.         more
  352.             more {-[0-9]*} {<filelist>} 
  353.  
  354.  
  355.             List file to screen with pauses 
  356.  
  357.  
  358.             -n  specify  tab  width  when  expanding  tabs, where n is an
  359.             integer.  more acts like 'cat'  when  redirected  -  you  can
  360.             concatenate files  in this manner.  If no files are specifed,
  361.             standard input is 'mored.' 
  362.  
  363.  
  364.         mv
  365.             mv <filelist> <uname> 
  366.  
  367.  
  368.             moves specified file or files to target specifed by  <uname>.
  369.             If  there  is  more  than one file in list, <uname> must be a
  370.             directory 
  371.  
  372.  
  373.         popd
  374.             popd <noargs> 
  375.  
  376.  
  377.             returns to directory at top of directory stack.  
  378.  
  379.  
  380.         pushd
  381.             pushd <uname> 
  382.  
  383.  
  384.             save  current  working  directory  on  directory  stack,  and
  385.             changes current working directory to <uname>.  
  386.  
  387.  
  388.         pwd
  389.             pwd 
  390.  
  391.  
  392.             prints current working directory to standard output.  
  393.  
  394.  
  395.         rd
  396.             rd | rmdir <uname> 
  397.  
  398.  
  399.             remove specified directory if possible.  
  400.  
  401.  
  402.         rm
  403.             rm {-q} <filelist> 
  404.  
  405.  
  406.             blows  away all files in <filelist>. If -q is specified, will
  407.             ask if they should be removed.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.         set
  419.             set {<envstring> {<envstring> .. <envstring>}} 
  420.  
  421.  
  422.             sets a string in the environment.   If  you  specify  'name='
  423.             with   no   string   after,   it  will  remove  it  from  the
  424.             environment.  If you don't specify a string, set  prints  out
  425.             current environment.  
  426.  
  427.  
  428.         tee
  429.             tee <uname> 
  430.  
  431.  
  432.             Copies  standard  input to standard output, depositing a copy
  433.             in <uname> 
  434.  
  435.  
  436.         touch
  437.             touch <filelist> 
  438.  
  439.  
  440.             Makes the modification time of specified  files  the  current
  441.             date and time.  
  442.  
  443.  
  444.         y
  445.             y <filelist> 
  446.  
  447.  
  448.             copies standard input to standard output, and then copies the 
  449.             specified files  to standard output.  Sort of the opposite of
  450.             tee, in other words.  
  451.  
  452.  
  453.         7. Helpful hints 
  454.  
  455.  
  456.             Use forward slashes in all path names - they get converted to 
  457.             back slashes before  dos  hears  about  them.    If  you  are
  458.             invoking a program that expects forward slashes (dos external 
  459.             commands frinstance) precede it with a back slash.  
  460.  
  461.  
  462.             put  single  quotes around arguments with semicolons in them,
  463.             so they don't turn into command delimiters.  
  464.  
  465.  
  466.             The set command affects only the local  shell's  environment.
  467.             You can 'exit' to command.com and the original environment is 
  468.             intact.   The  local  environment  is  4K  large  -  which is
  469.             useful.  
  470.  
  471.  
  472.             Exit and re-invoke if you have trouble loading large programs 
  473.             from it - shell dynamically allocates and  frees  memory  all
  474.             the  time,  but the AZTEC run-time doesn't tell DOS to shrink
  475.             memory 
  476.  
  477.  
  478.         8. Implementation notes 
  479.  
  480.  
  481.             DOS doesn't acknowledge  a  'change  default  drive'  command
  482.             until you issue  a  'get  current directory' call.  Why?  The
  483.             only way I figured this out is by disassembling command.com.  
  484.  
  485.  
  486.             This was developed with AZTEC C by MANX.  In  it  are  a  few
  487.             hacked  up  pieces  of  AZTECS library source, which I hereby
  488.             acknowledge.  If MANX has  a  problem  with  me  distributing
  489.             them,  they  can  call  me direct - I figure I'm doing them a
  490.             favor by disseminating this program  as  an  example  of  the
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.             power and quality of their compiler and development tools.  
  501.  
  502.  
  503.             If  you  have  the AZTEC compiler and MANX's version of make,
  504.             you can recreate the shell  from  source,  by  using  arc  to
  505.             unpack everything into a directory, editing the macros BINDIR 
  506.             and CLIB  and then making  shell.com.  I wouldn't try it with
  507.             any other compiler, because I make a lot of  calls  to  AZTEC
  508.             specific routines.    You can write your own commands and add
  509.             them  by  editing  cmds.c,  and  putting  the  name  of  your
  510.             subroutine and its associated command string into the builtin 
  511.             array.   
  512.  
  513.  
  514.             You  can  safely  modify  any  of my builtins, as long as you
  515.             don't assume that all of your static variables are  going  to
  516.             stay initialized to startup values.  
  517.  
  518.  
  519.             Any  of the other code (main.c, fexecvp.c fexecv.c) modify at
  520.             your own peril.  I break them every time I do it, and I wrote 
  521.             them!!!  
  522.  
  523.  
  524.             PC|MS-DOS has a limit of 20 file  handles.    If  you  add  a
  525.             command  that opens files, make sure you catch the ctrl-break
  526.             signal and close them.  Look at CAT.C or Y.C for examples.  
  527.  
  528.  
  529.         9. BUGS 
  530.             External DOS commands have trouble parsing the  command  line
  531.             when invoked from   shell.  The command line gets garbled.  I
  532.             spent a lot of time trying to figure this problem out  to  no
  533.             avail.  They apparently get their command line arguments some 
  534.             way that  is a mystery to me.  The only solution is either to
  535.             either run command.com, or 'exit'  to  the  original  command
  536.             prompt.  
  537.  
  538.  
  539.             This  problem  has  kept  me  from running this as a straight
  540.             command.com   replacement.    It  just  goes  to  show   that
  541.             Microsoft and IBM have one hell of a time following their own 
  542.             rules.  
  543.  
  544.  
  545.             Programs  compiled  by  AZTEC  C  that don't set up their own
  546.             signal  handlers  seem  to  be  'unbreakable'  -  you   can't
  547.             ctrl-break  out  of  them, as though SIGINT is set to SIG_IGN
  548.             before entry.  You might not want to invoke such a program if 
  549.         it lasts hours and you want to be able to break out of it.  
  550.  
  551.  
  552.         QUESTIONS COMMENTS GOTO 
  553.         KENT WILLIAMS
  554.         NORAND INC.
  555.         550 2nd ST. S.E.
  556.         Cedar Rapids Iowa 52401
  557.         (319) 338-6053 (HOME VOICE)
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.