home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rximc175.zip / shell.rexx < prev    next >
OS/2 REXX Batch file  |  1999-02-10  |  2KB  |  106 lines

  1. /* small shell program. */
  2. trace off
  3. signal on halt
  4. signal on syntax
  5. address command
  6. home=value("HOME",,"ENVIRONMENT")
  7. startup=home'/.shellrc'
  8. address command 'test -f' startup
  9. if rc=0 then address unix 'rxstack < 'startup
  10. alias.=""
  11. noargs.=0
  12. hostname='/bin/hostname'()
  13. rc=0
  14. n=1
  15. t=0
  16. hist=20
  17. restart:
  18. do i=n
  19.    qu=queued()
  20.    if qu=0 then do
  21.       r="Ready"
  22.       if rc then r=r "("rc")"
  23.       if t>0 then r=r"; T="format(t,,2)
  24.       say r
  25.       call charout ,hostname":"i">"
  26.    end
  27.    t=0
  28.    parse pull command 1 word $@ 1 $0 $1 $2 $3 $4 $5 $6 $7 $8 $9
  29.    echo=left(word,1)\=='@'
  30.    if \echo then parse var command 2 command 2 word $@ 2,
  31.       $0 $1 $2 $3 $4 $5 $6 $7 $8 $9
  32.    if qu>0&echo then say hostname":"i">"command
  33.    if alias.word\=="" then
  34.       if noargs.word then command=alias.word
  35.       else command=alias.word $@
  36.    if command="??" then do
  37.       do l=max(1,i-hist) to i-1
  38.          say right(l,4)':'line.(l//hist)
  39.       end
  40.       i=i-1
  41.       iterate i
  42.    end
  43.    if left(command,1)="!" then do
  44.       what=substr(command,2)
  45.       if \datatype(what,'W') then do
  46.          do l=i-1 to max(1,i-hist) by -1
  47.             if abbrev(line.(l//hist),what,1) then leave l
  48.          end
  49.          what=l
  50.       end
  51.       if what<i-hist|what<1|what>=i then do
  52.          say "Event not found"
  53.          i=i-1
  54.          iterate i
  55.       end
  56.       command=line.(what//hist)
  57.       say command
  58.    end  /* line 58!! */
  59.    line.(i//hist)=command
  60.    parse var command c t1 t2 1 . tt
  61.    c=translate(c)
  62.    select
  63.       when c='EXIT' then do
  64.          say 'Exiting rexx shell'
  65.          if t1="" then exit
  66.          else exit t1
  67.       end
  68.       when c='SETENV' then rc=value(t1,t2,"ENVIRONMENT")
  69.       when c='SAY' then interpret 'say' tt
  70.       when c=';' then do
  71.          call time 'R'
  72.      interpret tt
  73.      t=time('E')
  74.       end 
  75.       when c='CD' then do
  76.          rc=chdir(tt)
  77.      if rc\=0 then say tt':' ioerr(rc)
  78.       end
  79.       when c='ALIAS' then do
  80.          if t2="" then say alias.t1
  81.      else do
  82.             alias.t1=t2
  83.         if left($2,1)==';' then noargs.t1=1
  84.      end
  85.       end
  86.       otherwise
  87.          call time 'R'
  88.          command
  89.      t=time('E')
  90.    end
  91. end
  92.  
  93. halt:
  94. signal on halt
  95. say "Interrupted!"
  96. n=i
  97. if sigl>58 then n=n+1
  98. signal restart
  99.  
  100. syntax:
  101. signal on syntax
  102. say right(sigl,5) "+++" errortext(rc)
  103. n=i
  104. if sigl>58 then n=n+1
  105. signal restart
  106.