当前位置: 首页 > 文档资料 > Shell 中文文档 >

Appendix P. To Do List

优质
小牛编辑
129浏览
2023-12-01
  • A comprehensive survey of incompatibilities between Bashand the classic Bourne shell.
  • Same as above, but for the Korn shell (ksh).
  • A primer on CGI programming, using Bash.

Here's a simple CGI script to get you started.


Example P-1. Print the server environment

   1 #!/bin/bash
   2 # May have to change the location for your site.
   3 # (At the ISP's servers, Bash may not be in the usual place.)
   4 # Other places: /usr/bin or /usr/local/bin
   5 # Might even try it without any path in sha-bang.
   6
   7 # test-cgi.sh
   8 # by Michael Zick
   9 # Used with permission
  10
  11
  12 # Disable filename globbing.
  13 set -f
  14
  15 # Header tells browser what to expect.
  16 echo Content-type: text/plain
  17 echo
  18
  19 echo CGI/1.0 test script report:
  20 echo
  21
  22 echo environment settings:
  23 set
  24 echo
  25
  26 echo whereis bash?
  27 whereis bash
  28 echo
  29
  30
  31 echo who are we?
  32 echo ${BASH_VERSINFO[*]}
  33 echo
  34
  35 echo argc is $#. argv is "$*".
  36 echo
  37
  38 # CGI/1.0 expected environment variables.
  39
  40 echo SERVER_SOFTWARE = $SERVER_SOFTWARE
  41 echo SERVER_NAME = $SERVER_NAME
  42 echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE
  43 echo SERVER_PROTOCOL = $SERVER_PROTOCOL
  44 echo SERVER_PORT = $SERVER_PORT
  45 echo REQUEST_METHOD = $REQUEST_METHOD
  46 echo HTTP_ACCEPT = "$HTTP_ACCEPT"
  47 echo PATH_INFO = "$PATH_INFO"
  48 echo PATH_TRANSLATED = "$PATH_TRANSLATED"
  49 echo SCRIPT_NAME = "$SCRIPT_NAME"
  50 echo QUERY_STRING = "$QUERY_STRING"
  51 echo REMOTE_HOST = $REMOTE_HOST
  52 echo REMOTE_ADDR = $REMOTE_ADDR
  53 echo REMOTE_USER = $REMOTE_USER
  54 echo AUTH_TYPE = $AUTH_TYPE
  55 echo CONTENT_TYPE = $CONTENT_TYPE
  56 echo CONTENT_LENGTH = $CONTENT_LENGTH
  57
  58 exit 0
  59
  60 # Here document to give short instructions.
  61 :<<-'_test_CGI_'
  62
  63 1) Drop this in your http://domain.name/cgi-bin directory.
  64 2) Then, open http://domain.name/cgi-bin/test-cgi.sh.
  65
  66 _test_CGI_

Any volunteers?