aboutsummaryrefslogtreecommitdiffstats
path: root/examples/functions
diff options
context:
space:
mode:
Diffstat (limited to 'examples/functions')
-rw-r--r--examples/functions/basename243
-rw-r--r--examples/functions/coproc.bash108
-rw-r--r--examples/functions/coshell.README53
-rw-r--r--examples/functions/coshell.bash127
-rw-r--r--examples/functions/dirfuncs142
-rw-r--r--examples/functions/emptydir28
-rw-r--r--examples/functions/gethtml35
-rw-r--r--examples/functions/getoptx.bash301
-rw-r--r--examples/functions/isnum.bash52
-rw-r--r--examples/functions/jdate.bash78
-rw-r--r--examples/functions/jj.bash12
-rw-r--r--examples/functions/keep62
-rw-r--r--examples/functions/lowercase27
-rw-r--r--examples/functions/manpage129
-rw-r--r--examples/functions/mhfold16
-rw-r--r--examples/functions/pathfuncs45
-rw-r--r--examples/functions/recurse63
-rw-r--r--examples/functions/repeat243
-rw-r--r--examples/functions/repeat312
-rw-r--r--examples/functions/term35
-rw-r--r--examples/functions/xalias.bash22
-rw-r--r--examples/functions/xfind.bash52
22 files changed, 0 insertions, 1485 deletions
diff --git a/examples/functions/basename2 b/examples/functions/basename2
deleted file mode 100644
index a42231c..0000000
--- a/examples/functions/basename2
+++ /dev/null
@@ -1,43 +0,0 @@
-#From: "Grigoriy Strokin" <grg@philol.msu.ru>
-#Newsgroups: comp.unix.shell
-#Subject: fast basename and dirname functions for BASH/SH
-#Date: Sat, 27 Dec 1997 21:18:40 +0300
-#
-#Please send your comments to grg@philol.msu.ru
-
-function basename()
-{
- local name="${1##*/}"
- echo "${name%$2}"
-}
-
-function dirname()
-{
- local dir="${1%${1##*/}}"
- [ "${dir:=./}" != "/" ] && dir="${dir%?}"
- echo "$dir"
-}
-
-# Two additional functions:
-# 1) namename prints the basename without extension
-# 2) ext prints extension of a file, including "."
-
-function namename()
-{
- local name=${1##*/}
- local name0="${name%.*}"
- echo "${name0:-$name}"
-}
-function ext()
-{
- local name=${1##*/}
- local name0="${name%.*}"
- local ext=${name0:+${name#$name0}}
- echo "${ext:-.}"
-}
-
-
-
-
-
-
diff --git a/examples/functions/coproc.bash b/examples/functions/coproc.bash
deleted file mode 100644
index 61dc8d7..0000000
--- a/examples/functions/coproc.bash
+++ /dev/null
@@ -1,108 +0,0 @@
-# coprocess.bash
-#
-# vi:set sts=2 sw=2 ai:
-#
-
-coprocess_pid=
-
-#
-# coprocess - Start, control, and end coprocesses.
-#
-function coprocess ()
-{
- while (( $# > 0 )) ; do
- case "$1" in
- #
- # coprocess close
- #
- c|cl|clo|clos|close)
- shift
- exec 61>&- 62<&-
- coprocess_pid=
- if [ "$1" = "-SIGPIPE" ] ; then
- # Only print message in an interactive shell
- case "$-" in
- *i*)
- echo 'SIGPIPE' >&2
- ;;
- esac
- return 1
- fi
- return 0
- ;;
-
- #
- # coprocess open
- #
- o|op|ope|open)
- shift
- local fifo="/var/tmp/coprocess.$$.$RANDOM"
-
- local cmd="/bin/bash"
- if (( $# > 0 )) ; then
- cmd="$@"
- fi
-
- mkfifo "$fifo.in" || return $?
- mkfifo "$fifo.out" || {
- ret=$?
- rm -f "$fifo.in"
- return $?
- }
-
- ( "$@" <$fifo.in >$fifo.out ; rm -f "$fifo.in" "$fifo.out" ) &
- coprocess_pid=$!
- exec 61>$fifo.in 62<$fifo.out
- return 0
- ;;
-
- #
- # coprocess print - write to the coprocess
- #
- p|pr|pri|prin|print)
- shift
- local old_trap=$(trap -p SIGPIPE)
- trap 'coprocess close -SIGPIPE' SIGPIPE
- if [ $# -eq 1 ] && [ "$1" = "--stdin" ] ; then
- cat >&61
- else
- echo "$@" >&61
- fi
- local ret=$?
- eval "$old_trap"
- return $ret
- ;;
-
- #
- # coprocess read - read from the coprocess
- #
- r|re|rea|read)
- shift
- local old_trap=$(trap -p SIGPIPE)
- trap '_coprocess_close -SIGPIPE' SIGPIPE
- builtin read "$@" <&62
- local ret=$?
- eval "$old_trap"
- return $ret
- ;;
-
- s|st|sta|stat|statu|status)
- if [ -z "$coprocess_pid" ] ; then
- echo 'no active coprocess'
- return 1
- else
- echo " coprocess is active [$coprocess_pid]"
- return 0
- fi
- ;;
-
- *)
- coprocess print "$@"
- return $?
- ;;
- esac
- shift
- done
- coprocess status
- return $?
-}
diff --git a/examples/functions/coshell.README b/examples/functions/coshell.README
deleted file mode 100644
index 9675cda..0000000
--- a/examples/functions/coshell.README
+++ /dev/null
@@ -1,53 +0,0 @@
-Date: Fri, 21 Sep 2001 14:50:29 -0400
-From: "Jason M. Felice" <jfelice@cronosys.com>
-To: bash-maintainers@gnu.org, chet@po.cwru.edu
-Subject: Bash co-processes functions
-Message-ID: <20010921145029.A6093@argo.eraserhead.net>
-Mime-Version: 1.0
-
-Attached to this message you will find coprocess.bash and coshell.bash.
-Here's a brief synopsis of use:
-
-coprocess open telnet localhost
-while coprocess read il ; do
- echo "$il"
- case "$il" in
- *ogin:*)
- coprocess print 'user'
- ;;
- *ord:*)
- echo 'pass' |coprocess print --stdin
- ;;
- *$ *)
- coprocess print 'exit'
- break
- ;;
- esac
-done
-coprocess close
-
-And here's an example of the coshell function:
-
-coshell open ssh -l root otherbox
-coshell eval hostname
-coshell ls -l
-if coshell test -d /tmp ; then echo 'otherbox has a /tmp!' ; fi
-
-coshell sendfile /var/lib/upgrade.rpm /tmp/test.rpm || exit $?
-coshell eval rpm -ivh /tmp/test.rpm || exit $?
-coshell eval rm -f /tmp/test.rpm || exit $?
-coshell close
-exit 0
-
-There are a few minor issues that I'd like to work out, but it works well
-enough for me ;-) The issues are:
-
-- Shell quoting issue with 'coshell eval' commands - need to somehow
- re-quote words.
-- Interactive commands hang 'coshell eval', tried redirecting in </dev/null
- to executed command, but it caused strange shell exit problems.
-- Some way to copy stdin from local coshell eval to remote shell. Probably
- logically impossible, but would be wonderfully useful.
-
-I'm using it for writing scripts to publish websites and other scripts to
-co-located servers.
diff --git a/examples/functions/coshell.bash b/examples/functions/coshell.bash
deleted file mode 100644
index dc177b3..0000000
--- a/examples/functions/coshell.bash
+++ /dev/null
@@ -1,127 +0,0 @@
-# vi:set sts=2 sw=2 ai:
-#
-# coshell.bash - Control shell coprocesses (see coprocess.bash).
-#
-
-function coshell ()
-{
- while (( $# > 0 )) ; do
- case "$1" in
- #
- # coshell open
- #
- o|op|ope|open)
- shift
- coprocess open "$@"
- local ret=$?
-
- # This should eat any ssh error messages or what not.
- coshell eval : >/dev/null 2>&1
- return $ret
- ;;
-
- #
- # coshell close
- #
- c|cl|clo|close)
- shift
- coprocess close "$@"
- return $?
- ;;
-
- #
- # coshell eval
- #
- e|ev|eva|eval)
- shift
- local cookie=$RANDOM
- if (( $# == 0 )) ; then
- echo "coshell eval: no argumentsl" >&2
- return 1
- fi
- if [ x$coprocess_pid = x ] ; then
- echo "coshell eval: no active coshell" >&2
- return 1
- fi
-
- coprocess print "$@"
- coprocess print "coprocess_rc=\$?"
- coprocess print "printf 'coprocess-$cookie----\n%d\n' \$coprocess_rc"
- if [ x$coprocess_pid = x ] ; then
- return 0
- fi
-
- local ol
- while coprocess read ol ; do
- case "$ol" in
- *coprocess-$cookie----*)
- ol="${ol%coprocess-$cookie----}"
- echo -n "$ol"
- break
- ;;
- esac
- echo "$ol"
- done
- coprocess read ol
- return $ol
- ;;
-
- #
- # coshell sendfile
- #
- s|se|sen|send|sendf|sendfi|sendfil|sendfile)
- shift
- if (( $# != 2 )) ; then
- echo "coshell sendfile: syntax is 'coshell sendfile SRC TARGET'" >&2
- return 1
- fi
- if [ x$coprocess_pid = x ] ; then
- echo "coshell sendfile: no active coshell" >&2
- return 1
- fi
-
- local target=$2
- if coshell test -d "$target" ; then
- target="$target/${1##*/}"
- fi
-
- coprocess print "uudecode <<END_OF_FILE"
- uuencode -m "$target" <$1 |coprocess print --stdin
- coshell eval "END_OF_FILE"
- return $?
- ;;
-
- #
- # coshell getfile
- #
- g|ge|get|getf|getfi|getfil|getfile)
- shift
- if (( $# != 2 )) ; then
- echo "coshell getfile: syntax is 'coshell getfile SRC TARGET'" >&2
- return 1
- fi
- if [ x$coprocess_pid = x ] ; then
- echo "coshell getfile: no active coshell" >&2
- return 1
- fi
-
- local target=$2
- if test -d "$target" ; then
- target="$target/${1##*/}"
- fi
-
- coshell eval uuencode -m "$target" "<" "$1" |uudecode
- return $?
- ;;
-
- *)
- coshell eval "$@"
- return $?
- ;;
- esac
- shift
- done
- coprocess status
- return $?
-}
-
diff --git a/examples/functions/dirfuncs b/examples/functions/dirfuncs
deleted file mode 100644
index 3958bbe..0000000
--- a/examples/functions/dirfuncs
+++ /dev/null
@@ -1,142 +0,0 @@
-#
-# Directory manipulation functions from the book 'The Korn Shell'
-# Modified for use with bash Mon Apr 18 08:37 1994 by
-# Ken Konecki (kenk@wfg.com)
-#
-# Modified by Chet Ramey
-#
-# This could stand to have calls to `select' added back in
-#
-
-alias integer="declare -i"
-
-integer _push_max=${CDSTACK-31} _push_top=${CDSTACK-31}
-
-unalias cd
-# alias cd=_cd
-
-# Display directory stack -- $HOME display as ~
-dirs()
-{
- dir="${PWD#$HOME/}"
- case $dir in
- $HOME) dir=\~ ;;
- /*) ;;
- *) dir=\~/$dir ;;
- esac
-
- integer i=_push_top
- integer n=1
-
- echo "$n) $dir"
- while let "i < $_push_max"
- do
- n=n+1
- eval "echo \$n\) \$_push_stack_$i"
- i=i+1
- done
-}
-
-# Change directory and put directory on front of stack
-cd()
-{
- typeset dir=
- integer n=0 type=4 i
- case $1 in
- -|-1|2) # cd -
- n=_push_top type=1
- ;;
- -[1-9]|-[1-9][0-9]) # cd -n
- n=_push_top+${1#-}-1 type=2
- ;;
-
- 1) # keep present directory
- echo "$PWD"
- return
- ;;
-
- [2-9]|[1-9][0-9]) # cd n
- n=_push_top+${1}-2 type=2
- ;;
-
- *)
- if let "_push_top <= 0"; then
- type=3 n=_push_max
- fi
- ;;
- esac
-
- if let "type < 3"; then
- if let "n >= _push_max"; then
- echo cd: Directory stack not that deep
- return 1
- else
- eval dir=\${_push_stack_$n}
- fi
- fi
-
- case $dir in
- ~*) dir=$HOME${dir#\~} ;;
- esac
-
- cd2 ${dir:-$@} > /dev/null || return 1
- dir=${OLDPWD#$HOME/}
- case $dir in
- $HOME) dir=\~ ;;
- /*) ;;
- *) dir=\~/$dir ;;
- esac
-
- case $type in
- 1) # swap first two elements
- eval _push_stack_$_push_top=\$dir ;;
-
- 2|3) # put $dir on top and shift down by one until top
- i=_push_top
- unset _dirlist
- while let "i < $_push_max" ; do
- eval _dirlist=\"\$_dirlist \$_push_stack_$i\"
- i=i+1
- done
-
- i=_push_top
- for dir in "$dir" ${_dirlist} ; do
- let "i > n" && break
- eval _push_stack_$i=\$dir
- i=i+1
- done
- ;;
- 4) # push name
- _push_top=_push_top-1;
- eval _push_stack_$_push_top=\$dir
- ;;
- esac
-
- echo "$PWD"
-
-}
-
-# Menu-driven change directory command
-function mcd
-{
- dirs
- echo -n "Select by number or enter a name: "
- read
- cd $REPLY
-}
-
-
-# Emulate ksh cd substitution
-cd2()
-{
- case "$#" in
- 0) builtin cd "$HOME" ;;
- 1) builtin cd "$1" ;;
- 2) newDir=$(echo $PWD | sed -e "s:$1:$2:g")
- case "$newDir" in
- $PWD) echo "bash:: cd: bad substitution" >&2 ; return 1 ;;
- *) builtin cd "$newDir" ;;
- esac ;;
- *) echo "bash: cd: wrong arg count" 1>&2 ; return 1 ;;
- esac
-}
diff --git a/examples/functions/emptydir b/examples/functions/emptydir
deleted file mode 100644
index 412af5b..0000000
--- a/examples/functions/emptydir
+++ /dev/null
@@ -1,28 +0,0 @@
-#! /bin/bash
-#
-#Derived from:
-#
-#From: damercer@mmm.com (Dan Mercer)
-#Newsgroups: comp.unix.admin,comp.unix.shell,comp.unix.programmer,comp.sys.sun.admin
-#Subject: Re: Command to find out if a directory is empty
-#Date: 17 Aug 2000 14:35:56 GMT
-#Message-ID: <8ngt8c$fmr$1@magnum.mmm.com>
-
-# usage: emptydir [dirname] ; default dirname is "."
-
-emptydir()
-{
- typeset file dir=${1:-.}
- [[ -d $dir ]] || {
- echo "$FUNCNAME: $dir is not a directory" >&2
- return 2
- }
- for file in $dir/.* $dir/*
- do
- case ${file#$dir/} in
- .|..) ;;
- \*) [[ -e $file ]];let $?;return;;
- *) return 1;;
- esac
- done
-}
diff --git a/examples/functions/gethtml b/examples/functions/gethtml
deleted file mode 100644
index 2eec1d8..0000000
--- a/examples/functions/gethtml
+++ /dev/null
@@ -1,35 +0,0 @@
-#
-# get_html -- get a web page from a remote server
-#
-# Original Author: Jeff Korn <jlk@cs.princeton.edu>
-# Modified for bash by Chet Ramey <chet@po.cwru.edu>
-#
-# Example: get_html cnswww.cns.cwru.edu /~chet/ | more
-
-get_html()
-{
- local host port
-
- (($# < 2)) && {
- echo "usage: $FUNCNAME hostname path [port]" >&2
- return 1
- }
-
- host="$1"
- port="${3:-80}"
-
- exec 3<> /dev/tcp/$host/$port || {
- echo "$FUNCNAME: $host/$port: cannot connect" >&2
- exit 1
- }
-
- echo -e "GET $2 HTTP/1.0\n" >&3
-
- cat <&3
-
- exec 3<&-
-
- return 0
-}
-
-get_html "$@"
diff --git a/examples/functions/getoptx.bash b/examples/functions/getoptx.bash
deleted file mode 100644
index d402c7d..0000000
--- a/examples/functions/getoptx.bash
+++ /dev/null
@@ -1,301 +0,0 @@
-#From: "Grigoriy Strokin" <grg@philol.msu.ru>
-#Newsgroups: comp.unix.shell
-#Subject: BASH: getopt function that parses long-named options
-#Date: Mon, 22 Dec 1997 20:35:18 +0300
-
-#Hi, I have written a BASH function named getoptex, that is like bash builtin
-#"getopts", but does parse long-named options and optional arguments. It only
-#uses builtin bash commands, so it is very fast. In order to use it in your
-#bash scripts, include a command ". getopt.sh" (<dot> getopt.sh) to the file
-#containing your script, and that will define functions getopt, getoptex, and
-#optlistex (the file getopt.sh with its detailed description is listed
-#below).
-
-#*** file getopt.sh ***
-
-#! /bin/bash
-#
-# getopt.sh:
-# functions like getopts but do long-named options parsing
-# and support optional arguments
-#
-# Version 1.0 1997 by Grigoriy Strokin (grg@philol.msu.ru), Public Domain
-# Date created: December 21, 1997
-# Date modified: December 21, 1997
-#
-# IMPORTANT FEATURES
-#
-# 1) Parses both short and long-named options
-# 2) Supports optional arguments
-# 3) Only uses bash builtins, thus no calls to external
-# utilities such as expr or sed is done. Therefore,
-# parsing speed is high enough
-#
-#
-# DESCRIPTION
-#
-# FUNCTION getopt
-# Usage: getopt OPTLIST {"$@"|ALTERNATIVE_PARAMETERS}
-#
-# like getopts, but parse options with both required and optional arguments,
-# Options with optional arguments must have "." instead of ":" after them.
-# Furthemore, a variable name to place option name cannot be specified
-# and is always placed in OPTOPT variable
-#
-# This function is provided for compatibility with getopts()
-# OPTLIST style, and it actually calls getoptex (see bellow)
-#
-# NOTE that a list of parameters is required and must be either "$@",
-# if processing command line arguments, or some alternative parameters.
-#
-# FUNCTION getoptex
-# Usage: getoptex OPTION_LIST {"$@"|ALTERNATIVE_PARAMETERS}
-#
-# like getopts, but parse long-named options.
-#
-# Both getopt and getoptex return 0 if an option has been parsed,
-# and 1 if all options are already parsed or an error occured
-#
-# Both getopt and getoptex set or test the following variables:
-#
-# OPTERR -- tested for whether error messages must be given for invalid
-options
-#
-# OPTOPT -- set to the name of an option parsed,
-# or to "?" if no more options or error
-# OPTARG -- set to the option argument, if any;
-# unset if ther is no argument;
-# on error, set to the erroneous option name
-#
-# OPTIND -- Initialized to 1.
-# Then set to the number of the next parameter to be parsed
-# when getopt or getoptex will be called next time.
-# When all options are parsed, contains a number of
-# the first non-option argument.
-#
-#
-# OPTOFS -- If a parameter number $OPTIND containg an option parsed
-# does not contain any more options, OPTOFS is unset;
-# otherwise, OPTOFS is set to such a number of "?" signs
-# which is equal to the number of options parsed
-#
-# You might not set variables OPTIND and OPTOFS yourself
-# unless you want to parse a list of parameters more than once.
-# Otherwise, you whould unset OPTIND (or set it to 1)
-# and unset OPTOFS each time you want to parse a new parameters
-list
-#
-# Option list format is DIFFERENT from one for getopts or getopt.
-getopts-style
-# option list can be converted to getoptex-style using a function optlistex
-# (see bellow)
-#
-# DESCRIPTION of option list used with getoptex:
-# Option names are separated by whitespace. Options consiting of
-# more than one character are treated as long-named (--option)
-#
-# Special characters can appear at the and of option names specifying
-# whether an argument is required (default is ";"):
-# ";" (default) -- no argument
-# ":" -- required argument
-# "," -- optional argument
-#
-# For example, an option list "a b c help version f: file: separator."
-# defines the following options:
-# -a, -b, -c, --help, --version -- no argument
-# -f, --file -- argument required
-# --separator -- optional argument
-#
-# FUNCTION optlistex
-# Usage new_style_optlist=`optlistex OLD_STYLE_OPTLIST`
-#
-# Converts getopts-style option list in a format suitable for use with getoptex
-# Namely, it inserts spaces after each option name.
-#
-#
-# HOW TO USE
-#
-# In order o use in your bash scripts the functions described,
-# include a command ". getopt.sh" to the file containing the script,
-# which will define functions getopt, getoptex, and optlistex
-#
-# EXAMPLES
-#
-# See files 'getopt1' and 'getopt2' that contain sample scripts that use
-# getopt and getoptex functions respectively
-#
-#
-# Please send your comments to grg@philol.msu.ru
-
-function getoptex()
-{
- let $# || return 1
- local optlist="${1#;}"
- let OPTIND || OPTIND=1
- [ $OPTIND -lt $# ] || return 1
- shift $OPTIND
- if [ "$1" != "-" ] && [ "$1" != "${1#-}" ]
- then OPTIND=$[OPTIND+1]; if [ "$1" != "--" ]
- then
- local o
- o="-${1#-$OPTOFS}"
- for opt in ${optlist#;}
- do
- OPTOPT="${opt%[;.:]}"
- unset OPTARG
- local opttype="${opt##*[^;:.]}"
- [ -z "$opttype" ] && opttype=";"
- if [ ${#OPTOPT} -gt 1 ]
- then # long-named option
- case $o in
- "--$OPTOPT")
- if [ "$opttype" != ":" ]; then return 0; fi
- OPTARG="$2"
- if [ -z "$OPTARG" ];
- then # error: must have an agrument
- let OPTERR && echo "$0: error: $OPTOPT must have an argument" >&2
- OPTARG="$OPTOPT";
- OPTOPT="?"
- return 1;
- fi
- OPTIND=$[OPTIND+1] # skip option's argument
- return 0
- ;;
- "--$OPTOPT="*)
- if [ "$opttype" = ";" ];
- then # error: must not have arguments
- let OPTERR && echo "$0: error: $OPTOPT must not have arguments" >&2
- OPTARG="$OPTOPT"
- OPTOPT="?"
- return 1
- fi
- OPTARG=${o#"--$OPTOPT="}
- return 0
- ;;
- esac
- else # short-named option
- case "$o" in
- "-$OPTOPT")
- unset OPTOFS
- [ "$opttype" != ":" ] && return 0
- OPTARG="$2"
- if [ -z "$OPTARG" ]
- then
- echo "$0: error: -$OPTOPT must have an argument" >&2
- OPTARG="$OPTOPT"
- OPTOPT="?"
- return 1
- fi
- OPTIND=$[OPTIND+1] # skip option's argument
- return 0
- ;;
- "-$OPTOPT"*)
- if [ $opttype = ";" ]
- then # an option with no argument is in a chain of options
- OPTOFS="$OPTOFS?" # move to the next option in the chain
- OPTIND=$[OPTIND-1] # the chain still has other options
- return 0
- else
- unset OPTOFS
- OPTARG="${o#-$OPTOPT}"
- return 0
- fi
- ;;
- esac
- fi
- done
- echo "$0: error: invalid option: $o"
- fi; fi
- OPTOPT="?"
- unset OPTARG
- return 1
-}
-function optlistex
-{
- local l="$1"
- local m # mask
- local r # to store result
- while [ ${#m} -lt $[${#l}-1] ]; do m="$m?"; done # create a "???..." mask
- while [ -n "$l" ]
- do
- r="${r:+"$r "}${l%$m}" # append the first character of $l to $r
- l="${l#?}" # cut the first charecter from $l
- m="${m#?}" # cut one "?" sign from m
- if [ -n "${l%%[^:.;]*}" ]
- then # a special character (";", ".", or ":") was found
- r="$r${l%$m}" # append it to $r
- l="${l#?}" # cut the special character from l
- m="${m#?}" # cut one more "?" sign
- fi
- done
- echo $r
-}
-function getopt()
-{
- local optlist=`optlistex "$1"`
- shift
- getoptex "$optlist" "$@"
- return $?
-}
-
-#**************************************
-# cut here
-#**************************************
-#*** (end of getopt.sh) ***
-
-
-#*** file getopt1 ***
-
-#! /bin/bash
-# getopt1:
-# Sample script using the function getopt
-#
-# Type something like "getopt1 -ab -d 10 -e20 text1 text2"
-# on the command line to see how it works
-#
-# See getopt.sh for more information
-#. getopt.sh
-#echo Using getopt to parse arguments:
-#while getopt "abcd:e." "$@"
-#do
-# echo "Option <$OPTOPT> ${OPTARG:+has an arg <$OPTARG>}"
-#done
-#shift $[OPTIND-1]
-#for arg in "$@"
-#do
-# echo "Non option argument <$arg>"
-#done
-#
-#**************************************
-# cut here
-#**************************************
-#*** (end of getopt1) ***
-#
-#
-#*** file getopt2 ***
-#
-#! /bin/bash
-# getopt2:
-# Sample script using the function getoptex
-#
-# Type something like "getopt2 -ab -d 10 -e20 --opt1 --opt4=100 text1 text2"
-# to see how it works
-#
-# See getopt.sh for more information
-. getopt.sh
-#echo Using getoptex to parse arguments:
-#while getoptex "a; b; c; d: e. opt1 opt2 opt3 opt4: opt5." "$@"
-#do
-# echo "Option <$OPTOPT> ${OPTARG:+has an arg <$OPTARG>}"
-#done
-#shift $[OPTIND-1]
-#for arg in "$@"
-#do
-# echo "Non option argument <$arg>"
-#done
-#
-#**************************************
-# cut here
-#**************************************
-#*** (end of getopt2) ***
-
diff --git a/examples/functions/isnum.bash b/examples/functions/isnum.bash
deleted file mode 100644
index b733965..0000000
--- a/examples/functions/isnum.bash
+++ /dev/null
@@ -1,52 +0,0 @@
-#From: jrmartin@rainey.blueneptune.com (James R. Martin)
-#Newsgroups: comp.unix.shell
-#Subject: Re: testing user input on numeric or character value
-#Date: 26 Nov 1997 01:28:43 GMT
-
-# isnum returns True if its argument is a valid number,
-# and False (retval=1) if it is any other string.
-# The first pattern requires a digit before the decimal
-# point, and the second after the decimal point.
-
-# BASH NOTE: make sure you have executed `shopt -s extglob' before
-# trying to use this function, or it will not work
-
-isnum() # string
-{
- case $1 in
- ?([-+])+([0-9])?(.)*([0-9])?([Ee]?([-+])+([0-9])) )
- return 0;;
- ?([-+])*([0-9])?(.)+([0-9])?([Ee]?([-+])+([0-9])) )
- return 0;;
- *) return 1;;
- esac
-}
-
-isnum2() # string
-{
- case $1 in
- ?([-+])+([[:digit:]])?(.)*([[:digit:]])?([Ee]?([-+])+([[:digit:]])) )
- return 0;;
- ?([-+])*([[:digit:]])?(.)+([[:digit:]])?([Ee]?([-+])+([[:digit:]])) )
- return 0;;
- *) return 1;;
- esac
-}
-
-isint() # string
-{
- case $1 in
- ?([-+])+([0-9]) )
- return 0;;
- *) return 1;;
- esac
-}
-
-isint2() # string
-{
- case $1 in
- ?([-+])+([[:digit:]]) )
- return 0;;
- *) return 1;;
- esac
-}
diff --git a/examples/functions/jdate.bash b/examples/functions/jdate.bash
deleted file mode 100644
index 9488ed9..0000000
--- a/examples/functions/jdate.bash
+++ /dev/null
@@ -1,78 +0,0 @@
-#From: damatex@CAM.ORG (Mario Boudreault)
-#Newsgroups: comp.unix.shell
-#Subject: JULIAN DATE CONVERSION SUB
-#Date: 4 Aug 1995 10:23:28 -0400
-#Message-ID: <3vtah0$jb3@ocean.CAM.ORG>
-
-#For those using shells and who want to convert dates to a julian number
-#here is a shell script (wihtout validation) that can be used as a base
-#program for your shell scripts.
-
-#Special thanks to Ed Ferguson@ti.com who sent me the algorithm to compute
-#that date.
-
-#
-# MODIFIED BY CHET RAMEY TO CONVERT TO bash v2 SYNTAX
-#
-
-# cnvdate - Conversion de dates en julienne et vice et versa...
-#
-# Par : Mario Boudreault Damatex Inc Montreal, Canada
-# Date: 2 Aout 1995
-# Rev.: 2 Aout 1995
-#
-# Usage:
-# cvdate [-j] YYYMMDD pour convertir en nbre de jours
-# cvdate -d {julian number} pour convertir en AAAAMMJJ
-#
-
-jul_date()
-{
- #
- # Separe ANNEE, MOIS et JOUR...
- #
- YEAR=`echo $DATE | awk ' { print substr($0,1,4) } '`
- MONTH=`echo $DATE | awk ' { print substr($0,5,2) } '`
- DAY=`echo $DATE | awk ' { print substr($0,7,2) } '`
- #
- # Execute la formule magique...
- #
- A=$(( $DAY - 32075 + 1461 * ( $YEAR + 4800 - ( 14 - $MONTH ) / 12 ) \
- / 4 + 367 * ( $MONTH - 2 + ( 14 - $MONTH ) / 12 * 12 ) / 12 - \
- 3 * ( ( $YEAR + 4900 - ( 14 - $MONTH ) / 12 ) / 100 ) / 4 ))
- echo $A
-}
-
-day_date()
-{
- TEMP1=$(( $DATE + 68569 ))
- TEMP2=$(( 4 * $TEMP1 / 146097 ))
- TEMP1=$(( $TEMP1 - ( 146097 * $TEMP2 + 3 ) / 4 ))
- Y=$(( 4000 * ( $TEMP1 + 1 ) / 1461001 ))
- TEMP1=$(( $TEMP1 - 1461 * $Y / 4 + 31 ))
- M=$(( 80 * $TEMP1 / 2447 ))
- D=$(( $TEMP1 - 2447 * $M / 80 ))
- TEMP1=$(( $M / 11 ))
- M=$(( $M + 2 - 12 * $TEMP1 ))
- Y=$(( 100 * ( $TEMP2 - 49 ) + $Y + $TEMP1 ))
- M=`echo $M | awk ' { M=$0 ; if ( length($0) == 1 ) M="0"$0 } END { print M } '`
- D=`echo $D | awk ' { D=$0 ; if ( length($0) == 1 ) D="0"$0 } END { print D } '`
- echo $Y$M$D
-}
-
-# main()
-
-if [ $# -eq 1 ]; then
- DATE=$1
- jul_date
-elif [ "$1" = '-j' ]; then
- DATE=$2
- jul_date
-elif [ "$1" = '-d' ]; then
- DATE=$2
- day_date
-fi
-#
-# Termine
-#
-exit 0
diff --git a/examples/functions/jj.bash b/examples/functions/jj.bash
deleted file mode 100644
index 212c9ce..0000000
--- a/examples/functions/jj.bash
+++ /dev/null
@@ -1,12 +0,0 @@
-jj ()
-{
- p=$(jobs $1);
- echo $p
-
- case "$p" in
- [*) echo matches '[*'
- ;;
- *) echo not a match\?
- ;;
- esac
-}
diff --git a/examples/functions/keep b/examples/functions/keep
deleted file mode 100644
index 4433b35..0000000
--- a/examples/functions/keep
+++ /dev/null
@@ -1,62 +0,0 @@
-# From: Seth Chaiklin <psykseth@aau.dk>
-# To: chet@ins.CWRU.Edu
-# Subject: bash functions (sorta)
-
-#
-# keep:
-# usage: keep program
-# declare the a program should be "kept". i.e. try to fg a stopped one
-# and only when that fails start a fresh program.
-#
-
-keep()
-{
- case $# in
- 1|2) ;;
- *) echo "usage: keep [alias] program" 1>&2 ; return 1;;
- esac
-
- # progname
- pn=${1##*/}
-
- # set up an alias for the kept program
- if [ $# = 1 ]; then
- alias "$pn=fg $1 2>/dev/null || $1"
- else
- alias "$1=fg $2 2>/dev/null || $2"
- fi
-}
-
-#
-# unkeep:
-# usage: unkeep program
-# unset the alias set up by the keep function
-#
-
-unkeep()
-{
- if [ $# != 1 ]; then
- echo "usage: unkeep program"
- return 2
- fi
-
- # unset the alias for the kept program
- unalias "${1##*/}"
-}
-
-#
-# kept:
-# lists all kept programs in 'alias: program' form
-#
-
-kept()
-{
- alias | grep "fg.*2>" | sed "s/alias \(.*\)='fg.*||\(.*\)'$/\1:\2/"
-}
-
-
-# some things that should be kept
-#keep /usr/local/bin/emacs
-#keep e ${EDITOR:-/usr/local/bin/emacs}
-#keep edit ${EDITOR:-/usr/local/bin/emacs}
-#keep /usr/local/bin/emm
diff --git a/examples/functions/lowercase b/examples/functions/lowercase
deleted file mode 100644
index 3cf6bde..0000000
--- a/examples/functions/lowercase
+++ /dev/null
@@ -1,27 +0,0 @@
-#! /bin/bash
-#
-# original from
-# @(#) lowercase.ksh 1.0 92/10/08
-# 92/10/08 john h. dubois iii (john@armory.com)
-#
-# conversion to bash v2 syntax done by Chet Ramey
-
-lowercase()
-{
- for file; do
- [ -f "$file" ] || continue
- filename=${file##*/}
- case "$file" in
- */*) dirname=${file%/*} ;;
- *) dirname=.;;
- esac
- nf=$(echo $filename | tr A-Z a-z)
- newname="${dirname}/${nf}"
- if [ "$nf" != "$filename" ]; then
- mv "$file" "$newname"
- echo "lowercase: $file -> $newname"
- else
- echo "lowercase: $file not changed."
- fi
- done
-}
diff --git a/examples/functions/manpage b/examples/functions/manpage
deleted file mode 100644
index 60f9aed..0000000
--- a/examples/functions/manpage
+++ /dev/null
@@ -1,129 +0,0 @@
-# Written from scratch by Tom Tromey (tromey@cns.caltech.edu)
-#
-# manpage -- find and print a manual page.
-# usage: manpage section name [printing]
-#
-function manpage ()
-{
- local i h cmd zot sec
- local num="$1"
- local page="$2"
- local printing="$3"
- local mp
-
- mp="${MANPATH:-/usr/man}"
- if [ "$#" -lt 2 ]; then return 1; fi # should print usage
- if [ "$num" != "" ]; then
- sec="${num%%[a-zA-Z]*}"
- else
- sec='[168234571lnpo]'
- num="$sec"
- fi
- for i in $(echo "$mp" | tr : ' '); do
- if [ ! -d "$i" ]; then continue; fi
- file="$i"/man"$sec"/"$page"."$num"*
- set $file
- file="$1"
- if [ -f "$file" ]; then
- zot=$(sed 1q "$file")
- cmd=${MANROFF:-"nroff -man - | col | cat -s"}
- h=${zot##"'"'\"'}
- if [ "$h" != "$zot" ]; then
- while [ "$h" != "" ]; do
- case "$h" in
- *e) cmd="${MANEQN:-neqn} | $cmd";;
- *r) cmd="refer | $cmd";;
- *t) cmd="tbl | $cmd";;
- *v) cmd="vgrind | $cmd";;
- *) ;; # should print error
- esac
- h=${h%?}
- done
- fi
- if [ "$printing" != "" ]; then
- (cd "$i"; eval "$cmd") < "$file" | ${PAGER:-more}
- else
- (cd "$i"; eval "$cmd") < "$file" > /tmp/manpage-$$
- ${PAGER:-more} /tmp/manpage-$$
- rm -f /tmp/manpage-$$
- fi
- break
- fi
- done
-}
-
-function whatis_internal ()
-{
- local j
- for j in $(echo "$MANPATH" | tr : ' '); do
- if [ -f "$j/whatis" ]; then
- eval $2 -i -e "$1" $j/whatis
- fi
- done
-}
-
-function whatis ()
-{
- local name=$(basename "$1")
- whatis_internal "$name" "grep -w"
-}
-
-function apropos ()
-{
- whatis_internal "$1" "grep -F"
-}
-
-# Note: "-" and "-t" together not supported. This man could be
-# made a lot better, but it does everything I want.
-function man ()
-{
- local PAGER printing mpath MANROFF num
- mpath="${MANPATH:-/usr/man}"
- while true; do
- case "$1" in
- -) PAGER=cat
- printing= ;;
- -t)
- MANROFF=${TROFF:-"ptroff -man -t"}
- PAGER="${TCAT:-lpr}"
- printing=yes ;;
- -M)
- mpath="$2"
- shift;;
- *) break;;
- esac
- shift
- done
- local MANPATH="$mpath"
- case "$1" in
- -f | -k)
- local g a
- if [ "$1" = "-f" ]; then
- g="grep -w"
- a=$(basename "$2")
- else
- g="grep -F"
- a="$2"
- fi
- whatis_internal "$a" "$g"
- ;;
- [0-9npol] | [0-9][a-z]* | new | public | old | local)
- if [ "$1" = "new" ]; then
- num=n
- elif [ "$1" = "public" ]; then
- num=p
- elif [ "$1" = "old" ]; then
- num=o
- elif [ "$1" = "local" ]; then
- num=l
- else
- num="$1"
- fi
- shift
- manpage "$num" "$1" "$printing"
- ;;
- *)
- manpage "$num" "$1" "$printing"
- ;;
- esac
-}
diff --git a/examples/functions/mhfold b/examples/functions/mhfold
deleted file mode 100644
index 3c0c743..0000000
--- a/examples/functions/mhfold
+++ /dev/null
@@ -1,16 +0,0 @@
-# To: chet@ins.CWRU.Edu
-# Subject: Bash functions
-# From: Sandeep Mehta <sxm@philabs.Philips.Com>
-
-# print MH folders, useful only because folders(1) doesn't print
-# mod date/times
-
-mhfold()
-{
- list=`folders | awk '{if (1 < NR) print $1}'`
- /bin/ls -lag ~/Mail > /tmp/fold$$
- for i in $list; do
- grep $i /tmp/fold$$
- done
- /bin/rm -f /tmp/fold$$
-}
diff --git a/examples/functions/pathfuncs b/examples/functions/pathfuncs
deleted file mode 100644
index 56fdca3..0000000
--- a/examples/functions/pathfuncs
+++ /dev/null
@@ -1,45 +0,0 @@
-#From: "Simon J. Gerraty" <sjg@zen.void.oz.au>
-#Message-Id: <199510091130.VAA01188@zen.void.oz.au>
-#Subject: Re: a shell idea?
-#Date: Mon, 09 Oct 1995 21:30:20 +1000
-
-
-# NAME:
-# add_path.sh - add dir to path
-#
-# DESCRIPTION:
-# These functions originated in /etc/profile and ksh.kshrc, but
-# are more useful in a separate file.
-#
-# SEE ALSO:
-# /etc/profile
-#
-# AUTHOR:
-# Simon J. Gerraty <sjg@zen.void.oz.au>
-
-# @(#)Copyright (c) 1991 Simon J. Gerraty
-#
-# This file is provided in the hope that it will
-# be of use. There is absolutely NO WARRANTY.
-# Permission to copy, redistribute or otherwise
-# use this file is hereby granted provided that
-# the above copyright notice and this notice are
-# left intact.
-
-# is $1 missing from $2 (or PATH) ?
-no_path() {
- eval "case :\$${2-PATH}: in *:$1:*) return 1;; *) return 0;; esac"
-}
-# if $1 exists and is not in path, append it
-add_path () {
- [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1"
-}
-# if $1 exists and is not in path, prepend it
-pre_path () {
- [ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}"
-}
-# if $1 is in path, remove it
-del_path () {
- no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: |
- sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"`
-}
diff --git a/examples/functions/recurse b/examples/functions/recurse
deleted file mode 100644
index f69cd50..0000000
--- a/examples/functions/recurse
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/bin/bash
-
-#From: kaz@ashi.footprints.net (Kaz Kylheku)
-#Newsgroups: comp.os.linux.misc
-#Subject: Re: bash question: subdirectories
-#Message-ID: <slrn8a0gu9.v5n.kaz@ashi.FootPrints.net>
-#Date: Tue, 08 Feb 2000 16:24:35 GMT
-
-#Actually it can be made to. That is to say, it is possible to code a recursive
-#descender function in the bash language. Here is an example.
-#
-#What is nice about this is that you can embed the function into your shell
-#script. The function changes the current working directory as it descends.
-#So it can handle arbitrarily deep paths. Whereas paths generated by the
-#find command can cause a problem when they get too long; the kernel has a
-#hard limit on the length of the string passed to the open() and other
-#system calls.
-
-#There are races; what if the directory tree is blown away during the traversal?
-#The function won't be able to crawl back up using the .. link and will just
-#bail.
-
-# Recursive Directory Traverser
-# Author: Kaz Kylheku
-# Date: Feb 27, 1999
-# Copyright 1999
-
-# Function parameter usage:
-# $1 directory to search
-# $2 pattern to search for
-# $3 command to execute
-# $4 secret argument for passing down path
-
-function recurse
-{
- local file
- local path
-
- if [ "$4" = "" ] ; then
- path="${1%/}/"
- else
- path="$4$1/"
- fi
-
- if cd "$1" ; then
- for file in $2; do
- if [ -f "$file" ] || [ -d "$file" ]; then
- eval "$3"
- fi
- done
- for file in .* * ; do
- if [ "$file" = "." ] || [ "$file" = ".." ] ; then
- continue
- fi
- if [ -d "$file" ] && [ ! -L "$file" ]; then
- recurse "$file" "$2" "$3" "$path"
- fi
- done
- cd ..
- fi
-}
-
-recurse "$1" "$2" 'echo "$path$file"'
diff --git a/examples/functions/repeat2 b/examples/functions/repeat2
deleted file mode 100644
index 2e2dc7a..0000000
--- a/examples/functions/repeat2
+++ /dev/null
@@ -1,43 +0,0 @@
-# To: chet@ins.CWRU.Edu
-# Subject: Bash functions
-# From: Sandeep Mehta <sxm@philabs.Philips.Com>
-
-##########################################
-#
-# repeat - clone of C shell builtin `repeat'
-#
-# usage: repeat <count> <command>
-#
-# It has been tested inside other functions and in conditionals like
-# if [ "`repeat <count> <command>`" ]; then COMMANDS [ else COMMANDS ] fi
-# Please send me fixes/enhancements.
-#
-# Sandeep Mehta <sxm@philabs.Philips.Com>
-##########################################
-repeat()
-{
- local rcount=$1
-
- if [ $# -le 1 ] || [ -z "$rcount" ]; then
- echo "usage: repeat <count> <command>" 1>&2
- return 2
- fi
-
- shift
-
- local acmd=("$@")
-
- if [ $rcount -le 0 ]; then
- echo "count must be greater than 0"
- echo "usage: repeat <count> <command>" 1>&2
- return 2
- fi
-
- st=0
- while [ $rcount -gt 0 ]; do
- eval "${acmd[@]}"
- st=$?
- rcount=$((rcount - 1))
- done
- return $st
-}
diff --git a/examples/functions/repeat3 b/examples/functions/repeat3
deleted file mode 100644
index 65048bf..0000000
--- a/examples/functions/repeat3
+++ /dev/null
@@ -1,12 +0,0 @@
-# From psamuels@jake.niar.twsu.edu (Peter Samuelson)
-# posted to usenet, Message-ID: <6rtp8j$2a0$1@jake.niar.twsu.edu>
-
-repeat ()
-{
- local i max; # note that you can use \$i in the command string
- max=$1; shift;
-
- i=1; while ((i <= max)); do
- eval "$@"; ((i = i + 1));
- done;
-}
diff --git a/examples/functions/term b/examples/functions/term
deleted file mode 100644
index fbe99f1..0000000
--- a/examples/functions/term
+++ /dev/null
@@ -1,35 +0,0 @@
-#
-# term -- a shell function to set the terminal type interactively or not.
-#
-
-term()
-{
- local t
-
- if [ $# != 0 ] ; then
- eval $(tset -sQ $1)
- else # interactive
- if [ -z "$TERM" ] ; then
- TERM="unknown"
- fi
-
- case "$TERM" in
- network|dialup|unknown|lat)
- TERM=unknown
- ;;
- *)
- eval $(tset -sQ)
- ;;
- esac
-
- while [ "$TERM" = "unknown" ] ; do
- echo -n "Terminal type: "
- read t
- if [ -n "$t" ] ; then
- eval $(tset -sQ $t)
- fi
- done
- fi
-}
-
-
diff --git a/examples/functions/xalias.bash b/examples/functions/xalias.bash
deleted file mode 100644
index 88a00dc..0000000
--- a/examples/functions/xalias.bash
+++ /dev/null
@@ -1,22 +0,0 @@
-# xalias - convert csh alias commands to bash functions
-# from Mohit Aron <aron@cs.rice.edu>
-# posted to usenet as <4i5p17$bnu@larry.rice.edu>
-function xalias ()
-{
- if [ "x$2" = "x" ]
- then
- declare -f $1
- else
- case $2 in
- *[#\!]*)
- comm=$(echo $2 | sed 's/\\!\*/\"$\@\"/g
- s/\\!:\([1-9]\)/\"$\1\"/g
- s/#/\\#/g')
- ;;
- *)
- comm="$2 \"\$@\"" ;;
- esac
-
- eval function $1 \(\) "{" command "$comm" "; }"
- fi
-}
diff --git a/examples/functions/xfind.bash b/examples/functions/xfind.bash
deleted file mode 100644
index 6d29038..0000000
--- a/examples/functions/xfind.bash
+++ /dev/null
@@ -1,52 +0,0 @@
-#! /bin/bash
-#From: kaz@cafe.net (Kaz Kylheku)
-#Newsgroups: comp.unix.shell
-#Subject: Why not roll your own @#$% find! (was: splitting directory off from filename)
-#Message-ID: <6n1117$tp1@espresso.cafe.net>
-#Date: Fri, 26 Jun 1998 20:47:34 GMT
-
-# $1 = dirname, $2 = pattern, optional $3 = action
-xfind()
-{
- local x
- local dir="$1"
-
- # descend into specified directory
-
- builtin cd -L "$1" || {
- echo "${FUNCNAME}: cannot change dir to $1" >&2
- return 1
- }
-
- #
- # default action is to print the filename
- #
- if [ -n "$3" ]; then
- action="$3"
- else
- action='printf -- "%s\n"'
- fi
-
- # process ordinary files that match pattern
-
- for x in $2 ; do
- if [ -f "$x" ] ; then
- eval "$action" "$x"
- fi
- done
-
- # now descend into subdirectories, avoiding symbolic links
- # and directories that start with a period.
-
- for x in * ; do
- if [ -d "$x" ] && [ ! -L "$x" ] ; then
- $FUNCNAME "$x" "$2" "$action"
- fi
- done
-
- # finally, pop back up
-
- builtin cd -L ..
-}
-
-#xfind "$@"