prep for bash-4.3 release

This commit is contained in:
Chet Ramey 2014-02-25 20:36:50 -05:00
commit 4539d736f1
105 changed files with 0 additions and 13608 deletions

View file

@ -1,553 +0,0 @@
#!/bin/bash
# ash -- "Adventure shell"
# last edit: 86/04/21 D A Gwyn
# SCCS ID: @(#)ash.sh 1.4
OPATH=$PATH
ask()
{
echo -n "$@" '[y/n] '
read ans
case "$ans" in
y*|Y*)
return 0
;;
*)
return 1
;;
esac
}
CAT=${PAGER:-more}
ash_inst()
{
cat <<- EOF
Instructions for the Adventure shell
Welcome to the Adventure shell! In this exploration of the UNIX file
system, I will act as your eyes and hands. As you move around, I will
describe whatever is visible and will carry out your commands. The
general form of a command is
Verb Object Extra_stuff.
Most commands pay no attention to the "Extra_stuff", and many do not
need an "Object". A typical command is
get all
which picks up all files in the current "room" (directory). You can
find out what you are carrying by typing the command
inventory
The command "help" results in a full description of all commands that I
understand. To quit the Adventure shell, type
quit
There are UNIX monsters lurking in the background. These are also
known as "commands with arguments".
Good luck!
EOF
}
ash_help()
{
echo "I understand the following commands (synonyms in parentheses):"
echo ""
echo "change OBJECT to NEW_NAME changes the name of the object"
echo "clone OBJECT as NEW_NAME duplicates the object"
echo "drop OBJECTS leaves the objects in the room"
echo "enter (go) PASSAGE takes the labeled passage"
echo "examine OBJECTS describes the objects in detail"
echo "feed OBJECT to MONSTER stuffs the object into a UNIX monster"
echo "get (take) OBJECTS picks up the specified objects"
echo "gripe (bug) report a problem with the Adventure shell"
echo "help prints this summary"
echo "inventory (i) tells what you are carrying"
echo "kill (destroy) OBJECTS destroys the objects"
echo "look (l) describes the room, including hidden objects"
echo "open (read) OBJECT shows the contents of an object"
echo "quit (exit) leaves the Adventure shell"
echo "resurrect OBJECTS attempts to restore dead objects"
echo "steal OBJECT from MONSTER obtains the object from a UNIX monster"
echo "throw OBJECT at daemon feeds the object to the printer daemon"
echo "up takes the overhead passage"
echo "wake MONSTER awakens a UNIX monster"
echo "where (w) tells you where you are"
echo "xyzzy moves you to your home"
}
MAINT=chet@ins.cwru.edu
PATH=/usr/ucb:/bin:/usr/bin:/usr/local/bin:.
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 -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/ $//'; }
# enable history, bang history expansion, and emacs editing
set -o history
set -o histexpand
set -o emacs
cd
LIM=.limbo # $HOME/$LIM contains "destroyed" objects
mkdir $LIM || {
echo "ash: cannot mkdir $LIM: exiting"
exit 1
}
KNAP=.knapsack # $HOME/$KNAP contains objects being "carried"
if [ ! -d $KNAP ]
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.'
exit 1
fi
else echo 'One moment while I peek in your old knapsack...'
fi
kn=`echo \`ls -a $KNAP | sed -e '/^\.$/d' -e '/^\.\.$/d'\``
if ask 'Welcome to the Adventure shell! Do you need instructions?'
then
ash_inst
echo -n 'Type a newline to continue: '
read
fi
wiz=false
cha=false
prev=$LIM
while :
do room=`pwd`
if [ $room != $prev ]
then if [ $room = $HOME ]
then echo 'You are in your own home.'
else echo "You have entered $room."
fi
exs=
obs=
hexs=
hobs=
f=false
for i in `ls -a`
do case $i in
.|..) ;;
.*) if [ -f $i ]
then hobs="$hobs $i"
elif [ -d $i ]
then hexs="$hexs $i"
else f=true
fi
;;
*) if [ -f $i ]
then obs="$obs $i"
elif [ -d $i ]
then exs="$exs $i"
else f=true
fi
;;
esac
done
if [ "$obs" ]
then echo 'This room contains:'
ash_pr $obs
else echo 'The room looks empty.'
fi
if [ "$exs" ]
then echo 'There are exits labeled:'
ash_pr $exs
echo 'as well as a passage overhead.'
else echo 'There is a passage overhead.'
fi
if sh -c $f
then echo 'There are shadowy figures in the corner.'
fi
prev=$room
fi
read -e -p '-advsh> ' verb obj x # prompt is '-advsh> '
if [ $? != 0 ]
then verb=quit # EOF
fi
case $verb in
change) if [ "$obj" ]
then if ash_lk "$obs $hobs" "$obj"
then set -- $x
case "$1" in
to) if [ "$2" ]
then if [ -f $2 ]
then echo "You must destroy $2 first."
set --
fi
if [ "$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."
fi
fi
else echo 'To what?'
fi
;;
*) echo "Change $obj to what?"
;;
esac
else if ash_lk "$kn" "$obj"
then echo 'You must drop it first.'
else echo "I see no $obj here."
fi
fi
else echo 'Change what?'
fi
;;
clone) if [ "$obj" ]
then if ash_lk "$obs $hobs" "$obj"
then if [ ! -r $obj ]
then echo "The $obj does not wish to be cloned."
else set -- $x
case "$1" in
as) if [ "$2" ]
then if [ -f $2 ]
then echo "You must destroy $2 first."
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.'
fi
fi
else echo 'As what?'
fi
;;
*) echo "Clone $obj as what?"
;;
esac
fi
else if ash_lk "$kn" "$obj"
then echo 'You must drop it first.'
else echo "I see no $obj here."
fi
fi
else echo 'Clone what?'
fi
;;
drop) if [ "$obj" ]
then for it in $obj $x
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>&-
then echo "$it: dropped."
kn=`ash_rm "$kn" "$it"`
obs=`echo $it $obs`
else echo "The $it is caught in your knapsack."
fi
fi
else echo "You're not carrying the $it!"
fi
done
else echo 'Drop what?'
fi
;;
enter|go) if [ "$obj" ]
then if [ $obj != up ]
then if ash_lk "$exs $hexs" "$obj"
then if [ -x $obj ]
then if cd $obj
then echo 'You squeeze through the passage.'
else echo "You can't go that direction."
fi
else echo 'An invisible force blocks your way.'
fi
else echo 'I see no such passage.'
fi
else if cd ..
then echo 'You struggle upwards.'
else echo "You can't reach that high."
fi
fi
else echo 'Which passage?'
fi
;;
examine) if [ "$obj" ]
then if [ $obj = all ]
then $obj=`echo $obs $exs`
x=
fi
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>/dev/null
if [ $? != 0 ]
then echo "-- when you look directly at the $it, it vanishes."
fi
else if ash_lk "$kn" "$it"
then echo 'You must drop it first.'
else echo "I see no $it here."
fi
fi
done
else echo 'Examine what?'
fi
;;
feed) if [ "$obj" ]
then if ash_lk "$obs $hobs" "$obj"
then set -- $x
case "$1" in
to) if [ "$2" ]
then shift
if PATH=$OPATH $* <$obj 2>/dev/null
then echo "The $1 monster devours your $obj."
if rm -f $obj # >&- 2>&-
then obs=`ash_rm "$obs" "$obj"`
else echo 'But he spits it back up.'
fi
else echo "The $1 monster holds his nose in disdain."
fi
else echo 'To what?'
fi
;;
*) echo "Feed $obj to what?"
;;
esac
else if ash_lk "$kn" "$obj"
then echo 'You must drop it first.'
else echo "I see no $obj here."
fi
fi
else echo 'Feed what?'
fi
;;
get|take) if [ "$obj" ]
then if [ $obj = all ]
then obj="$obs"
x=
fi
for it in $obj $x
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>&-
then echo "$it: taken."
kn="$it $kn"
obs=`ash_rm "$obs" "$it"`
else echo "The $it is too heavy."
fi
fi
else echo "I see no $it here."
fi
done
else echo 'Get what?'
fi
;;
gripe|bug) echo 'Please describe the problem and your situation at the time it failed.\nEnd the bug report with a line containing just a Ctrl-D.'
cat | mail $MAINT -s 'ash bug'
echo 'Thank you!'
;;
help) ash_help
;;
inventory|i) if [ "$kn" ]
then echo 'Your knapsack contains:'
ash_pr $kn
else echo 'You are poverty-stricken.'
fi
;;
kill|destroy) if [ "$obj" ]
then if [ $obj = all ]
then x=
if ask "Do you really want to attempt to $verb them all?"
then obj=`echo $obs`
else echo 'Chicken!'
obj=
fi
fi
for it in $obj $x
do if ash_lk "$obs $hobs" "$it"
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."
fi
obs=`ash_rm "$obs" "$it"`
else if [ $verb = kill ]
then echo "Your feeble blows are no match for the $it."
else echo "The $it is indestructible."
fi
fi
else if ash_lk "$kn" "$it"
then echo "You must drop the $it first."
found=false
else echo "I see no $it here."
fi
fi
done
else echo 'Kill what?'
fi
;;
look|l) obs=`echo $obs $hobs`
hobs=
if [ "$obs" ]
then echo 'The room contains:'
ash_pr $obs
else echo 'The room is empty.'
fi
exs=`echo $exs $hexs`
hexs=
if [ "$exs" ]
then echo 'There are exits plainly labeled:'
ash_pr $exs
echo 'and a passage directly overhead.'
else echo 'The only exit is directly overhead.'
fi
;;
magic) if [ "$obj" = mode ]
then if sh -c $cha
then echo 'You had your chance and you blew it.'
else if ask 'Are you a wizard?'
then echo -n 'Prove it! Say the magic word: '
read obj
if [ "$obj" = armadillo ]
then echo 'Yes, master!!'
wiz=true
else echo "Homie says: I don't think so"
cha=true
fi
else echo "I didn't think so."
fi
fi
else echo 'Nice try.'
fi
;;
open|read) if [ "$obj" ]
then if ash_lk "$obs $hobs" "$obj"
then if [ -r $obj ]
then if [ -s $obj ]
then echo "Opening the $obj reveals:"
$CAT < $obj
if [ $? != 0 ]
then echo '-- oops, you lost the contents!'
fi
else echo "There is nothing inside the $obj."
fi
else echo "You do not have the proper tools to open the $obj."
fi
else if ash_lk "$kn" "$obj"
then echo 'You must drop it first.'
found=false
else echo "I see no $obj here."
fi
fi
else echo 'Open what?'
fi
;;
quit|exit) if ask 'Do you really want to quit now?'
then if [ "$kn" ]
then echo 'The contents of your knapsack will still be there next time.'
fi
rm -rf $HOME/$LIM
echo 'See you later!'
exit 0
fi
;;
resurrect) if [ "$obj" ]
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>&-
then echo "The $it staggers to his feet."
obs=`echo $it $obs`
else echo "There are sparks but no $it appears."
fi
fi
done
else echo 'Resurrect what?'
fi
;;
steal) if [ "$obj" ]
then if ash_lk "$obs $hobs" "$obj"
then echo 'There is already one here.'
else set -- $x
case "$1" in
from) if [ "$2" ]
then shift
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>&-
fi
else echo 'From what?'
fi
;;
*) echo "Steal $obj from what?"
;;
esac
fi
else echo 'Steal what?'
fi
;;
throw) if [ "$obj" ]
then if ash_lk "$obs $hobs" "$obj"
then set -- $x
case "$1" in
at) case "$2" in
daemon) if sh -c "lpr -r $obj"
then echo "The daemon catches the $obj, turns it into paper,\nand leaves it in the basket."
obs=`ash_rm "$obs" "$obj"`
else echo "The daemon is nowhere to be found."
fi
;;
*) echo 'At what?'
;;
esac
;;
*) echo "Throw $obj at what?"
;;
esac
else if ash_lk "$kn" "$obj"
then echo 'It is in your knapsack.'
found=false
else echo "I see no $obj here."
fi
fi
else echo 'Throw what?'
fi
;;
u|up) if cd ..
then echo 'You pull yourself up a level.'
else echo "You can't reach that high."
fi
;;
wake) if [ "$obj" ]
then echo "You awaken the $obj monster:"
PATH=$OPATH $obj $x
echo 'The monster slithers back into the darkness.'
else echo 'Wake what?'
fi
;;
w|where) echo "You are in $room."
;;
xyzzy) if cd
then echo 'A strange feeling comes over you.'
else echo 'Your spell fizzles out.'
fi
;;
*) if [ "$verb" ]
then if sh -c $wiz
then PATH=$OPATH $verb $obj $x
else echo "I don't know how to \"$verb\"."
echo 'Type "help" for assistance.'
fi
else echo 'Say something!'
fi
;;
esac
done

View file

@ -1,67 +0,0 @@
#From: "dennis" <dennis@netstrata.com>
#To: <bash-maintainers@gnu.org>
#Subject: New example script: bash-hexdump
#Date: Mon, 4 Jan 2010 22:48:19 -0700
#Message-ID: <6dbec42d$64fcdbd2$4a32cf2d$@com>
#I've written a script that functions like "hexdump -C" or "hd". If you'd
#like to include it in a future distribution of example Bash scripts, I have
#included it here:
#!/bin/bash
# bash-hexdump# pure Bash, no externals
# by Dennis Williamson - 2010-01-04
# in response to
http://stackoverflow.com/questions/2003803/show-hexadecimal-numbers-of-a-file
# usage: bash-hexdump file
saveIFS="$IFS"
IFS="" # disables interpretation of \t, \n and space
saveLANG="$LANG"
LANG=C # allows characters > 0x7F
bytecount=0
valcount=0
printf "%08x " $bytecount
while read -d '' -r -n 1 char # -d '' allows newlines, -r allows \
do
((bytecount++))
# for information about the apostrophe in this printf command, see
# http://www.opengroup.org/onlinepubs/009695399/utilities/printf.html
printf -v val "%02x" "'$char"
echo -n "$val "
((valcount++))
if [[ "$val" < 20 || "$val" > 7e ]]
then
string+="." # show unprintable characters as a dot
else
string+=$char
fi
if (( bytecount % 8 == 0 )) # add a space down the middle
then
echo -n " "
fi
if (( bytecount % 16 == 0 )) # print 16 values per line
then
echo "|$string|"
string=''
valcount=0
printf "%08x " $bytecount
fi
done < "$1"
if [[ "$string" != "" ]] # if the last line wasn't full, pad it out
then
length=${#string}
if (( length > 7 ))
then
((length--))
fi
(( length += (16 - valcount) * 3 + 4))
printf "%${length}s\n" "|$string|"
printf "%08x " $bytecount
fi
echo
LANG="$saveLANG";
IFS="$saveIFS"
exit 0

File diff suppressed because it is too large Load diff

View file

@ -1,476 +0,0 @@
#!/bin/sh
# this is a line editor using only /bin/sh, /bin/dd and /bin/rm
# /bin/rm is not really required, but it is nice to clean up temporary files
PATH=
dd=/bin/dd
rm=/bin/rm
# temporary files we might need
tmp=/tmp/silly.$$
ed=/tmp/ed.$$
trap "$rm -f $tmp $tmp.1 $tmp.2 $tmp.3 $tmp.4 $tmp.5 $tmp.6 $ed.a $ed.b $ed.c; exit" 0 1 2 3
# from now on, no more rm - the above trap is enough
unset rm
# we do interesting things with IFS, but better save it...
saveIFS="$IFS"
# in case "echo" is not a shell builtin...
Echo () {
case "$1" in
-n) shift
$dd of=$tmp 2>/dev/null <<EOF
$@
EOF
IFS="+"
set `$dd if=$tmp bs=1 of=/dev/null skip=1 2>&1`
IFS="$saveIFS"
$dd if=$tmp bs=1 count=$1 2>/dev/null
;;
*) $dd 2>/dev/null <<EOF
$@
EOF
;;
esac
}
# this is used to generate garbage files
true () {
return 0
}
false () {
return 1
}
zero () {
( trap 'go=false' 13
go=true
while $go
do
$dd "if=$0"
case "$?" in
0) ;;
*) go=false ;;
esac
done
) 2>/dev/null
}
# arithmetic using dd!
# add variable n1 n2 n3...
# assigns n1+n2+n3+... to variable
add () {
result="$1"
shift
$dd if=/dev/null of=$tmp bs=1 2>/dev/null
for n in "$@"
do
case "$n" in
0) ;;
*) zero | $dd of=$tmp.1 bs=1 "count=$n" 2>/dev/null
( $dd if=$tmp; $dd if=$tmp.1 ) 2>/dev/null | $dd of=$tmp.2 2>/dev/null
$dd if=$tmp.2 of=$tmp 2>/dev/null
;;
esac
done
IFS="+"
set `$dd if=$tmp bs=1 of=/dev/null 2>&1`
IFS="$saveIFS"
eval $result='$1'
}
# subtract variable n1 n2
# subtracts n2 from n1, assigns result to variable
subtract () {
result="$1"
zero | $dd of=$tmp bs=1 "count=$2" 2>/dev/null
IFS="+"
set `$dd if=$tmp bs=1 of=/dev/null "skip=$3" 2>&1`
IFS="$saveIFS"
case "$1" in
dd*) set 0 ;;
esac
eval $result='$1'
}
# multiply variable n1 n2
# variable = n1 * n2
multiply () {
result="$1"
zero | $dd "bs=$2" of=$tmp "count=$3" 2>/dev/null
IFS="+"
set `$dd if=$tmp bs=1 of=/dev/null 2>&1`
IFS="$saveIFS"
eval $result='$1'
}
# divide variable n1 n2
# variable = int( n1 / n2 )
divide () {
result="$1"
zero | $dd bs=1 of=$tmp "count=$2" 2>/dev/null
IFS="+"
set `$dd if=$tmp "bs=$3" of=/dev/null 2>&1`
IFS="$saveIFS"
eval $result='$1'
}
# compare variable n1 n2 sets variable to lt if n1<n2, gt if n1>n2, eq if n1==n2
compare () {
res="$1"
n1="$2"
n2="$3"
subtract somename "$n1" "$n2"
case "$somename" in
0) ;;
*) eval $res=gt; return;
esac
subtract somename "$n2" "$n1"
case "$somename" in
0) ;;
*) eval $res=lt; return;
esac
eval $res=eq
}
# lt n1 n2 returns true if n1 < n2
lt () {
n1="$1"
n2="$2"
subtract somename "$n2" "$n1"
case "$somename" in
0) return 1 ;;
esac
return 0
}
# le n1 n2 returns true if n1 <= n2
le () {
n1="$1"
n2="$2"
subtract somename "$n1" "$n2"
case "$somename" in
0) return 0 ;;
esac
return 1
}
# gt n1 n2 returns true if n1 > n2
gt () {
n1="$1"
n2="$2"
subtract somename "$n1" "$n2"
case "$somename" in
0) return 1 ;;
esac
return 0
}
# ge n1 n2 returns true if n1 >= n2
ge () {
n1="$1"
n2="$2"
subtract somename "$n2" "$n1"
case "$somename" in
0) return 0 ;;
esac
return 1
}
# useful functions for the line editor
# open a file - copy it to the buffers
open () {
file="$1"
set `$dd "if=$file" of=/dev/null 2>&1`
case "$1" in
dd*) return 1
esac
# copy the first line to $ed.c
go=true
len=0
while $go
do
case "`$dd "if=$file" bs=1 skip=$len count=1 2>/dev/null`" in
?*) go=true ;;
*) go=false ;;
esac
add len 1 $len
done
# now $len is the length of the first line (including newline)
$dd "if=$file" bs=1 count=$len of=$ed.c 2>/dev/null
$dd "if=$file" bs=1 skip=$len of=$ed.b 2>/dev/null
$dd if=/dev/null of=$ed.a 2>/dev/null
lineno=1
}
# save a file - copy the buffers to the file
save () {
# make a backup copy of the original
$dd "if=$1" "of=$1.bak" 2>/dev/null
# and save
( $dd if=$ed.a; $dd if=$ed.c; $dd if=$ed.b ) > "$1" 2>/dev/null
}
# replace n1 n2 bla replaces n2 chars of current line, starting n1-th
replace () {
$dd if=$ed.c of=$tmp.1 bs=1 "count=$1" 2>/dev/null
( $dd if=$ed.c "skip=$1" bs=1 | $dd of=$tmp.2 bs=1 "skip=$2" ) 2>/dev/null
shift
shift
( $dd if=$tmp.1; Echo -n "$@"; $dd if=$tmp.2 ) > $tmp.3 2>/dev/null
$dd if=$tmp.3 of=$ed.c 2>/dev/null
}
# rstring n s bla
# replace the n-th occurence of s with bla
rstring () {
n="$1"
shift;
# first we have to find it - this is fun!
# we have $tmp.4 => text before string, $tmp.5 => text after
$dd if=/dev/null of=$tmp.4 2>/dev/null
$dd if=$ed.c of=$tmp.5 2>/dev/null
string="$1"
shift
$dd of=$tmp.6 2>/dev/null <<EOF
$@
EOF
while :
do
case "`$dd if=$tmp.5 2>/dev/null`" in
$string*)
if lt $n 2
then
# now we want to replace the string
Echo -n "$@" > $tmp.2
Echo -n "$string" > $tmp.1
IFS="+"
set `$dd bs=1 if=$tmp.1 of=/dev/null 2>&1`
IFS="$saveIFS"
slen=$1
IFS="+"
( $dd if=$tmp.4; $dd if=$tmp.2; $dd if=$tmp.5 bs=1 skip=$slen ) \
2>/dev/null > $tmp
$dd if=$tmp of=$ed.c 2>/dev/null
return 0
else
subtract n $n 1
( $dd if=$tmp.4; $dd if=$tmp.5 bs=1 count=1 ) > $tmp 2>/dev/null
$dd if=$tmp of=$tmp.4 2>/dev/null
# and remove it from $tmp.5
$dd if=$tmp.5 of=$tmp bs=1 skip=1 2>/dev/null
$dd if=$tmp of=$tmp.5 2>/dev/null
fi
;;
?*) # add one more byte...
( $dd if=$tmp.4; $dd if=$tmp.5 bs=1 count=1 ) > $tmp 2>/dev/null
$dd if=$tmp of=$tmp.4 2>/dev/null
# and remove it from $tmp.5
$dd if=$tmp.5 of=$tmp bs=1 skip=1 2>/dev/null
$dd if=$tmp of=$tmp.5 2>/dev/null
;;
*) # not found
return 1
;;
esac
done
}
# skip to next line
next () {
add l $lineno 1
( $dd if=$ed.a; $dd if=$ed.c ) 2>/dev/null > $tmp.3
$dd if=$ed.b of=$tmp.4 2>/dev/null
open $tmp.4
$dd if=$tmp.3 of=$ed.a 2>/dev/null
lineno=$l
}
# delete current line
delete () {
l=$lineno
$dd if=$ed.a 2>/dev/null > $tmp.1
$dd if=$ed.b of=$tmp.2 2>/dev/null
open $tmp.2
$dd if=$tmp.1 of=$ed.a 2>/dev/null
lineno=$l
}
# insert before current line (without changing current)
insert () {
( $dd if=$ed.a; Echo "$@" ) 2>/dev/null > $tmp.1
$dd if=$tmp.1 of=$ed.a 2>/dev/null
add lineno $lineno 1
}
# previous line
prev () {
case "$lineno" in
1) ;;
*) subtract lineno $lineno 1
# read last line of $ed.a
IFS='+'
set `$dd if=$ed.a of=/dev/null bs=1 2>&1`
IFS="$saveIFS"
size=$1
# empty?
case "$size" in
0) return ;;
esac
subtract size $size 1
# skip final newline
case "$size" in
0) ;;
*) subtract size1 $size 1
case "`$dd if=$ed.a bs=1 skip=$size count=1 2>/dev/null`" in
?*) ;;
*) size=$size1 ;;
esac
;;
esac
go=true
while $go
do
case "$size" in
0) go=false ;;
*) case "`$dd if=$ed.a bs=1 skip=$size count=1 2>/dev/null`" in
?*) go=true; subtract size $size 1 ;;
*) go=false; add size $size 1 ;;
esac
;;
esac
done
# now $size is the size of the first n-1 lines
# add $ed.c to $ed.b
( $dd if=$ed.c; $dd if=$ed.b ) 2>/dev/null > $tmp.5
$dd if=$tmp.5 of=$ed.b 2>/dev/null
# move line to ed.c
case "$size" in
0) $dd if=$ed.a of=$ed.c 2>/dev/null
$dd if=/dev/null of=$tmp.5 2>/dev/null
;;
*) $dd if=$ed.a of=$ed.c bs=1 skip=$size 2>/dev/null
$dd if=$ed.a of=$tmp.5 bs=1 count=$size 2>/dev/null
;;
esac
# move rest to ed.a
$dd if=$tmp.5 of=$ed.a 2>/dev/null
;;
esac
}
# goes to a given line
goto () {
rl="$1"
compare bla "$rl" $lineno
case "$bla" in
eq) return
;;
gt) while gt "$rl" $lineno
do
next
done
;;
lt) while lt "$rl" $lineno
do
prev
done
;;
esac
}
lineout () {
Echo -n "$lineno: "
$dd if=$ed.c 2>/dev/null
}
state=closed
name=
autoprint=true
while true
do
Echo -n '> '
read cmd arg
case "$cmd:$state" in
open:open) Echo "There is a file open already" ;;
open:*) if open "$arg"
then state=open; name="$arg"; $autoprint
else Echo "Cannot open $arg"
fi
;;
new:open) Echo "There is a file open already" ;;
new:*) open "$arg"
state=open
name="$arg"
$autoprint
;;
close:changed) Echo "Use 'discard' or 'save'" ;;
close:closed) Echo "Closed already" ;;
close:*) state=closed ;;
save:closed) Echo "There isn't a file to save" ;;
save:*) case "$arg" in
?*) save "$arg" ;;
*) save "$name" ;;
esac
state=open
;;
discard:changed) Echo "Your problem!"; state=closed ;;
discard:*) state=closed ;;
print:closed) Echo "No current file" ;;
print:*) lineout ;;
goto:closed) Echo "No current file" ;;
goto:*) goto "$arg"; $autoprint ;;
next:closed) Echo "No current file" ;;
next:*) next; $autoprint ;;
prev:closed) Echo "No current file" ;;
prev:*) prev; $autoprint ;;
name:closed) Echo "No current file" ;;
name:*) name="$arg" ;;
replace:closed) Echo "No current file" ;;
replace:*) if rstring 1 $arg
then state=changed; $autoprint
else Echo "Not found"
fi
;;
nreplace:closed) Echo "No current file" ;;
nreplace:*) if rstring $arg
then state=changed; $autoprint
else Echo "Not found"
fi
;;
delete:closed) Echo "No current file" ;;
delete:*) delete; state=changed; $autoprint ;;
insert:closed) Echo "No current file" ;;
insert:*) insert "$arg"; prev; state=changed; $autoprint ;;
quit:changed) Echo "Use 'save' or 'discard'" ;;
quit:*) Echo "bye"; exit;;
autoprint:*) autoprint="lineout" ;;
noprint:*) autoprint="" ;;
:*) ;;
*) Echo "Command not understood" ;;
esac
done

View file

@ -1,92 +0,0 @@
#! /bin/bash
#
# From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
# Newsgroups: comp.unix.shell,comp.os.linux.misc
# Subject: GNU Bash Script to fix filenames
# Date: 28 Mar 1996 14:54:43 -0800
# Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
#
#This is a script which takes a list of directories, descends through each one
#and ``corrects'' filenames that:
#
# - contain filename globbing characters: * ? [ ]
# - quote characters: ' "
# - control characters: 0-31 (127 is not dealt with---oops)
# - - or + as the first character
#
# The GNU version of 'tr' is required. Also requires 'sed'.
#
# Script to process a given list of directories recursively
# and rename each file to something that is reasonable.
#
# The rules are:
#
# 1. replace each space, [, ], *, ", and ' character in the name with a
# period.
# 2. replace each control character 1..31 with a printable character obtained
# by adding 64 to the ascii value. ^A becomes A, ^B becomes B and so on.
# 3. replace a - or + occuring at the beginning of the name with a #
#
# 4. if the resulting name has been changed in any way, then
# 5. if a file of the new name already exists, then
# 6. add a . to the new name and goto step 5.
# 7. rename the old name to the new name
#
# written by Kaz Kylheku <kaz@cafe.net>
# March 1996
# Vancouver, Canada
#
# requires GNU 'bash', GNU 'tr', and some sort of 'sed' program.
#
# minimal conversion to bash v2 syntax done by Chet Ramey
processfile()
{
new_name="`echo -n $1 | tr '\173\175\052\077\042\047 ' '.......' |
tr '[\000-\037]' '[\100-\137]' |
sed -e 's/^-/#/' -e 's/+/#/'`"
if [ "$new_name" != "$1" ] ; then
while [ -e "$new_name" ] ; do
new_name="${new_name}."
done
echo changing \"$1\" to \"$new_name\" in `pwd`
mv -- "$1" "$new_name"
fi
}
processdir()
{
set -f
local savepwd="$PWD"
if cd "$1" ; then
set +f
for file in * ; do
set -f
if [ "$file" != "." ] && [ "$file" != ".." ] ; then
if [ -L "$file" ] ; then
echo "skipping symlink" $file in `pwd`
elif [ -d "$file" ] ; then
processdir "$file"
elif [ -f "$file" ] ; then
processfile "$file"
fi
fi
done
cd "$savepwd"
fi
}
shopt -s nullglob dotglob
if [ $# = 0 ] ; then
echo "$0: must specify a list of directories" >&2
echo "$0: usage: $0 directory [directory ...]" >&2
exit 2
fi
while [ $# != 0 ] ; do
processdir "$1"
shift
done
exit 0

View file

@ -1,21 +0,0 @@
# Towers of Hanoi in bash
#
# cribbed from the ksh93 book, example from exercises on page 85
#
# Chet Ramey
# chet@po.cwru.edu
hanoi() # n from to spare
{
typeset -i nm1=$1-1
((nm1>0)) && hanoi $nm1 $2 $4 $3
echo "Move disc $2 to $3"
((nm1>0)) && hanoi $nm1 $4 $3 $2
}
case $1 in
[1-9])
hanoi $1 1 2 3;;
*) echo "${0##*/}: Argument must be from 1 to 9"
exit 1;;
esac

View file

@ -1,74 +0,0 @@
# Originally
#
# From: bsh20858@news.fhda.edu (Brian S Hiles)
# Newsgroups: comp.unix.shell
# Subject: Re: getting random numbers
# Date: 23 Jan 1997 23:27:30 GMT
# Message-ID: <5c8s52$eif@tiptoe.fhda.edu>
# @(#) krand Produces a random number within integer limits
# "krand" Korn shell script generates a random number in a
# specified range with an optionally specified ``seed'' value.
# Author: Peter Turnbull, May 1993
# Modified by: Becca Thomas, January 1994
# changed the optional third argument to a -s option, converted to
# bash v2 syntax -- chet@po.cwru.edu
PROGNAME=${0##*/}
USAGE="usage: $PROGNAME [-s seed] lower-limit upper-limit"
Seed=$$ # Initialize random-number seed value with PID
usage()
{
echo ${PROGNAME}: "$USAGE" >&2
}
errexit()
{
echo ${PROGNAME}: "$@" >&2
exit 1
}
# Process command-line arguments:
while getopts "s:" opt; do
case "$opt" in
s) Seed=$OPTARG ;;
*) usage ; exit 2;;
esac
done
shift $(($OPTIND - 1))
case $# in
2) Lower=$1; Upper=$2 ;;
*) usage ; exit 2;;
esac
# Check that specified values are integers:
expr "$Lower" + 0 >/dev/null 2>&1
[ $? -eq 2 ] && { errexit "lower ($Lower) not an integer"; }
expr "$Upper" + 0 >/dev/null 2>&1
[ $? -eq 2 ] && { errexit "upper ($Upper) not an integer"; }
expr "$Seed" + 0 >/dev/null 2>&1
[ $? -eq 2 ] && { errexit "seed ($Seed) not an integer"; }
# Check that values are in the correct range:
if (( "$Lower" < 0 )) || [ ${#Lower} -gt 5 ]; then
errexit "lower limit ($Lower) less than zero"
fi
if (( "$Upper" > 32767 )) || [ ${#Upper} -gt 5 ]; then
errexit "upper limit ($Upper) greater than 32767"
fi
if (( "$Seed" < 0 )) || (( "$Seed" > 32767 )) || [ ${#Seed} -gt 5 ]; then
errexit "seed value ($Seed) out of range (0 to 32767)"
fi
(( "$Upper" <= "$Lower" )) && errexit "upper limit ($Upper) <= lower limit ($Lower)"
# Seed the random-number generator:
RANDOM=$Seed
# Compute value, scaled within range:
let rand="$RANDOM % ($Upper - $Lower + 1) + $Lower"
# Report result:
echo $rand

View file

@ -1,184 +0,0 @@
#! /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" ] && [ ${#line} != 0 ] ; do
echo -n " "
line="${line%?}"
done
while [ "${line% }" = "$line" ] && [ ${#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 ] && [ $(( ${#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>"

View file

@ -1,51 +0,0 @@
#
# BASH VERSION OF nohup COMMAND
#
ctype()
{
path=$(builtin type -p $cmd | sed 1q)
if [ -n "$path" ]; then
echo "$path"
return 0
else
case "$cmd" in
*/*) [ -x "$cmd ] && { echo "$cmd" ; return 0; } ;;
*) case "$(builtin type -t $cmd)" in
"") return 1;;
*) echo "$cmd" ; return 0;;
esac ;;
esac
fi
return 1
}
trap '' HUP # ignore hangup
command=$(ctype "$1")
oldmask=$(umask)
umask u=rw,og= # default mode for nohup.out
exec 0< /dev/null # disconnect input
if [ -t 1 ]; then # redirect output if necessary
if [ -w . ]; then
echo 'Sending output to nohup.out'
exec >> nohup.out
else echo "Sending output to $HOME/nohup.out"
exec >> $HOME/nohup.out
fi
fi
umask "$oldmask"
# direct unit 2 to a file
if [ -t 2 ]; then
exec 2>&1
fi
# run the command
case $command in
*/*) exec "$@"
;;
time) eval "$@"
;;
*) "$@"
;;
esac

View file

@ -1,75 +0,0 @@
# @(#)precedence_test 1.0 91/07/24 Maarten Litmaath
# test of relative precedences for `&&' and `||' operators
echo "\`Say' echos its argument. Its return value is of no interest."
case `echo -n` in
'') Say () { echo -n "$*" ; } ;;
*) Say () { echo "$*\c" ; } ;;
esac
echo "\`Truth' echos its argument and returns a TRUE result."
Truth () {
Say $1;
return 0;
}
echo "\`False' echos its argument and returns a FALSE result."
False () {
Say $1;
return 1;
}
echo ""
cmd1='$open $test1 && $test2 $close || $test3'
cmd2='$test1 || $open $test2 && $test3 $close'
grouping_sh=
grouping_C='( )'
test3='Say 3'
for i in 1 2
do
eval proto=\$cmd$i
for test1 in 'Truth 1' 'False 1'
do
for test2 in 'Truth 2' 'False 2'
do
for precedence in sh C
do
eval set x \$grouping_$precedence
shift
open=${1-' '}
close=${2-' '}
eval cmd=\""$proto"\"
Say "$cmd output="
output=`eval "$cmd"`
Say "$output"
read correct || { echo 'Input fubar. Abort.' >&2; exit 1; }
test "X$output" = "X$correct" || echo " correct=$correct"
echo ''
done
echo ''
done
done
done << EOF
12
12
123
123
13
13
13
13
13
1
13
1
123
123
12
12
EOF

View file

@ -1,18 +0,0 @@
# The following prints a random card from a card deck.
#
# cribbed from the ksh93 book, example from page 70
#
# chet@po.cwru.edu
#
declare -i i=0
# load the deck
for suit in clubs diamonds hearts spades; do
for n in ace 2 3 4 5 6 7 8 9 10 jack queen king; do
card[i]="$n of $suit"
i=i+1 # let is not required with integer variables
done
done
# and print a random card
echo ${card[RANDOM%52]}

View file

@ -1,25 +0,0 @@
#!/bin/bash
#
# scrollbar - display scrolling text
#
# usage: scrollbar args
#
# A cute hack originally from Heiner Steven <hs@bintec.de>
#
# converted from ksh syntax to bash v2 syntax by Chet Ramey
WIDTH=${COLUMNS:-80}
WMINUS=$(( $WIDTH - 1 ))
[ $# -lt 1 ] && set -- TESTING
# use the bash-2.02 printf builtin
Text=$(printf "%-${WIDTH}s" "$*")
Text=${Text// /_}
while :
do
printf "%-.${WIDTH}s\r" "$Text"
LastC=${Text:${WMINUS}:1}
Text="$LastC""${Text%?}"
done

View file

@ -1,24 +0,0 @@
#!/bin/bash
#
# scrollbar - display scrolling text
#
# usage: scrollbar args
#
# A cute hack originally from Heiner Steven <hs@bintec.de>
#
# converted from ksh syntax to bash v2 syntax by Chet Ramey
WIDTH=${COLUMNS:-80}
WMINUS=$(( $WIDTH - 1 ))
[ $# -lt 1 ] && set -- TESTING
# use the bash-2.02 printf builtin
Text=$(printf "%-${WIDTH}s" "$*")
while :
do
printf "%-.${WIDTH}s\r" "$Text"
LastC=${Text:${WMINUS}:1}
Text="$LastC""${Text%?}"
done

View file

@ -1,9 +0,0 @@
# self-reproducing script (except for these comment lines -- remove them)
# i got this from the ksh93 faq:
# http://www.kornshell.com/doc/faq.html
#
n="
" q="'" x="cat <<-!" y=! z='n="$n" q="$q" x="$x" y=$y z=$q$z$q$n$x$n$z$n$y'
cat <<-!
n="$n" q="$q" x="$x" y=$y z=$q$z$q$n$x$n$z$n$yb
!

View file

@ -1,53 +0,0 @@
#Newsgroups: comp.unix.shell
#From: gwc@root.co.uk (Geoff Clare)
#Subject: Re: Determining permissions on a file
#Message-ID: <Dr79nw.DtL@root.co.uk>
#Date: Fri, 10 May 1996 17:23:56 GMT
#Here's a bit of Korn shell that converts the symbolic permissions produced
#by "ls -l" into octal, using only shell builtins. How to create a script
#combining this with an "ls -l" is left as an exercise...
#
#
# Converted to Bash v2 syntax by Chet Ramey <chet@po.cwru.edu>
#
# usage: showperm modestring
#
# example: showperm '-rwsr-x--x'
#
[ -z "$1" ] && {
echo "showperm: usage: showperm modestring" >&2
exit 2
}
tmode="$1"
typeset -i omode sbits
typeset pmode
# check for set-uid, etc. bits
sbits=0
case $tmode in
???[sS]*) (( sbits += 8#4000 )) ;; # set-uid
??????[sSl]*) (( sbits += 8#2000 )) ;; # set-gid or mand. lock
?????????[tT]*) (( sbits += 8#1000 )) ;; # sticky
esac
omode=0
while :
do
tmode=${tmode#?}
case $tmode in
"") break ;;
[-STl]*) (( omode *= 2 )) ;;
[rwxst]*) (( omode = omode*2 + 1 )) ;;
*) echo "$0: first letter of \"$tmode\" is unrecognized" >&2
(( omode *= 2 ))
;;
esac
done
(( omode += sbits ))
printf "0%o\n" $omode

View file

@ -1,53 +0,0 @@
#Newsgroups: comp.unix.admin,comp.unix.solaris,comp.unix.shell
#From: gwc@root.co.uk (Geoff Clare)
#Subject: Re: timeout -t <sec> <unix command> (Re: How to give rsh a shorter timeout?)
#Message-ID: <EoBxrs.223@root.co.uk>
#Date: Fri, 13 Feb 1998 18:23:52 GMT
#
# Conversion to bash v2 syntax done by Chet Ramey <chet@po.cwru.edu
# UNTESTED
#
prog=${0##*/}
usage="usage: $prog [-signal] [timeout] [:interval] [+delay] [--] <command>"
SIG=-TERM # default signal sent to the process when the timer expires
timeout=60 # default timeout
interval=15 # default interval between checks if the process is still alive
delay=2 # default delay between posting the given signal and
# destroying the process (kill -KILL)
while :
do
case $1 in
--) shift; break ;;
-*) SIG=$1 ;;
[0-9]*) timeout=$1 ;;
:*) EXPR='..\(.*\)' ; interval=`expr x"$1" : "$EXPR"` ;;
+*) EXPR='..\(.*\)' ; delay=`expr x"$1" : "$EXPR"` ;;
*) break ;;
esac
shift
done
case $# in
0) echo "$prog: $usage" >&2 ; exit 2 ;;
esac
(
for t in $timeout $delay
do
while (( $t > $interval ))
do
sleep $interval
kill -0 $$ || exit
t=$(( $t - $interval ))
done
sleep $t
kill $SIG $$ && kill -0 $$ || exit
SIG=-KILL
done
) 2> /dev/null &
exec "$@"

View file

@ -1,29 +0,0 @@
#!/bin/sh
# Author: P@draigBrady.com
# V1.0 : Nov 3 2006
#
# Execute a command with a timeout.
# If the timeout occurs the exit status is 128
#
# Note there is an asynchronous equivalent of this
# script packaged with bash (under /usr/share/doc/ in my distro),
# which I only noticed after writing this.
if [ "$#" -lt "2" ]; then
echo "Usage: `basename $0` timeout_in_seconds command" >&2
echo "Example: `basename $0` 2 sleep 3 || echo timeout" >&2
exit 1
fi
cleanup()
{
kill %1 2>/dev/null #kill sleep $timeout if running
kill %2 2>/dev/null && exit 128 #kill monitored job if running
}
set -m #enable job control
trap "cleanup" 17 #cleanup after timeout or command
timeout=$1 && shift #first param is timeout in seconds
sleep $timeout& #start the timeout
"$@" #start the job

View file

@ -1,92 +0,0 @@
#!/bin/bash
#
# The Bash script executes a command with a time-out.
# Based on the Bash documentation example.
#
# Upon time-out expiration SIGTERM (15) is sent to the process. If the signal
# is blocked, then the subsequent SIGKILL (9) terminates it.
# Dmitry V Golovashkin (E-mail: dvg@ieee.org)
#
script_name="${0##*/}"
# Default values.
readonly param_timeout=5
readonly param_interval=1
readonly param_delay=1
declare -i timeout=param_timeout
declare -i interval=param_interval
declare -i delay=param_delay
blue="$(tput setaf 4)"
bold_red="$(tput bold; tput setaf 1)"
off="$(tput sgr0)"
function print_usage() {
cat <<EOF
Synopsis: $script_name [-t timeout] [-i interval] [-d delay] command
Executes the command with a time-out. Upon time-out expiration SIGTERM (15) is
sent to the process. If SIGTERM signal is blocked, then the subsequent SIGKILL
(9) terminates it.
$blue-t timeout$off
Number of seconds to wait for command completion.
Default value: $param_timeout seconds. In some practical situations
this value ${bold_red}must$off be increased (for instance -t 180) to allow
the command to complete.
$blue-i interval$off
Interval between checks if the process is still alive.
Positive integer, default value: $param_interval seconds.
Default value is OK for most situations.
$blue-d delay$off
Delay between posting the SIGTERM signal and destroying the process by
SIGKILL. Default value: $param_delay seconds.
Default value is OK for most situations.
As of today, Bash does not support floating point arithmetic (sleep does),
therefore all time values must be integers.
Dmitry Golovashkin (E-mail: dvg@ieee.org)
EOF
exit 1 # No useful work was done.
}
# Options.
while getopts ":t:i:d:" option; do
case "$option" in
t) timeout=$OPTARG ;;
i) interval=$OPTARG ;;
d) delay=$OPTARG ;;
*) print_usage ;;
esac
done
shift $((OPTIND - 1))
# $# should be at least 1 (the command to execute), however it may be strictly
# greater than 1 if the command itself has options.
if (($# == 0 || interval <= 0)); then
print_usage
fi
# kill -0 pid Exit code indicates if a signal may be sent to "pid" process.
(
((t = timeout))
while ((t > 0)); do
sleep $interval
kill -0 $$ || exit 0
((t -= interval))
done
# Be nice, post SIGTERM first.
# The 'exit 0' below will be executed if any preceeding command fails.
kill -s SIGTERM $$ && kill -0 $$ || exit 0
sleep $delay
kill -s SIGKILL $$
) 2> /dev/null &
exec "$@"

View file

@ -1,43 +0,0 @@
#!/bin/bash
#
# vtree - make a tree printout of the specified directory, with disk usage
# in 1k blocks
#
# usage: vtree [-a] [dir]
#
# Original posted to Usenet sometime in February, 1996
# I believe that the original author is Brian S. Hiles <bsh29256@atc.fhda.edu>
#
usage()
{
echo "vtree: usage: vtree [-a] [dir]" >&2
}
while getopts a opt
do
case "$opt" in
a) andfiles=-a ;;
*) usage ; exit 2 ;;
esac
done
shift $((OPTIND - 1))
export BLOCKSIZE=1k # 4.4 BSD systems need this
[ $# -eq 0 ] && set .
while [ $# -gt 0 ]
do
cd "$1" || { shift; [ $# -ge 1 ] && echo >&2; continue; }
echo -n "$PWD"
du $andfiles | sort -k 2f | sed \
-e 's/\([^ ]*\) \(.*\)/\2 (\1)/' \
-e "s#^$1##" \
-e 's#[^/]*/\([^/]*\)$#|____\1#' \
-e 's#[^/]*/#| #g'
[ $# -gt 1 ] && echo
shift
done

View file

@ -1,99 +0,0 @@
#!/bin/ksh
#
# 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 ;;
*) 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

View file

@ -1,100 +0,0 @@
#!/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

View file

@ -1,230 +0,0 @@
#!/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