Imported from ../bash-2.04.tar.gz.

This commit is contained in:
Jari Aalto 2000-03-17 21:46:59 +00:00
commit bb70624e96
387 changed files with 28522 additions and 9334 deletions

View file

@ -86,7 +86,8 @@ export PATH
trap 'echo Ouch!' 2 3
#trap '' 18 # disable Berkeley job control
ash_lk(){ echo " $1 " | fgrep " $2 " >&- 2>&-; }
#ash_lk(){ echo " $1 " | fgrep " $2 " >&- 2>&-; }
ash_lk(){ echo " $1 " | fgrep -q " $2 " >/dev/null 2>&1 ; }
ash_pr(){ echo $* | tr ' ' '\012' | pr -5 -t -w75 -l$[ ( $# + 4 ) / 5 ]; }
ash_rm(){ echo " $1 " | sed -e "s/ $2 / /" -e 's/^ //' -e 's/ $//'; }
@ -97,10 +98,13 @@ set -o emacs
cd
LIM=.limbo # $HOME/$LIM contains "destroyed" objects
mkdir $LIM >&- 2>&-
mkdir $LIM || {
echo "ash: cannot mkdir $LIM: exiting
exit 1
}
KNAP=.knapsack # $HOME/$KNAP contains objects being "carried"
if [ ! -d $KNAP ]
then mkdir $KNAP >&- 2>&-
then mkdir $KNAP >/dev/null 2>&1
if [ $? = 0 ]
then echo 'You found a discarded empty knapsack.'
else echo 'You have no knapsack to carry things in.'
@ -185,7 +189,7 @@ do room=`pwd`
set --
fi
if [ "$2" ]
then if mv $obj $2 >&- 2>&-
then if mv $obj $2 # >&- 2>&-
then echo "The $obj shimmers and turns into $2."
obs=`ash_rm "$2 $obs" "$obj"`
else echo "There is a cloud of smoke but the $obj is unchanged."
@ -214,7 +218,7 @@ do room=`pwd`
as) if [ "$2" ]
then if [ -f $2 ]
then echo "You must destroy $2 first."
else if cp $obj $2 >&- 2>&-
else if cp $obj $2 # >&- 2>&-
then echo "Poof! When the smoke clears, you see the new $2."
obs="$obs $2"
else echo 'You hear a dull thud but no clone appears.'
@ -240,7 +244,7 @@ do room=`pwd`
do if ash_lk "$kn" "$it"
then if [ -w $it ]
then echo "You must destroy $it first."
else if mv $HOME/$KNAP/$it $it >&- 2>&-
else if mv $HOME/$KNAP/$it $it # >&- 2>&-
then echo "$it: dropped."
kn=`ash_rm "$kn" "$it"`
obs=`echo $it $obs`
@ -281,7 +285,7 @@ do room=`pwd`
for it in $obj $x
do if ash_lk "$obs $hobs $exs $hexs" "$it"
then echo "Upon close inspection of the $it, you see:"
ls -ld $it 2>&-
ls -ld $it 2>/dev/null
if [ $? != 0 ]
then echo "-- when you look directly at the $it, it vanishes."
fi
@ -300,9 +304,9 @@ do room=`pwd`
case "$1" in
to) if [ "$2" ]
then shift
if PATH=$OPATH $* <$obj 2>&-
if PATH=$OPATH $* <$obj 2>/dev/null
then echo "The $1 monster devours your $obj."
if rm -f $obj >&- 2>&-
if rm -f $obj # >&- 2>&-
then obs=`ash_rm "$obs" "$obj"`
else echo 'But he spits it back up.'
fi
@ -331,7 +335,7 @@ do room=`pwd`
do if ash_lk "$obs $hobs" "$it"
then if ash_lk "$kn" "$it"
then echo 'You already have one.'
else if mv $it $HOME/$KNAP/$it >&- 2>&-
else if mv $it $HOME/$KNAP/$it # >&- 2>&-
then echo "$it: taken."
kn="$it $kn"
obs=`ash_rm "$obs" "$it"`
@ -367,7 +371,7 @@ do room=`pwd`
fi
for it in $obj $x
do if ash_lk "$obs $hobs" "$it"
then if mv $it $HOME/$LIM <&- >&- 2>&-
then if mv $it $HOME/$LIM # <&- >&- 2>&-
then if [ $verb = kill ]
then echo "The $it cannot defend himself; he dies."
else echo "You have destroyed the $it; it vanishes."
@ -457,7 +461,7 @@ do room=`pwd`
then for it in $obj $x
do if ash_lk "$obs $hobs" "$it"
then echo "The $it is already alive and well."
else if mv $HOME/$LIM/$it $it <&- >&- 2>&-
else if mv $HOME/$LIM/$it $it # <&- >&- 2>&-
then echo "The $it staggers to his feet."
obs=`echo $it $obs`
else echo "There are sparks but no $it appears."
@ -474,11 +478,11 @@ do room=`pwd`
case "$1" in
from) if [ "$2" ]
then shift
if PATH=$OPATH $* >$obj 2>&-
if PATH=$OPATH $* >$obj 2>/dev/null
then echo "The $1 monster drops the $obj."
obs=`echo $obj $obs`
else echo "The $1 monster runs away as you approach."
rm -f $obj >&- 2>&-
rm -f $obj # >&- 2>&-
fi
else echo 'From what?'
fi

24
examples/scripts/center Normal file
View file

@ -0,0 +1,24 @@
#! /bin/bash
#
# center - center a group of lines
#
# tabs in the lines might cause this to look a little bit off
#
#
width=${COLUMNS:-80}
if [[ $# == 0 ]]
then
set -- /dev/stdin
fi
for file
do
while read -r
do
printf "%*s\n" $(( (width+${#REPLY})/2 )) "$REPLY"
done < $file
done
exit 0

View file

@ -0,0 +1,185 @@
#! /bin/bash
#
#From: kaz@cafe.net (Kaz Kylheku)
#Newsgroups: comp.unix.shell
#Subject: Funky little bash script
#Message-ID: <6mspb9$ft2@espresso.cafe.net>
#Date: Thu, 25 Jun 1998 06:11:39 GMT
#Here is something I wrote a few years ago when I was bored one day.
#Warning: this contains control characters.
# Line input routine for GNU Bourne-Again Shell
# plus terminal-control primitives.
#
# by Kaz Kylheku
# June 1996, Vancouver, Canada
#
# Function to disable canonical input processing.
# Terminal modes are saved into variable "savetty"
#
#
function raw
{
savetty=$(stty -g)
stty -icanon -isig -echo -echok -echonl inlcr
}
#
# Function to restore terminal settings from savetty variable
#
function restore
{
stty $savetty
}
#
# Set terminal MIN and TIME values.
# If the input argument is a zero, set up terminal to wait for
# a keystroke indefinitely. If the argument is non-zero, set up
# an absolute timeout of that many tenths of a second. The inter-keystroke
# timer facility of the terminal driver is not exploited.
#
function settimeout
# $1 = tenths of a second
{
if [ "$1" = "0" ] ; then
min=1
timeout=0
else
min=0
timeout="$1"
fi
stty min $min time $timeout
unset min timeout
}
#
# Input a single key using 'dd' and echo it to standard output.
# Launching an external program to get a single keystroke is a bit
# of a pig, but it's the best you can do! Maybe we could convince the
# GNU guys to make 'dd' a bash builtin.
#
function getkey
{
eval $1="\"\$(dd bs=1 count=1 2> /dev/null)\""
}
#
# Input a line of text gracefully.
# The first argument is the name of a variable where the input line is
# to be stored. If this variable is not empty, its contents are printed
# and treated as though the user had entered them.
# The second argument gives the maximum length of the input line; if it
# is zero, the input is unlimited (bad idea).
# ^W is used to delete words
# ^R redraws the line at any time by backspacing over it and reprinting it
# ^U backspaces to the beginning
# ^H or ^? (backspace or del) delete a single character
# ^M (enter) terminates the input
# all other control keys are ignored and cause a beep when pressed
#
#
function getline
{
settimeout 0 # No keystroke timeout.
save_IFS="$IFS" # Save word delimiter and set it to
IFS="" # to null so ${#line} works correctly.
eval line=\${$1} # Fetch line contents
echo -n "$line" # and print the existing line.
while [ 1 ] ; do
getkey key # fetch a single keystroke
case "$key" in
 |  ) # BS or DEL
if [ ${#line} != 0 ] ; then # if line not empty
echo -n " " # print destructive BS
line="${line%%?}" # chop last character
else # else if line empty
echo -n  # beep the terminal
fi
;;
 ) # kill to line beg
while [ ${#line} != 0 ] ; do # while line not empty
echo -n " " # print BS, space, BS
line="${line%?}" # shorten line by 1
done
;;
 ) # redraw line
linesave="$line" # save the contents
while [ ${#line} != 0 ] ; do # kill to line beg
echo -n " "
line="${line%?}"
done
echo -n "$linesave" # reprint, restore
line="$linesave"
unset linesave # forget temp var
;;
 )
while [ "${line% }" != "$line" -a ${#line} != 0 ] ; do
echo -n " "
line="${line%?}"
done
while [ "${line% }" = "$line" -a ${#line} != 0 ] ; do
echo -n " "
line="${line%?}"
done
;;
 |  |  |  |  |  |  |  |  | | | )
echo -n  # ignore various control characters
;; # with an annoying beep
 |  |  |  |  |  |  |  |  |  |  |  |  )
echo -n 
;;
' ' |  |  |  |  |  )
echo -n 
;;
'' ) # Break out of loop on carriage return.
echo # Send a newline to the terminal.
break # (Also triggered by NUL char!).
;;
* ) # Append character to the end of the line.
# If length is restricted, and the line is too
# long, then beep...
if [ "$2" != 0 -a $(( ${#line} >= $2 )) = 1 ] ; then
echo -n 
else # Otherwise add
line="$line$key" # the character.
echo -n "$key" # And echo it.
fi
;;
esac
done
eval $1=\"\$line\"
IFS="$save_IFS"
unset line save_IFS
}
# uncomment the lines below to create a standalone test program
#
echo "Line input demo for the GNU Bourne-Again Shell."
echo "Hacked by Kaz Kylheku"
echo
echo "Use ^H/Backspace/Del to erase, ^W to kill words, ^U to kill the"
echo "whole line of input, ^R to redraw the line."
echo "Pass an argument to this program to prime the buffer contents"
raw
echo -n "go: "
if [ ${#1} != 0 ] ; then
LINE=$1
fi
getline LINE 50
restore
echo "<$LINE>"

100
examples/scripts/vtree3a Normal file
View file

@ -0,0 +1,100 @@
#!/bin/bash
#
# Name: dirtree
# Programmer:
# Hemant T. Shah
# Life Insurance Data Processing
# July 12 1994
#
# Description:
# Print directory tree structure as follows:
# |___Mail
# |___scheduler
# |___cics_scripts
# |___tar_msdos
# |___awk
# |___attributes
# |___tmp
# |___News
# |___dosscsi
# |___FAQ_xterminal
# |___shell_history.Z
# |___FAQ_AIX
# |___aix_ftp_site
# |___hp_software
# |___dnload
# |___telnet.h
# |___msdos
# |___tnetd.tar.Z
# |___aix
# |___hp
# |___xkey.c
#
# Conversion to bash v2 syntax done by Chet Ramey
# - removed command substitutions calling `basename'
#
ProgramName=${0##*/}
Path="."
ShowAll=1
ShowDir=0
ExpandDirectory()
{
local object # Local variable
cd "$1"
for object in $PWD/.??* $PWD/*
do
if [ -d $object ]; # It is a directory
then
echo "${indent}|___${object##*/}/"
indent="${indent}! " # Add to indentation
if [ -x $object ];
then
ExpandDirectory $object
fi
indent=${indent%????} # Remove from indentation
elif [ -e $object ]; then
if (( ShowAll == 1 ));
then
echo "${indent}|___${object##*/}"
fi
fi
done
}
usage()
{
echo -e "Usage: $ProgramName [-h] [-f] [-d] [path] "
echo -e "\t-h ... display this help message."
echo -e "\t-f path ... shows all files and directories below path (default)."
echo -e "\t-d path ... shows all directories only below path."
}
while getopts "fd" opt
do
case $opt in
f) ShowAll=1 ;;
#d) ShowDir=1 ;;
d) ShowAll=0 ;;
*) usage ; exit 2;;
esac
done
shift $(( $OPTIND - 1 ))
Path=${1:-.}
if [ ! -d "$Path" ]; then
echo "$0: error: specified path is not a directory." >&2
exit 1
fi
echo "!$Path/"
ExpandDirectory $Path

230
examples/scripts/websrv.sh Normal file
View file

@ -0,0 +1,230 @@
#!/bin/sh
#for instructions or updates go to:
#<A HREF="http://math.ucr.edu:8889/">This script's home page</A>
#email me questions or comments at:
#<A HREF="mailto:insom@math.ucr.edu">insom@math.ucr.edu</A>
#copyright chris ulrich; This software may be used or modified
#in any way so long as this notice remains intact.
#
# WWW server in sh
# Author: Chris Ulrich <chris@tinker.ucr.edu>
#
INDEX=index.html
date=`date`
DOCHOME=/home/insom/web-docs
BINHOME=/home/insom/web-bin
LOGHOME=/home/insom/web-logs
LOGFILE=$LOGHOME/access_log
#verbose=:
verbose=echo
exec 2>> $LOGHOME/error_log
hheader() {
echo "HTTP/1.0 200 OK
Server: WebSH/2.00
Connection: close
Date: $date"
}
header() {
echo "Content-type: $1
"
}
no_url() {
header "text/plain"
echo "No such url $1"
}
send() {
#case "$#" in 2) ;; *) echo eep! | mailx insom@math.ucr.edu ; exit 3 ;; esac
if test -f "$DOCHOME/$2"
then
header "$1"
cat "$DOCHOME/$2"
else
no_url "$2"
fi
}
LsToHTML() {
if test -f "$DOCHOME/$url/.title"
then
header "text/html; charset=US-ASCII"
echo "<pre>"
cat "$DOCHOME/$url/.title"
echo "</pre>"
elif test -f "$DOCHOME/$url/.title.html"
then
header "text/html; charset=US-ASCII"
cat "$DOCHOME/$url/.title.html"
else
header "text/html; charset=US-ASCII"
fi
case "$url" in
/) ;;
*) url="$url/"
esac
while read link
do
case $link in
*.cgi) ;;
*)
echo "<A HREF=\"$url$link\">$link</A> <BR>"
;;
esac
done
}
read method data
$verbose "
$date access from ${TCPREMOTEINFO:=NO-IDENT}@${TCPREMOTEHOST:=$TCPREMOTEIP}
on local machine $TCPLOCALHOST
$method $data " >> $LOGFILE
for hopeurl in $data
do
url="${url}${url:+ }$second"
second="$hopeurl"
done
case "$second" in
*[1-9].*)
read inheader
while
case "$inheader" in
?|'') false
;;
*)
read inheader
;;
esac
do
:
done
hheader
;;
esac
case "$url" in
*..*)
no_url "$url"
exit 1
;;
*.txt|*.[ch])
send "text/plain; charset=US-ASCII" "$url"
;;
*.html)
send "text/html; charset=US-ASCII" "$url"
;;
*.cgi)
if test -x "$DOCHOME/$url"
then
read message
echo "$message" | "$DOCHOME/$url"
else
no_url "$url"
fi
;;
*".cgi?"*)
oIFS="$IFS"
echo "$url" | {
IFS='?' read url QUERY_STRING
if test -x "$DOCHOME/$url"
then
IFS="$oIFS"
export QUERY_STRING
"$DOCHOME/$url"
else
no_url "$url"
fi
}
;;
*.[Gg][Ii][Ff])
send "image/gif" "$url"
;;
*.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg])
send "image/jpeg" "$url"
;;
*.tbl)
header "text/html; charset=US-ASCII"
echo "<pre>"
test -f "$DOCHOME/$url" &&
tbl < "$DOCHOME/$url" | nroff ||
no_url "$url"
echo "</pre>"
;;
*.nroff)
header "text/html; charset=US-ASCII"
echo "<pre>"
test -f "$DOCHOME/$url" &&
nroff < "$DOCHOME/$url" ||
no_url "$url"
echo "</pre>"
;;
*mp[23])
if test -f "$DOCHOME/$url"
then
header "application/mpstream"
echo "+$TCPLOCALIP:${MPSERVPORT:=9001}/$url"
else
no_url "$url"
fi
;;
*.[0-9]|*.[0-9][a-z])
header "text/html; charset=US-ASCII"
echo "<pre>"
if test -f "$DOCHOME/$url"
then
#nroff -man "$DOCHOME/$url" | $BINHOME/man2html
echo "perl at the moment is broken, so man2html doesn't work. Sorry."
echo "</pre>"
else
no_url "$url"
fi
;;
*.???|*.??)
send "unknown/data" "$url"
;;
*/)
if test -d "$DOCHOME/$url"
then
ls "$DOCHOME/$url" | LsToHTML
fi
;;
*)
if test -f "$DOCHOME/$url"
then
read filetype < "$DOCHOME/$url"
case "$filetype" in
\#!/*/*|\#!?/*/*)
header "text/plain; charset=US-ASCII"
cat "$DOCHOME/$url"
;;
'<!*>')
header "text/html; charset=US-ASCII"
cat "$DOCHOME/$url"
;;
*)
header "text/html; charset=US-ASCII"
echo "<pre>"
cat "$DOCHOME/$url"
echo "</pre>"
;;
esac
elif test -f "$DOCHOME/$url/$INDEX"
then
header "text/html; charset=US-ASCII"
cat "$DOCHOME/$url/$INDEX"
elif test -d "$DOCHOME/$url"
then
ls "$DOCHOME/$url" | LsToHTML
else
no_url "$url"
fi
;;
esac

27
examples/scripts/xterm_title Executable file
View file

@ -0,0 +1,27 @@
#! /bin/bash
#
# xterm_title - print the contents of the xterm title bar
#
# Derived from http://www.clark.net/pub/dickey/xterm/xterm.faq.html#how2_title
#
P=${0##*/}
[ -z "$DISPLAY" ] && {
echo "${P}: not running X" >&2
exit 1
}
if [ -z "$TERM" ] || [ "$TERM" != "xterm" ]; then
echo "${P}: not running in an xterm" >&2
exit 1
fi
exec </dev/tty
old=$(stty -g)
stty raw -echo min 0 time ${1-10}
echo -e "\033[21t\c" > /dev/tty
IFS='' read -r a
stty $old
b=${a#???}
echo "${b%??}"
exit 0