bash-20130308 remove leftover and stray files

This commit is contained in:
Chet Ramey
2013-03-26 20:52:27 -04:00
parent c677e9e0a2
commit e632a17a4f
52 changed files with 0 additions and 43378 deletions
-4749
View File
File diff suppressed because it is too large Load Diff
-82
View File
@@ -1,82 +0,0 @@
Starting bash with the `--posix' command-line option or executing
`set -o posix' while bash is running will cause bash to conform more
closely to the Posix.2 standard by changing the behavior to match that
specified by Posix.2 in areas where the bash default differs.
The following list is what's changed when `posix mode' is in effect:
1. When a command in the hash table no longer exists, bash will re-search
$PATH to find the new location. This is also available with
`shopt -s checkhash'.
2. The >& redirection does not redirect stdout and stderr.
3. The message printed by the job control code and builtins when a job
exits with a non-zero status is `Done(status)'.
4. Reserved words may not be aliased.
5. The Posix.2 PS1 and PS2 expansions of `!' -> history number and
`!!' -> `!' are enabled, and parameter expansion is performed on
the value regardless of the setting of the `promptvars' option.
6. Interactive comments are enabled by default. (Note that bash has
them on by default anyway.)
7. The Posix.2 startup files are executed ($ENV) rather than the normal
bash files.
8. Tilde expansion is only performed on assignments preceding a command
name, rather than on all assignment statements on the line.
9. The default history file is ~/.sh_history (default value of $HISTFILE).
10. The output of `kill -l' prints all the signal names on a single line,
separated by spaces.
11. Non-interactive shells exit if `file' in `. file' is not found.
12. Redirection operators do not perform pathname expansion on the word
in the redirection unless the shell is interactive
13. Function names must be valid shell identifiers. That is, they may not
contain characters other than letters, digits, and underscores, and
may not start with a digit. Declaring a function with an illegal name
causes a fatal syntax error in non-interactive shells.
14. Posix.2 `special' builtins are found before shell functions during command
lookup.
15. If a Posix.2 special builtin returns an error status, a non-interactive
shell exits. The fatal errors are those listed in the POSIX.2 standard,
and include things like passing incorrect options, redirection errors,
variable assignment errors for assignments preceding the command name,
and so on.
16. The environment passed to executed commands is not sorted. Neither is
the output of `set'. This is not strictly Posix.2 behavior, but sh
does it this way. Ksh does not. It's not necessary to sort the
environment; no program should rely on it being sorted.
17. If the `cd' builtin finds a directory to change to using $CDPATH, the
value it assigns to $PWD does not contain any symbolic links, as if
`cd -P' had been executed.
18. A non-interactive shell exits with an error status if a variable
assignment error occurs when no command name follows the assignment
statements. A variable assignment error occurs, for example, when
trying to assign a value to a read-only variable.
19. A non-interactive shell exits with an error status if the iteration
variable in a for statement or the selection variable in a select
statement is a read-only variable.
20. Process substitution is not available.
21. Assignment statements preceding POSIX.2 `special' builtins persist in
the shell environment after the builtin completes.
There is other Posix.2 behavior that bash does not implement. Specifically:
1. Assignment statements affect the execution environment of all builtins,
not just special ones.
-544
View File
@@ -1,544 +0,0 @@
This file is set.def, from which is created set.c.
It implements the "set" and "unset" builtins in Bash.
Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 1, or (at your option) any later
version.
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
$PRODUCES set.c
#include <stdio.h>
#include "../shell.h"
#include "../flags.h"
#include "bashgetopt.h"
extern int interactive;
extern int noclobber, posixly_correct;
#if defined (READLINE)
extern int rl_editing_mode, no_line_editing;
#endif /* READLINE */
$BUILTIN set
$FUNCTION set_builtin
$SHORT_DOC set [--abefhkmnptuvxldBCHP] [-o option] [arg ...]
-a Mark variables which are modified or created for export.
-b Notify of job termination immediately.
-e Exit immediately if a command exits with a non-zero status.
-f Disable file name generation (globbing).
-h Locate and remember function commands as functions are
defined. Function commands are normally looked up when
the function is executed.
-i Force the shell to be an "interactive" one. Interactive shells
always read `~/.bashrc' on startup.
-k All keyword arguments are placed in the environment for a
command, not just those that precede the command name.
-m Job control is enabled.
-n Read commands but do not execute them.
-o option-name
Set the variable corresponding to option-name:
allexport same as -a
braceexpand same as -B
#if defined (READLINE)
emacs use an emacs-style line editing interface
#endif /* READLINE */
errexit same as -e
histexpand same as -H
ignoreeof the shell will not exit upon reading EOF
interactive-comments
allow comments to appear in interactive commands
monitor same as -m
noclobber disallow redirection to existing files
noexec same as -n
noglob same as -f
nohash same as -d
notify save as -b
nounset same as -u
physical same as -P
posix change the behavior of bash where the default
operation differs from the 1003.2 standard to
match the standard
privileged same as -p
verbose same as -v
#if defined (READLINE)
vi use a vi-style line editing interface
#endif /* READLINE */
xtrace same as -x
-p Turned on whenever the real and effective user ids do not match.
Disables processing of the $ENV file and importing of shell
functions. Turning this option off causes the effective uid and
gid to be set to the real uid and gid.
-t Exit after reading and executing one command.
-u Treat unset variables as an error when substituting.
-v Print shell input lines as they are read.
-x Print commands and their arguments as they are executed.
-l Save and restore the binding of the NAME in a FOR command.
-d Disable the hashing of commands that are looked up for execution.
Normally, commands are remembered in a hash table, and once
found, do not have to be looked up again.
#if defined (BRACE_EXPANSION)
-B the shell will perform brace expansion
#endif /* BRACE_EXPANSION */
#if defined (BANG_HISTORY)
-H Enable ! style history substitution. This flag is on
by default.
#endif /* BANG_HISTORY */
-C If set, disallow existing regular files to be overwritten
by redirection of output.
-P If set, do not follow symbolic links when executing commands
such as cd which change the current directory.
Using + rather than - causes these flags to be turned off. The
flags can also be used upon invocation of the shell. The current
set of flags may be found in $-. The remaining n ARGs are positional
parameters and are assigned, in order, to $1, $2, .. $n. If no
ARGs are given, all shell variables are printed.
$END
/* An a-list used to match long options for set -o to the corresponding
option letter. */
struct {
char *name;
int letter;
} o_options[] = {
{ "allexport", 'a' },
#if defined (BRACE_EXPANSION)
{ "braceexpand",'B' },
#endif
{ "errexit", 'e' },
{ "histexpand", 'H' },
{ "monitor", 'm' },
{ "noexec", 'n' },
{ "noglob", 'f' },
{ "nohash", 'd' },
#if defined (JOB_CONTROL)
{ "notify", 'b' },
#endif /* JOB_CONTROL */
{"nounset", 'u' },
{"physical", 'P' },
{"privileged", 'p' },
{"verbose", 'v' },
{"xtrace", 'x' },
{(char *)NULL, 0},
};
#define MINUS_O_FORMAT "%-15s\t%s\n"
void
list_minus_o_opts ()
{
register int i;
char *on = "on", *off = "off";
printf (MINUS_O_FORMAT, "noclobber", (noclobber == 1) ? on : off);
if (find_variable ("ignoreeof") || find_variable ("IGNOREEOF"))
printf (MINUS_O_FORMAT, "ignoreeof", on);
else
printf (MINUS_O_FORMAT, "ignoreeof", off);
printf (MINUS_O_FORMAT, "interactive-comments",
interactive_comments ? on : off);
printf (MINUS_O_FORMAT, "posix", posixly_correct ? on : off);
#if defined (READLINE)
if (no_line_editing)
{
printf (MINUS_O_FORMAT, "emacs", off);
printf (MINUS_O_FORMAT, "vi", off);
}
else
{
/* Magic. This code `knows' how readline handles rl_editing_mode. */
printf (MINUS_O_FORMAT, "emacs", (rl_editing_mode == 1) ? on : off);
printf (MINUS_O_FORMAT, "vi", (rl_editing_mode == 0) ? on : off);
}
#endif /* READLINE */
for (i = 0; o_options[i].name; i++)
{
int *on_or_off, zero = 0;
on_or_off = find_flag (o_options[i].letter);
if (on_or_off == FLAG_UNKNOWN)
on_or_off = &zero;
printf (MINUS_O_FORMAT, o_options[i].name, (*on_or_off == 1) ? on : off);
}
}
set_minus_o_option (on_or_off, option_name)
int on_or_off;
char *option_name;
{
int option_char = -1;
if (STREQ (option_name, "noclobber"))
{
if (on_or_off == FLAG_ON)
bind_variable ("noclobber", "");
else
unbind_variable ("noclobber");
stupidly_hack_special_variables ("noclobber");
}
else if (STREQ (option_name, "ignoreeof"))
{
unbind_variable ("ignoreeof");
unbind_variable ("IGNOREEOF");
if (on_or_off == FLAG_ON)
bind_variable ("IGNOREEOF", "10");
stupidly_hack_special_variables ("IGNOREEOF");
}
#if defined (READLINE)
else if ((STREQ (option_name, "emacs")) || (STREQ (option_name, "vi")))
{
if (on_or_off == FLAG_ON)
{
rl_variable_bind ("editing-mode", option_name);
if (interactive)
with_input_from_stdin ();
no_line_editing = 0;
}
else
{
int isemacs = (rl_editing_mode == 1);
if ((isemacs && STREQ (option_name, "emacs")) ||
(!isemacs && STREQ (option_name, "vi")))
{
if (interactive)
with_input_from_stream (stdin, "stdin");
no_line_editing = 1;
}
else
builtin_error ("not in %s editing mode", option_name);
}
}
#endif /* READLINE */
else if (STREQ (option_name, "interactive-comments"))
interactive_comments = (on_or_off == FLAG_ON);
else if (STREQ (option_name, "posix"))
{
posixly_correct = (on_or_off == FLAG_ON);
unbind_variable ("POSIXLY_CORRECT");
unbind_variable ("POSIX_PEDANTIC");
if (on_or_off == FLAG_ON)
{
bind_variable ("POSIXLY_CORRECT", "");
stupidly_hack_special_variables ("POSIXLY_CORRECT");
}
}
else
{
register int i;
for (i = 0; o_options[i].name; i++)
{
if (STREQ (option_name, o_options[i].name))
{
option_char = o_options[i].letter;
break;
}
}
if (option_char == -1)
{
builtin_error ("%s: unknown option name", option_name);
return (EXECUTION_FAILURE);
}
if (change_flag (option_char, on_or_off) == FLAG_ERROR)
{
bad_option (option_name);
return (EXECUTION_FAILURE);
}
}
return (EXECUTION_SUCCESS);
}
/* Set some flags from the word values in the input list. If LIST is empty,
then print out the values of the variables instead. If LIST contains
non-flags, then set $1 - $9 to the successive words of LIST. */
set_builtin (list)
WORD_LIST *list;
{
int on_or_off, flag_name, force_assignment = 0;
if (!list)
{
SHELL_VAR **vars;
vars = all_shell_variables ();
if (vars)
{
print_var_list (vars);
free (vars);
}
vars = all_shell_functions ();
if (vars)
{
print_var_list (vars);
free (vars);
}
return (EXECUTION_SUCCESS);
}
/* Check validity of flag arguments. */
if (*list->word->word == '-' || *list->word->word == '+')
{
register char *arg;
WORD_LIST *save_list = list;
while (list && (arg = list->word->word))
{
char c;
if (arg[0] != '-' && arg[0] != '+')
break;
/* `-' or `--' signifies end of flag arguments. */
if (arg[0] == '-' &&
(!arg[1] || (arg[1] == '-' && !arg[2])))
break;
while (c = *++arg)
{
if (find_flag (c) == FLAG_UNKNOWN && c != 'o')
{
char s[2];
s[0] = c; s[1] = '\0';
bad_option (s);
if (c == '?')
builtin_usage ();
return (c == '?' ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
}
}
list = list->next;
}
list = save_list;
}
/* Do the set command. While the list consists of words starting with
'-' or '+' treat them as flags, otherwise, start assigning them to
$1 ... $n. */
while (list)
{
char *string = list->word->word;
/* If the argument is `--' or `-' then signal the end of the list
and remember the remaining arguments. */
if (string[0] == '-' && (!string[1] || (string[1] == '-' && !string[2])))
{
list = list->next;
/* `set --' unsets the positional parameters. */
if (string[1] == '-')
force_assignment = 1;
/* Until told differently, the old shell behaviour of
`set - [arg ...]' being equivalent to `set +xv [arg ...]'
stands. Posix.2 says the behaviour is marked as obsolescent. */
else
{
change_flag ('x', '+');
change_flag ('v', '+');
}
break;
}
if ((on_or_off = *string) &&
(on_or_off == '-' || on_or_off == '+'))
{
int i = 1;
while (flag_name = string[i++])
{
if (flag_name == '?')
{
builtin_usage ();
return (EXECUTION_SUCCESS);
}
else if (flag_name == 'o') /* -+o option-name */
{
char *option_name;
WORD_LIST *opt;
opt = list->next;
if (!opt)
{
list_minus_o_opts ();
continue;
}
option_name = opt->word->word;
if (!option_name || !*option_name || (*option_name == '-'))
{
list_minus_o_opts ();
continue;
}
list = list->next; /* Skip over option name. */
if (set_minus_o_option (on_or_off, option_name) != EXECUTION_SUCCESS)
return (EXECUTION_FAILURE);
}
else
{
if (change_flag (flag_name, on_or_off) == FLAG_ERROR)
{
char opt[3];
opt[0] = on_or_off;
opt[1] = flag_name;
opt[2] = '\0';
bad_option (opt);
builtin_usage ();
return (EXECUTION_FAILURE);
}
}
}
}
else
{
break;
}
list = list->next;
}
/* Assigning $1 ... $n */
if (list || force_assignment)
remember_args (list, 1);
return (EXECUTION_SUCCESS);
}
$BUILTIN unset
$FUNCTION unset_builtin
$SHORT_DOC unset [-f] [-v] [name ...]
For each NAME, remove the corresponding variable or function. Given
the `-v', unset will only act on variables. Given the `-f' flag,
unset will only act on functions. With neither flag, unset first
tries to unset a variable, and if that fails, then tries to unset a
function. Some variables (such as PATH and IFS) cannot be unset; also
see readonly.
$END
#define NEXT_VARIABLE() any_failed++; list = list->next; continue;
unset_builtin (list)
WORD_LIST *list;
{
int unset_function, unset_variable, unset_array, opt, any_failed;
char *name;
unset_function = unset_variable = unset_array = any_failed = 0;
reset_internal_getopt ();
while ((opt = internal_getopt (list, "fv")) != -1)
{
switch (opt)
{
case 'f':
unset_function = 1;
break;
case 'v':
unset_variable = 1;
break;
default:
builtin_usage ();
return (EXECUTION_FAILURE);
}
}
list = loptend;
if (unset_function && unset_variable)
{
builtin_error ("cannot simultaneously unset a function and a variable");
return (EXECUTION_FAILURE);
}
while (list)
{
SHELL_VAR *var;
int tem;
#if defined (ARRAY_VARS)
char *t;
#endif
name = list->word->word;
#if defined (ARRAY_VARS)
if (!unset_function && valid_array_reference (name))
{
t = strchr (name, '[');
*t++ = '\0';
unset_array++;
}
#endif
var = unset_function ? find_function (name) : find_variable (name);
if (var && !unset_function && non_unsettable_p (var))
{
builtin_error ("%s: cannot unset", name);
NEXT_VARIABLE ();
}
/* Posix.2 says that unsetting readonly variables is an error. */
if (var && readonly_p (var))
{
builtin_error ("%s: cannot unset: readonly %s",
name, unset_function ? "function" : "variable");
NEXT_VARIABLE ();
}
/* Unless the -f option is supplied, the name refers to a variable. */
#if defined (ARRAY_VARS)
if (var && unset_array)
{
if (array_p (var) == 0)
{
builtin_error ("%s: not an array variable", name);
NEXT_VARIABLE ();
}
else
tem = unbind_array_element (var, t);
}
else
#endif /* ARRAY_VARS */
tem = makunbound (name, unset_function ? shell_functions : shell_variables);
/* This is what Posix.2 draft 11+ says. ``If neither -f nor -v
is specified, the name refers to a variable; if a variable by
that name does not exist, a function by that name, if any,
shall be unset.'' */
if ((tem == -1) && !unset_function && !unset_variable)
tem = makunbound (name, shell_functions);
if (tem == -1)
any_failed++;
else if (!unset_function)
stupidly_hack_special_variables (name);
list = list->next;
}
if (any_failed)
return (EXECUTION_FAILURE);
else
return (EXECUTION_SUCCESS);
}
-50
View File
@@ -1,50 +0,0 @@
/* unwind_prot.h - Macros and functions for hacking unwind protection. */
/* Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#if !defined (_UNWIND_PROT_H)
#define _UNWIND_PROT_H
/* Run a function without interrupts. */
extern void begin_unwind_frame ();
extern void discard_unwind_frame ();
extern void run_unwind_frame ();
extern void add_unwind_protect ();
extern void remove_unwind_protect ();
extern void run_unwind_protects ();
extern void unwind_protect_var ();
/* Define for people who like their code to look a certain way. */
#define end_unwind_frame()
/* How to protect an integer. */
#define unwind_protect_int(X) unwind_protect_var (&(X), (char *)(X), sizeof (int))
/* How to protect a pointer to a string. */
#define unwind_protect_string(X) \
unwind_protect_var ((int *)&(X), (X), sizeof (char *))
/* How to protect any old pointer. */
#define unwind_protect_pointer(X) unwind_protect_string (X)
/* How to protect the contents of a jmp_buf. */
#define unwind_protect_jmp_buf(X) \
unwind_protect_var ((int *)(X), (char *)(X), sizeof (procenv_t))
#endif /* _UNWIND_PROT_H */
-1244
View File
File diff suppressed because it is too large Load Diff
Vendored
-4195
View File
File diff suppressed because it is too large Load Diff
-4151
View File
File diff suppressed because it is too large Load Diff
-42
View File
@@ -1,42 +0,0 @@
# This file is a shell script that caches the results of configure
# tests for CYGWIN32 so they don't need to be done when cross-compiling.
# AC_FUNC_GETPGRP should also define GETPGRP_VOID
ac_cv_func_getpgrp_void=${ac_cv_func_getpgrp_void='yes'}
# AC_FUNC_SETVBUF_REVERSED should not define anything else
ac_cv_func_setvbuf_reversed=${ac_cv_func_setvbuf_reversed='no'}
# on CYGWIN32, system calls do not restart
ac_cv_sys_restartable_syscalls=${ac_cv_sys_restartable_syscalls='no'}
bash_cv_sys_restartable_syscalls=${bash_cv_sys_restartable_syscalls='no'}
# these may be necessary, but they are currently commented out
#ac_cv_c_bigendian=${ac_cv_c_bigendian='no'}
ac_cv_sizeof_char_p=${ac_cv_sizeof_char_p='4'}
ac_cv_sizeof_int=${ac_cv_sizeof_int='4'}
ac_cv_sizeof_long=${ac_cv_sizeof_long='4'}
ac_cv_sizeof_double=${ac_cv_sizeof_double='8'}
bash_cv_dup2_broken=${bash_cv_dup2_broken='no'}
bash_cv_pgrp_pipe=${bash_cv_pgrp_pipe='no'}
bash_cv_type_rlimit=${bash_cv_type_rlimit='long'}
bash_cv_decl_under_sys_siglist=${bash_cv_decl_under_sys_siglist='no'}
bash_cv_under_sys_siglist=${bash_cv_under_sys_siglist='no'}
bash_cv_sys_siglist=${bash_cv_sys_siglist='no'}
bash_cv_opendir_not_robust=${bash_cv_opendir_not_robust='no'}
bash_cv_getenv_redef=${bash_cv_getenv_redef='yes'}
bash_cv_printf_declared=${bash_cv_printf_declared='yes'}
bash_cv_ulimit_maxfds=${bash_cv_ulimit_maxfds='no'}
bash_cv_getcwd_calls_popen=${bash_cv_getcwd_calls_popen='no'}
bash_cv_must_reinstall_sighandlers=${bash_cv_must_reinstall_sighandlers='no'}
bash_cv_job_control_missing=${bash_cv_job_control_missing='present'}
bash_cv_sys_named_pipes=${bash_cv_sys_named_pipes='missing'}
bash_cv_func_sigsetjmp=${bash_cv_func_sigsetjmp='missing'}
bash_cv_mail_dir=${bash_cv_mail_dir='unknown'}
bash_cv_func_strcoll_broken=${bash_cv_func_strcoll_broken='no'}
bash_cv_type_int32_t=${bash_cv_type_int32_t='int'}
bash_cv_type_u_int32_t=${bash_cv_type_u_int32_t='int'}
ac_cv_type_bits64_t=${ac_cv_type_bits64_t='no'}
# end of cross-build/cygwin32.cache
-1745
View File
File diff suppressed because it is too large Load Diff
-10293
View File
File diff suppressed because it is too large Load Diff
-8701
View File
File diff suppressed because it is too large Load Diff
-10
View File
@@ -1,10 +0,0 @@
@ignore
Copyright (C) 1988-2013 Free Software Foundation, Inc.
@end ignore
@set LASTCHANGE Sat Mar 2 20:26:13 EST 2013
@set EDITION 4.2
@set VERSION 4.2
@set UPDATED 2 March 2013
@set UPDATED-MONTH March 2013
-55
View File
@@ -1,55 +0,0 @@
# based on the cd completion function from the bash_completion package
_comp_cd()
{
local IFS=$' \t\n' # normalize IFS
local cur _skipdot _cdpath
local i j k
# Tilde expansion, with side effect of expanding tilde to full pathname
case "$2" in
\~*) eval cur="$2" ;;
*) cur=$2 ;;
esac
# no cdpath or absolute pathname -- straight directory completion
if [[ -z "${CDPATH:-}" ]] || [[ "$cur" == @(./*|../*|/*) ]]; then
# compgen prints paths one per line; could also use while loop
IFS=$'\n'
COMPREPLY=( $(compgen -d -- "$cur") )
IFS=$' \t\n'
# CDPATH+directories in the current directory if not in CDPATH
else
IFS=$'\n'
_skipdot=false
# preprocess CDPATH to convert null directory names to .
_cdpath=${CDPATH/#:/.:}
_cdpath=${_cdpath//::/:.:}
_cdpath=${_cdpath/%:/:.}
for i in ${_cdpath//:/$'\n'}; do
if [[ $i -ef . ]]; then _skipdot=true; fi
k="${#COMPREPLY[@]}"
for j in $( compgen -d -- "$i/$cur" ); do
COMPREPLY[k++]=${j#$i/} # cut off directory
done
done
$_skipdot || COMPREPLY+=( $(compgen -d -- "$cur") )
IFS=$' \t\n'
fi
# variable names if appropriate shell option set and no completions
if shopt -q cdable_vars && [[ ${#COMPREPLY[@]} -eq 0 ]]; then
COMPREPLY=( $(compgen -v -- "$cur") )
fi
# append slash to passed directory name that is the only completion.
# readline will not do this if we complete from CDPATH
if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
i=${COMPREPLY[0]} # shorthand
if [[ "$cur" == "$i" ]] && [[ "$i" != "*/" ]]; then
COMPREPLY[0]+=/
fi
fi
return 0
}
complete -o filenames -o nospace -o bashdefault -F _comp_cd cd
-495
View File
@@ -1,495 +0,0 @@
#
# Completion examples
#
#
# This encapsulates the default bash completion code
# call with the word to be completed as $1
#
# Since programmable completion does not use the bash default completions
# or the readline default of filename completion when the compspec does
# not generate any matches, this may be used as a `last resort' in a
# completion function to mimic the default bash completion behavior.
#
_bash_def_completion ()
{
local h t
COMPREPLY=()
# command substitution
if [[ "$1" == \$\(* ]]; then
t=${1#??}
COMPREPLY=( $(compgen -c -P '$(' $t) )
fi
# variables with a leading `${'
if [ ${#COMPREPLY[@]} -eq 0 ] && [[ "$1" == \$\{* ]]; then
t=${1#??}
COMPREPLY=( $(compgen -v -P '${' -S '}' $t) )
fi
# variables with a leading `$'
if [ ${#COMPREPLY[@]} -eq 0 ] && [[ "$1" == \$* ]]; then
t=${1#?}
COMPREPLY=( $(compgen -v -P '$' $t ) )
fi
# username expansion
if [ ${#COMPREPLY[@]} -eq 0 ] && [[ "$1" == ~* ]] && [[ "$1" != */* ]]; then
t=${1#?}
COMPREPLY=( $( compgen -u -P '~' $t ) )
fi
# hostname
if [ ${#COMPREPLY[@]} -eq 0 ] && [[ "$1" == *@* ]]; then
h=${1%%@*}
t=${1#*@}
COMPREPLY=( $( compgen -A hostname -P "${h}@" $t ) )
fi
# glob pattern
if [ ${#COMPREPLY[@]} -eq 0 ]; then
# sh-style glob pattern
if [[ $1 == *[*?[]* ]]; then
COMPREPLY=( $( compgen -G "$1" ) )
# ksh-style extended glob pattern - must be complete
elif shopt -q extglob && [[ $1 == *[?*+\!@]\(*\)* ]]; then
COMPREPLY=( $( compgen -G "$1" ) )
fi
fi
# final default is filename completion
if [ ${#COMPREPLY[@]} -eq 0 ]; then
COMPREPLY=( $(compgen -f "$1" ) )
fi
}
#
# Return 1 if $1 appears to contain a redirection operator. Handles backslash
# quoting (barely).
#
_redir_op()
{
case "$1" in
*\\'[\<\>]'*) return 1;;
*[\<\>]*) return 0;;
*) return 1;;
esac
}
# _redir_test tests the current word ($1) and the previous word ($2) for
# redirection operators and does filename completion on the current word
# if either one contains a redirection operator
_redir_test()
{
if _redir_op "$1" ; then
COMPREPLY=( $( compgen -f "$1" ) )
return 0
elif _redir_op "$2" ; then
COMPREPLY=( $( compgen -f "$1" ) )
return 0
fi
return 1
}
# optional, but without this you can't use extended glob patterns
shopt -s extglob
#
# Easy ones for the shell builtins
#
# nothing for: alias, break, continue, dirs, echo, eval, exit, getopts,
# let, logout, popd, printf, pwd, return, shift, suspend, test, times,
# umask
#
complete -f -- . source
complete -A enabled builtin
complete -d cd
# this isn't exactly right yet -- needs to skip shell functions and
# do $PATH lookup (or do compgen -c and filter out matches that also
# appear in compgen -A function)
complete -c command
# could add -S '=', but that currently screws up because readline appends
# a space unconditionally
complete -v export local readonly
complete -A helptopic help # currently same as builtins
complete -d pushd
complete -A shopt shopt
complete -c type
complete -a unalias
complete -v unset
#
# Job control builtins: fg, bg, disown, kill, wait
# kill not done yet
#
complete -A stopped -P '%' bg
complete -j -P '%' fg jobs disown
# this is not quite right at this point
_wait_func ()
{
local cur
cur=${COMP_WORDS[COMP_CWORD]}
case "$cur" in
%*) COMPREPLY=( $(compgen -A running -P '%' ${cur#?} ) ) ;;
[0-9]*) COMPREPLY=( $(jobs -p | grep ^${cur}) ) ;;
*) COMPREPLY=( $(compgen -A running -P '%') $(jobs -p) )
;;
esac
}
complete -F _wait_func wait
#
# more complicated things, several as yet unimplemented
#
#complete -F _bind_func bind
_declare_func()
{
local cur prev nflag opts
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
COMPREPLY=()
if (( $COMP_CWORD <= 1 )) || [[ $cur == '-' ]]; then
COMPREPLY=(-a -f -F -i -p -r -t -x)
return 0;
fi
if [[ $cur == '+' ]]; then
COMPREPLY=(+i +t +x)
return 0;
fi
if [[ $prev == '-p' ]]; then
COMPREPLY=( $(compgen -v $cur) )
return 0;
fi
return 1
}
complete -F _declare_func declare typeset
_enable_func()
{
local cur prev nflag opts
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
COMPREPLY=()
if (( $COMP_CWORD <= 1 )) || [[ $cur == '-' ]]; then
COMPREPLY=(-a -d -f -n -p -s)
return 0;
fi
if [[ $prev == '-f' ]]; then
COMPREPLY=( $( compgen -f $cur ) )
return 0;
fi
for opts in "${COMP_WORDS[@]}" ; do
if [[ $opts == -*n* ]]; then nflag=1; fi
done
if [ -z "$nflag" ] ; then
COMPREPLY=( $( compgen -A enabled $cur ) )
else
COMPREPLY=( $( compgen -A disabled $cur ) )
fi
return 0;
}
complete -F _enable_func enable
_exec_func()
{
local cur prev
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if (( $COMP_CWORD <= 1 )) || [[ $cur == '-' ]]; then
COMPREPLY=(-a -c -l)
return 0;
fi
if [[ $prev != -*a* ]]; then
COMPREPLY=( $( compgen -c $cur ) )
return 0
fi
return 1;
}
complete -F _exec_func exec
_fc_func()
{
local cur prev
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if (( $COMP_CWORD <= 1 )) || [[ $cur == '-' ]]; then
COMPREPLY=(-e -n -l -r -s)
return 0;
fi
if [[ $prev == -*e ]]; then
COMPREPLY=( $(compgen -c $cur) )
return 0
fi
return 1
}
complete -F _fc_func fc
_hash_func()
{
local cur prev
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if (( $COMP_CWORD <= 1 )) || [[ $cur == '-' ]]; then
COMPREPLY=(-p -r -t)
return 0;
fi
if [[ $prev == '-p' ]]; then
COMPREPLY=( $( compgen -f $cur ) )
return 0;
fi
COMPREPLY=( $( compgen -c $cur ) )
return 0
}
complete -F _hash_func hash
_history_func()
{
local cur prev
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
COMPREPLY=()
if (( $COMP_CWORD <= 1 )) || [[ $cur == '-' ]]; then
COMPREPLY=(-a -c -d -n -r -w -p -s)
return 0;
fi
if [[ $prev == -[anrw] ]]; then
COMPREPLY=( $( compgen -f $cur ) )
fi
return 0
}
complete -F _history_func history
#complete -F _read_func read
_set_func ()
{
local cur prev
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
COMPREPLY=()
_redir_test "$cur" "$prev" && return 0;
if (( $COMP_CWORD <= 1 )) || [[ $cur == '-' ]]; then
COMPREPLY=(-a -b -e -f -k -m -n -o -p -t -u -v -x -B -C -H -P --)
return 0;
fi
if [[ $cur == '+' ]]; then
COMPREPLY=(+a +b +e +f +k +m +n +o +p +t +u +v +x +B +C +H +P)
return 0;
fi
if [[ $prev == [+-]o ]]; then
COMPREPLY=( $(compgen -A setopt $cur) )
return 0;
fi
return 1;
}
complete -F _set_func set
_trap_func ()
{
local cur
cur=${COMP_WORDS[COMP_CWORD]}
if (( $COMP_CWORD <= 1 )) || [[ $cur == '-' ]]; then
COMPREPLY=(-l -p)
return 0;
fi
COMPREPLY=( $( compgen -A signal ${cur}) )
return 0
}
complete -F _trap_func trap
#
# meta-completion (completion for complete/compgen)
#
_complete_meta_func()
{
local cur prev cmd
COMPREPLY=()
cmd=$1
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
_redir_test "$cur" "$prev" && return 0;
if (( $COMP_CWORD <= 1 )) || [[ "$cur" == '-' ]]; then
case "$cmd" in
complete) COMPREPLY=(-a -b -c -d -e -f -j -k -s -v -u -r -p -A -G -W -P -S -X -F -C);;
compgen) COMPREPLY=(-a -b -c -d -e -f -j -k -s -v -u -A -G -W -P -S -X -F -C);;
esac
return 0
fi
if [[ $prev == -A ]]; then
COMPREPLY=(alias arrayvar binding builtin command directory \
disabled enabled export file 'function' helptopic hostname job keyword \
running service setopt shopt signal stopped variable)
return 0
elif [[ $prev == -F ]]; then
COMPREPLY=( $( compgen -A function $cur ) )
elif [[ $prev == -C ]]; then
COMPREPLY=( $( compgen -c $cur ) )
else
COMPREPLY=( $( compgen -c $cur ) )
fi
return 0
}
complete -F _complete_meta_func complete compgen
#
# some completions for shell reserved words
#
#complete -c -k time do if then else elif '{'
#
# external commands
#
complete -e printenv
complete -c nohup exec nice eval trace truss strace sotruss gdb
_make_targets ()
{
local mdef makef gcmd cur prev i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# if prev argument is -f, return possible filename completions.
# we could be a little smarter here and return matches against
# `makefile Makefile *.mk', whatever exists
case "$prev" in
-*f) COMPREPLY=( $(compgen -f $cur ) ); return 0;;
esac
# if we want an option, return the possible posix options
case "$cur" in
-) COMPREPLY=(-e -f -i -k -n -p -q -r -S -s -t); return 0;;
esac
# make reads `makefile' before `Makefile'
# GNU make reads `GNUmakefile' before all other makefiles, but we
# check that we're completing `gmake' before checking for it
if [ -f GNUmakefile ] && [ ${COMP_WORDS[0]} == gmake ]; then
mdef=GNUmakefile
elif [ -f makefile ]; then
mdef=makefile
elif [ -f Makefile ]; then
mdef=Makefile
else
mdef=*.mk # local convention
fi
# before we scan for targets, see if a makefile name was specified
# with -f
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
if [[ ${COMP_WORDS[i]} == -*f ]]; then
eval makef=${COMP_WORDS[i+1]} # eval for tilde expansion
break
fi
done
[ -z "$makef" ] && makef=$mdef
# if we have a partial word to complete, restrict completions to
# matches of that word
if [ -n "$2" ]; then gcmd='grep "^$2"' ; else gcmd=cat ; fi
# if we don't want to use *.mk, we can take out the cat and use
# test -f $makef and input redirection
COMPREPLY=( $(cat $makef 2>/dev/null | awk 'BEGIN {FS=":"} /^[^.# ][^=]*:/ {print $1}' | tr -s ' ' '\012' | sort -u | eval $gcmd ) )
}
complete -F _make_targets -X '+($*|*.[cho])' make gmake pmake
_umount_func ()
{
COMPREPLY=( $(mount | awk '{print $1}') )
}
complete -F _umount_func umount
_configure_func ()
{
case "$2" in
-*) ;;
*) return ;;
esac
case "$1" in
\~*) eval cmd=$1 ;;
*) cmd="$1" ;;
esac
COMPREPLY=( $("$cmd" --help | awk '{if ($1 ~ /--.*/) print $1}' | grep ^"$2" | sort -u) )
}
complete -F _configure_func configure
complete -W '"${GROUPS[@]}"' newgrp
complete -f chown ln more cat
complete -d mkdir rmdir
complete -f strip
complete -f -X '*.gz' gzip
complete -f -X '*.bz2' bzip2
complete -f -X '*.Z' compress
complete -f -X '!*.+(gz|tgz|Gz)' gunzip gzcat zcat zmore
complete -f -X '!*.Z' uncompress zmore zcat
complete -f -X '!*.bz2' bunzip2 bzcat
complete -f -X '!*.zip' unzip
complete -f -X '!*.+(gif|jpg|jpeg|GIF|JPG|JPEG|bmp)' xv
complete -f -X '!*.pl' perl perl5
complete -A hostname rsh telnet rlogin ftp ping xping host traceroute nslookup
complete -A hostname rxterm rxterm3 rxvt2
complete -u su
complete -g newgrp groupdel groupmod
complete -f -X '!*.+(ps|PS)' gs gv ghostview psselect pswrap
complete -f -X '!*.+(dvi|DVI)' dvips xdvi dviselect dvitype catdvi
complete -f -X '!*.+(pdf|PDF)' acroread4
complete -f -X '!*.texi*' makeinfo texi2dvi texi2html
complete -f -X '!*.+(tex|TEX)' tex latex slitex
complete -f -X '!*.+(mp3|MP3)' mpg123
complete -f -X '!*.+(htm|html)' links w3m lynx
#
# other possibilities, left as exercises
#
#complete -F _find_func find
#complete -F _man_func man
#complete -F _stty_func stty
-50
View File
@@ -1,50 +0,0 @@
# from zsh, just for testing
complete -A stopped -P '%' bg
complete -j -P '%' fg jobs disown
# this is wrong at this point
complete -j -P '%' -W '$(ps -x | tail +2 | cut -c1-5)' wait
complete -c type
complete -a unalias
complete -v getopts read unset
complete -v -S '=' declare export local readonly typeset
complete -f -- . source
complete -A shopt shopt
complete -e printenv
complete -A helptopic help
complete -c nohup exec nice eval
complete -c -k time
complete -A signal trap kill
complete -f chown ln more cat
complete -d mkdir rmdir
complete -f -X '!*.+(gz|tgz)' gunzip gzcat zcat zmore
complete -f -X '!*.Z' uncompress zmore zcat
complete -f gzip
complete -d cd pushd popd
complete -A hostname rsh telnet rlogin ftp
complete -u su
complete -W '"${GROUPS[@]}"' newgrp
complete -g groupdel groupmod
complete -f -X '!*.+(ps|PS)' gs gv ghostview
complete -f -X '!*.dvi' dvips xdvi
complete -f -X '!*.pdf' acroread
complete -f -X '!*.texi*' makeinfo texi2dvi texi2html
complete -c gdb make
complete -p gs
complete -p
complete -r xdvi
complete -r notthere
complete -r
complete
-76
View File
@@ -1,76 +0,0 @@
# cdfunc - example completion function for cd
#
# based on the cd completion function from the bash_completion package
#
# Chet Ramey <chet.ramey@case.edu>
#
# Copyright 2011 Chester Ramey
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# TThis program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
_comp_cd()
{
local IFS=$' \t\n' # normalize IFS
local cur _skipdot _cdpath
local i j k
# Tilde expansion, with side effect of expanding tilde to full pathname
case "$2" in
\~*) eval cur="$2" ;;
*) cur=$2 ;;
esac
# no cdpath or absolute pathname -- straight directory completion
if [[ -z "${CDPATH:-}" ]] || [[ "$cur" == @(./*|../*|/*) ]]; then
# compgen prints paths one per line; could also use while loop
IFS=$'\n'
COMPREPLY=( $(compgen -d -- "$cur") )
IFS=$' \t\n'
# CDPATH+directories in the current directory if not in CDPATH
else
IFS=$'\n'
_skipdot=false
# preprocess CDPATH to convert null directory names to .
_cdpath=${CDPATH/#:/.:}
_cdpath=${_cdpath//::/:.:}
_cdpath=${_cdpath/%:/:.}
for i in ${_cdpath//:/$'\n'}; do
if [[ $i -ef . ]]; then _skipdot=true; fi
k="${#COMPREPLY[@]}"
for j in $( compgen -d -- "$i/$cur" ); do
COMPREPLY[k++]=${j#$i/} # cut off directory
done
done
$_skipdot || COMPREPLY+=( $(compgen -d -- "$cur") )
IFS=$' \t\n'
fi
# variable names if appropriate shell option set and no completions
if shopt -q cdable_vars && [[ ${#COMPREPLY[@]} -eq 0 ]]; then
COMPREPLY=( $(compgen -v -- "$cur") )
fi
# append slash to passed directory name that is the only completion.
# readline will not do this if we complete from CDPATH
if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
i=${COMPREPLY[0]} # shorthand
if [[ "$cur" == "$i" ]] && [[ "$i" != "*/" ]]; then
COMPREPLY[0]+=/
fi
fi
return 0
}
complete -o filenames -o nospace -o bashdefault -F _comp_cd cd
-103
View File
@@ -1,103 +0,0 @@
# usage: reverse arrayname
reverse()
{
local -a R
local -i i
local rlen temp
# make r a copy of the array whose name is passed as an arg
eval R=\( \"\$\{$1\[@\]\}\" \)
# reverse R
rlen=${#R[@]}
for ((i=0; i < rlen/2; i++ ))
do
temp=${R[i]}
R[i]=${R[rlen-i-1]}
R[rlen-i-1]=$temp
done
# and assign R back to array whose name is passed as an arg
eval $1=\( \"\$\{R\[@\]\}\" \)
}
A=(1 2 3 4 5 6 7)
echo "${A[@]}"
reverse A
echo "${A[@]}"
reverse A
echo "${A[@]}"
# unset last element of A
alen=${#A[@]}
unset A[$alen-1]
echo "${A[@]}"
# ashift -- like shift, but for arrays
ashift()
{
local -a R
local n
case $# in
1) n=1 ;;
2) n=$2 ;;
*) echo "$FUNCNAME: usage: $FUNCNAME array [count]" >&2
exit 2;;
esac
# make r a copy of the array whose name is passed as an arg
eval R=\( \"\$\{$1\[@\]\}\" \)
# shift R
R=( "${R[@]:$n}" )
# and assign R back to array whose name is passed as an arg
eval $1=\( \"\$\{R\[@\]\}\" \)
}
ashift A 2
echo "${A[@]}"
ashift A
echo "${A[@]}"
ashift A 7
echo "${A[@]}"
# Sort the members of the array whose name is passed as the first non-option
# arg. If -u is the first arg, remove duplicate array members.
array_sort()
{
local -a R
local u
case "$1" in
-u) u=-u ; shift ;;
esac
if [ $# -eq 0 ]; then
echo "array_sort: argument expected" >&2
return 1
fi
# make r a copy of the array whose name is passed as an arg
eval R=\( \"\$\{$1\[@\]\}\" \)
# sort R
R=( $( printf "%s\n" "${A[@]}" | sort $u) )
# and assign R back to array whose name is passed as an arg
eval $1=\( \"\$\{R\[@\]\}\" \)
return 0
}
A=(3 1 4 1 5 9 2 6 5 3 2)
array_sort A
echo "${A[@]}"
A=(3 1 4 1 5 9 2 6 5 3 2)
array_sort -u A
echo "${A[@]}"
-59
View File
@@ -1,59 +0,0 @@
#
# A function that works as a front end for both stty and the `bind'
# builtin, so the tty driver and readline see the same changes
#
#
# Convert between the stty ^H control character form and the readline \C-H
# form
#
cvt()
{
echo "$@" | cat -v | sed 's/\^/\\C-/'
}
#
# stty front-end. Parses the argument list and creates two command strings,
# one for stty, another for bind.
#
fstty()
{
local cmd="" bargs=""
local e
while [ $# -gt 0 ]
do
case "$1" in
-a) cmd="$cmd everything"
;;
erase) shift;
e=$(cvt "$1")
cmd="$cmd erase $1"
bargs="$bargs '\"$e\": backward-delete-char'"
;;
kill) shift
e=$(cvt "$1")
cmd="$cmd kill $1"
bargs="$bargs '\"$e\": unix-line-discard'"
;;
werase) shift;
e=$(cvt "$1")
cmd="$cmd erase $1"
bargs="$bargs '\"$e\": backward-kill-word'"
;;
lnext) shift;
e=$(cvt "$1")
cmd="$cmd erase $1"
bargs="$bargs '\"$e\": quoted-insert'"
;;
*) cmd="$cmd $1"
;;
esac
shift
done
command stty $cmd
if [ -n "$bargs" ]; then
builtin bind $bargs
fi
}
-27
View File
@@ -1,27 +0,0 @@
#
# func -- print out definitions for functions named by arguments
#
# usage: func name [name ...]
#
# Chet Ramey
# chet@ins.CWRU.Edu
func()
{
local status=0
if [ $# -eq 0 ] ; then
echo "usage: func name [name...]" 1>&2
return 1
fi
for f
do
if [ "$(builtin type -type $f)" != "function" ] ; then
echo "func: $f: not a function" 1>&2
status=1 # one failed
continue
fi
builtin type $f | sed 1d
done
return $status
}
-60
View File
@@ -1,60 +0,0 @@
#
# inet2hex - Internet address conversion, dotted-decimal to hex
#
inet2hex ()
{
local IFS
IFS=.
set -- $1
if (( $# != 4 )); then
echo "inet2hex: incorrect input format: $1" >&2
echo "inet2hex: usage: inet2hex XX.XX.XX.XX" >&2
return 2
fi
printf "0x%02x%02x%02x%02x\n" $1 $2 $3 $4
}
#
# hex2inet - Internet address conversion, hex to dotted-decimal
#
hex2inet ()
{
local x1 x2 x3 x4
local rev
OPTIND=1
while getopts "r" o
do
case "$o" in
r) rev=true;;
*) echo "hex2inet: usage: hex2inet [-r] [0x]XXXXXXXX" >&2 ; exit 2;;
esac
done
shift $(( $OPTIND - 1 ))
case "$1" in
0x*) h=${1#??} ;;
*) h=$1 ;;
esac
if (( ${#h} != 8 )); then
echo "hex2inet: $h not in inet format" >&2
echo "hex2inet: usage: hex2inet [0x]XXXXXXXX" >&2
return 2
fi
x1=$(( 0x${h:0:2} ))
x2=$(( 0x${h:2:2} ))
x3=$(( 0x${h:4:2} ))
x4=$(( 0x${h:6:2} ))
if [ -z "$rev" ] ; then
printf "%d.%d.%d.%d\n" $x1 $x2 $x3 $x4
else
printf "%d.%d.%d.%d\n" $x4 $x3 $x2 $x1
fi
return 0
}
-22
View File
@@ -1,22 +0,0 @@
isnum2()
{
case "$1" in
'[-+]' | '') return 1;; # empty or bare `-' or `+'
[-+]*[!0-9]*) return 1;; # non-digit with leading sign
[-+]*) return 0;; # OK
*[!0-9]*) return 1;; # non-digit
*) return 0;; # OK
esac
}
# this one handles floating point
isnum3()
{
case "$1" in
'') return 1;; # empty
*[!0-9.+-]*) return 1;; # non-digit, +, -, or .
*?[-+]*) return 1;; # sign as second or later char
*.*.*) return 1;; # multiple decimal points
*) return 0;; # OK
esac
}
-35
View File
@@ -1,35 +0,0 @@
#
# ksh-like `cd': cd [-LP] [dir [change]]
#
cd()
{
OPTIND=1
while getopts "LP" opt
do
case $opt in
L|P) CDOPTS="$CDOPTS -$opt" ;;
*) echo "$FUNCNAME: usage: $FUNCNAME [-LP] [dir] [change]" >&2
return 2;;
esac
done
shift $(( $OPTIND - 1 ))
case $# in
0) builtin cd $CDOPTS "$HOME" ;;
1) builtin cd $CDOPTS "$@" ;;
2) old="$1" new="$2"
case "$PWD" in
*$old*) ;;
*) echo "${0##*/}: $FUNCNAME: bad substitution" >&2 ; return 1 ;;
esac
dir=${PWD//$old/$new}
builtin cd $CDOPTS "$dir" && echo "$PWD"
;;
*) echo "${0##*/}: $FUNCNAME: usage: $FUNCNAME [-LP] [dir] [change]" >&2
return 2 ;;
esac
}
-40
View File
@@ -1,40 +0,0 @@
#
# replacements for test/[ that do arithmetic expansion on the operands to
# the arithmetic operators, like ksh.
#
function test()
{
local -i n1 n3
case "$#" in
3) case "$2" in
-lt|-gt|-eq|-ne|-le|-ge) n1=$(( $1 ))
n3=$(( $3 ))
builtin test "$n1" $2 "$n3"
return $?;;
*) builtin test "$@" ;;
esac;;
*) builtin test "$@" ;;
esac
}
function [()
{
local -i n1 n3
case "$#" in
4) case "$2" in
-lt|-gt|-eq|-ne|-le|-ge) n1=$(( $1 ))
n3=$(( $3 ))
builtin [ "$n1" $2 "$n3" ]
return $?;;
*) builtin [ "$@" ;;
esac;;
*) builtin [ "$@" ;;
esac
}
q=7
[ q -lt 10 ]
echo $?
[ $q -lt 10 ]
echo $?
-228
View File
@@ -1,228 +0,0 @@
#
# .kshenv -- functions and aliases to provide the beginnings of a ksh
# environment for bash.
#
# Chet Ramey
# chet@ins.CWRU.Edu
#
#
# These are definitions for the ksh compiled-in `exported aliases'. There
# are others, but we already have substitutes for them: "history", "type",
# and "hash".
#
alias r="fc -s"
alias functions="typeset -f"
alias integer="typeset -i"
alias nohup="nohup "
alias command="command "
alias stop="kill -s STOP"
alias redirect="command exec"
alias hist="fc"
#
# An almost-ksh compatible `whence' command. This is as hairy as it is
# because of the desire to exactly mimic ksh (whose behavior was determined
# empirically).
#
# This depends somewhat on knowing the format of the output of the bash
# `builtin type' command.
#
whence()
{
local vflag pflag fflag defarg c
local path
vflag= aflag= pflag= fflag=
path=
if [ "$#" = "0" ] ; then
echo "whence: usage: whence [-afpv] name..." >&2
return 2
fi
OPTIND=1
while getopts "avfp" c
do
case "$c" in
a) defarg=-a ;;
f) fflag=1 ;; # no-op
p) pflag=1 ;;
v) vflag=1 ;;
?) echo "whence: $1: unknown option" >&2
echo "whence: usage: whence [-afpv] name..." >&2
return 2 ;;
esac
done
shift $(( $OPTIND - 1 ))
if [ "$#" = "0" ] ; then
echo "whence: usage: whence [-afpv] name..." >&2
return 2
fi
for cmd
do
if [ "$vflag" ] ; then
if [ -z "$defarg" ]; then
builtin type $cmd | sed 1q
else
if builtin type $defarg -t $cmd | grep 'function$' >/dev/null 2>&1; then
# HAIRY awk script to suppress
# printing of function body -- could
# do it with sed, but I don't have
# that kind of time
builtin type $defarg $cmd | awk '
BEGIN {printit = 1;}
$1 == "'$cmd'" && $2 == "()" {printit=0; next; }
/^}$/ { if (printit == 0) printit=1 ; else print $0; next ; }
/.*/ { if (printit) print $0; }'
else
builtin type $defarg $cmd
fi
fi
else
path=$(builtin type $defarg -p $cmd)
if [ "$path" ] ; then
echo $path
else
case "$cmd" in
/*) echo "" ;;
*) case "$(builtin type -t $cmd)" in
"") echo "" ;;
*) echo "$cmd" ;;
esac
;;
esac
fi
fi
done
return 0
}
#
# For real ksh homeboy fanatics, redefine the `type' builtin with a ksh
# version.
#
#type()
#{
# whence -v "$*"
#}
#
# ksh-like `cd': cd [-LP] [dir [change]]
#
cd()
{
OPTIND=1
while getopts "LP" opt
do
case $opt in
L|P) CDOPTS="$CDOPTS -$opt" ;;
*) echo "$FUNCNAME: usage: $FUNCNAME [-LP] [dir] [change]" >&2
return 2;;
esac
done
shift $(( $OPTIND - 1 ))
case $# in
0) builtin cd $CDOPTS "$HOME" ;;
1) builtin cd $CDOPTS "$@" ;;
2) old="$1" new="$2"
case "$PWD" in
*$old*) ;;
*) echo "${0##*/}: $FUNCNAME: bad substitution" >&2 ; return 1 ;;
esac
dir=${PWD//$old/$new}
builtin cd $CDOPTS "$dir" && echo "$PWD"
;;
*) echo "${0##*/}: $FUNCNAME: usage: $FUNCNAME [-LP] [dir] [change]" >&2
return 2 ;;
esac
}
#
# ksh print emulation
#
# print [-Rnprsu[n]] [-f format] [arg ...]
#
# - end of options
# -R BSD-style -- only accept -n, no escapes
# -n do not add trailing newline
# -p no-op (no coprocesses)
# -r no escapes
# -s print to the history file
# -u n redirect output to fd n
# -f format printf "$format" "$@"
#
print()
{
local eflag=-e
local nflag= fflag= c
local fd=1
OPTIND=1
while getopts "fRnprsu:" c
do
case $c in
R) eflag= ;;
r) eflag= ;;
n) nflag=-n ;;
s) sflag=y ;;
f) fflag=y ;;
u) fd=$OPTARG ;;
p) ;;
esac
done
shift $(( $OPTIND - 1 ))
if [ -n "$fflag" ]; then
builtin printf "$@" >&$fd
return
fi
case "$sflag" in
y) builtin history -s "$*" ;;
*) builtin echo $eflag $nflag "$@" >&$fd
esac
}
# substring function
# this function should be equivalent to the substring built-in which was
# eliminated after the 06/29/84 version
substring ()
{
local lpat flag str #local variables
set -f
case $1 in
-l|-L)
flag=$1
lpat=$2
shift 2
;;
esac
# test for too few or too many arguments
if [ x"$1" = x ] || [ $# -gt 2 ]; then
print -u2 'substring: bad argument count'
return 1
fi
str=$1
if [ x"$flag" = x-l ]; then #substring -l lpat
str=${str#$lpat}
elif [ x"$flag" = x-L ]; then
str=${str##$lpat} #substring -L lpat
fi
if [ x"$2" != x ]; then
echo ${str%$2}
else
echo $str
fi
return 0
}
-58
View File
@@ -1,58 +0,0 @@
trap _notify CHLD
NOTIFY_ALL=false
unset NOTIFY_LIST
unalias false
false()
{
return 1
}
_notify ()
{
local i j
local newlist=
if $NOTIFY_ALL
then
return # let bash take care of this itself
elif [ -z "$NOTIFY_LIST" ]; then
return
else
set -- $NOTIFY_LIST
for i in "$@"
do
j=$(jobs -n %$i)
if [ -n "$j" ]; then
echo "$j"
jobs -n %$i >/dev/null
else
newlist="newlist $i"
fi
done
NOTIFY_LIST="$newlist"
fi
}
notify ()
{
local i j
if [ $# -eq 0 ]; then
NOTIFY_ALL=:
set -b
return
else
for i in "$@"
do
# turn a valid job spec into a job number
j=$(jobs $i)
case "$j" in
[*) j=${j%%]*}
j=${j#[}
NOTIFY_LIST="$NOTIFY_LIST $j"
;;
esac
done
fi
}
-37
View File
@@ -1,37 +0,0 @@
# Generate a sequence from m to n, m defaults to 1.
seq ()
{
declare -i lo hi i # makes local
local _SEQ INIT COMPARE STEP
case "$1" in
-r) INIT='i=$hi _SEQ=""' COMPARE='let "i >= $lo"' STEP='let i-=1' ; shift ;;
*) INIT='i=$lo _SEQ=""' COMPARE='let "i <= $hi"' STEP='let i+=1' ;;
esac
case $# in
1) lo=1 hi="$1" ;;
2) lo=$1 hi=$2 ;;
*) echo seq: usage: seq [-r] [low] high 1>&2 ; return 2 ;;
esac
# equivalent to the as-yet-unimplemented
# for (( "$INIT" ; "$COMPARE" ; "$STEP" )); do _SEQ="${_SEQ}$i "; done
eval "$INIT"
while eval "$COMPARE"; do
_SEQ="${_SEQ}$i "
eval "$STEP"
done
echo "${_SEQ# }"
return 0
}
# like the APL `iota' function (or at least how I remember it :-)
iota()
{
case $# in
1) seq 1 "$1"; return $?;;
*) echo "iota: usage: iota high" 1>&2; return 2;;
esac
}
-29
View File
@@ -1,29 +0,0 @@
# Generate a sequence from m to n, m defaults to 1.
seq ()
{
declare -i lo hi i # makes local
local _SEQ
case $# in
1) seq 1 "$1" ; return $? ;;
2) lo=$1 hi=$2
i=$lo _SEQ=""
while let "i <= hi"; do
_SEQ="${_SEQ}$i "
let i+=1
done
echo "${_SEQ# }"
return 0 ;;
*) echo seq: usage: seq [low] high 1>&2 ; return 2 ;;
esac
}
# like the APL `iota' function (or at least how I remember it :-)
iota()
{
case $# in
1) seq 1 "$1"; return $?;;
*) echo "iota: usage: iota high" 1>&2; return 2;;
esac
}
-50
View File
@@ -1,50 +0,0 @@
# Sort the positional paramters.
# Make sure the positional parameters are passed as arguments to the function.
# If -u is the first arg, remove duplicate array members.
sort_posparams()
{
local -a R
local u
case "$1" in
-u) u=-u ; shift ;;
esac
# if you want the case of no positional parameters to return success,
# remove the error message and return 0
if [ $# -eq 0 ]; then
echo "$FUNCNAME: argument expected" >&2
return 1
fi
# make R a copy of the positional parameters
R=( "${@}" )
# sort R.
R=( $( printf "%s\n" "${R[@]}" | sort $u) )
printf "%s\n" "${R[@]}"
return 0
}
# will print everything on separate lines
set -- 3 1 4 1 5 9 2 6 5 3 2
sort_posparams "$@"
# sets without preserving quoted parameters
set -- $( sort_posparams "$@" )
echo "$@"
echo $#
# sets preserving quoted parameters, beware pos params with embedded newlines
set -- 'a b' 'a c' 'x z'
oifs=$IFS
IFS=$'\n'
set -- $( sort_posparams "$@" )
IFS="$oifs"
echo "$@"
echo $#
sort_posparams
-81
View File
@@ -1,81 +0,0 @@
#
# substr -- a function to emulate the ancient ksh builtin
#
# -l == remove shortest from left
# -L == remove longest from left
# -r == remove shortest from right (the default)
# -R == remove longest from right
substr()
{
local flag pat str
local usage="usage: substr -lLrR pat string or substr string pat"
local options="l:L:r:R:"
OPTIND=1
while getopts "$options" c
do
case "$c" in
l | L | r | R)
flag="-$c"
pat="$OPTARG"
;;
'?')
echo "$usage"
return 1
;;
esac
done
if [ "$OPTIND" -gt 1 ] ; then
shift $(( $OPTIND -1 ))
fi
if [ "$#" -eq 0 ] || [ "$#" -gt 2 ] ; then
echo "substr: bad argument count"
return 2
fi
str="$1"
#
# We don't want -f, but we don't want to turn it back on if
# we didn't have it already
#
case "$-" in
"*f*")
;;
*)
fng=1
set -f
;;
esac
case "$flag" in
-l)
str="${str#$pat}" # substr -l pat string
;;
-L)
str="${str##$pat}" # substr -L pat string
;;
-r)
str="${str%$pat}" # substr -r pat string
;;
-R)
str="${str%%$pat}" # substr -R pat string
;;
*)
str="${str%$2}" # substr string pat
;;
esac
echo "$str"
#
# If we had file name generation when we started, re-enable it
#
if [ "$fng" = "1" ] ; then
set +f
fi
}
-79
View File
@@ -1,79 +0,0 @@
#
# substr -- a function to emulate the ancient ksh builtin
#
#
# -l == shortest from left
# -L == longest from left
# -r == shortest from right (the default)
# -R == longest from right
substr()
{
local flag pat str
local usage="usage: substr -lLrR pat string or substr string pat"
case "$1" in
-l | -L | -r | -R)
flag="$1"
pat="$2"
shift 2
;;
-*)
echo "substr: unknown option: $1"
echo "$usage"
return 1
;;
*)
flag="-r"
pat="$2"
;;
esac
if [ "$#" -eq 0 ] || [ "$#" -gt 2 ] ; then
echo "substr: bad argument count"
return 2
fi
str="$1"
#
# We don't want -f, but we don't want to turn it back on if
# we didn't have it already
#
case "$-" in
"*f*")
;;
*)
fng=1
set -f
;;
esac
case "$flag" in
-l)
str="${str#$pat}" # substr -l pat string
;;
-L)
str="${str##$pat}" # substr -L pat string
;;
-r)
str="${str%$pat}" # substr -r pat string
;;
-R)
str="${str%%$pat}" # substr -R pat string
;;
*)
str="${str%$2}" # substr string pat
;;
esac
echo "$str"
#
# If we had file name generation when we started, re-enable it
#
if [ "$fng" = "1" ] ; then
set +f
fi
}
-52
View File
@@ -1,52 +0,0 @@
#
# whatis -- and implementation of the 10th Edition Unix sh builtin `whatis'
# command.
#
# usage: whatis arg [...]
#
# For each argument, whatis prints the associated value as a parameter,
# builtin, function, alias, or executable file as appropriate. In each
# case, the value is printed in a form which would yield the same value
# if typed as input to the shell itself.
#
whatis()
{
local wusage='usage: whatis arg [arg...]'
local fail=0
if [ $# -eq 0 ] ; then
echo "$wusage"
return 1
fi
for arg
do
case $(builtin type -type $arg 2>/dev/null) in
"alias")
builtin alias "$arg"
;;
"function")
builtin type "$arg" | sed 1d
;;
"builtin")
echo builtin "$arg"
;;
"file")
builtin type -path "$arg"
;;
*)
# OK, we could have a variable, or we could have nada
if [ "$(eval echo \${$arg+set})" = "set" ] ; then
# It is a variable, and it is set
echo -n "$arg="
eval echo '\"'\$$arg'\"'
else
echo whatis: $arg: not found
fail=1
fi
;;
esac
done
return $fail
}
-59
View File
@@ -1,59 +0,0 @@
#
# An almost-ksh compatible `whence' command. This is as hairy as it is
# because of the desire to exactly mimic ksh.
#
# This depends somewhat on knowing the format of the output of the bash
# `builtin type' command.
#
# Chet Ramey
# chet@ins.CWRU.Edu
#
whence()
{
local vflag= path=
if [ "$#" = "0" ] ; then
echo "whence: argument expected"
return 1
fi
case "$1" in
-v) vflag=1
shift 1
;;
-*) echo "whence: bad option: $1"
return 1
;;
*) ;;
esac
if [ "$#" = "0" ] ; then
echo "whence: bad argument count"
return 1
fi
for cmd
do
if [ "$vflag" ] ; then
echo $(builtin type $cmd | sed 1q)
else
path=$(builtin type -path $cmd)
if [ "$path" ] ; then
echo $path
else
case "$cmd" in
/*) if [ -x "$cmd" ]; then
echo "$cmd"
fi
;;
*) case "$(builtin type -type $cmd)" in
"") ;;
*) echo "$cmd"
;;
esac
;;
esac
fi
fi
done
return 0
}
-44
View File
@@ -1,44 +0,0 @@
#
# which - emulation of `which' as it appears in FreeBSD
#
# usage: which [-as] command [command...]
#
which()
{
local aflag sflag ES a opt
OPTIND=1
while builtin getopts as opt ; do
case "$opt" in
a) aflag=-a ;;
s) sflag=1 ;;
?) echo "which: usage: which [-as] command [command ...]" >&2
exit 2 ;;
esac
done
(( $OPTIND > 1 )) && shift $(( $OPTIND - 1 ))
# without command arguments, exit with status 1
ES=1
# exit status is 0 if all commands are found, 1 if any are not found
for command; do
# if $command is a function, make sure we add -a so type
# will look in $PATH after finding the function
a=$aflag
case "$(builtin type -t $command)" in
"function") a=-a;;
esac
if [ -n "$sflag" ]; then
builtin type -p $a $command >/dev/null 2>&1
else
builtin type -p $a $command
fi
ES=$?
done
return $ES
}
-238
View File
@@ -1,238 +0,0 @@
#
# Simple makefile for the sample loadable builtins
#
# Copyright (C) 1996 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
# Include some boilerplate Gnu makefile definitions.
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
infodir = @infodir@
includedir = @includedir@
topdir = @top_srcdir@
BUILD_DIR = @BUILD_DIR@
srcdir = @srcdir@
VPATH = .:@srcdir@
@SET_MAKE@
CC = @CC@
RM = rm -f
SHELL = @MAKE_SHELL@
host_os = @host_os@
host_cpu = @host_cpu@
host_vendor = @host_vendor@
CFLAGS = @CFLAGS@
LOCAL_CFLAGS = @LOCAL_CFLAGS@
DEFS = @DEFS@
LOCAL_DEFS = @LOCAL_DEFS@
CPPFLAGS = @CPPFLAGS@
BASHINCDIR = ${topdir}/include
LIBBUILD = ${BUILD_DIR}/lib
INTL_LIBSRC = ${topdir}/lib/intl
INTL_BUILDDIR = ${LIBBUILD}/intl
INTL_INC = @INTL_INC@
LIBINTL_H = @LIBINTL_H@
CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) $(CFLAGS)
#
# These values are generated for configure by ${topdir}/support/shobj-conf.
# If your system is not supported by that script, but includes facilities for
# dynamic loading of shared objects, please update the script and send the
# changes to bash-maintainers@gnu.org.
#
SHOBJ_CC = @SHOBJ_CC@
SHOBJ_CFLAGS = @SHOBJ_CFLAGS@
SHOBJ_LD = @SHOBJ_LD@
SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@
SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@
SHOBJ_LIBS = @SHOBJ_LIBS@
SHOBJ_STATUS = @SHOBJ_STATUS@
INC = -I. -I.. -I$(topdir) -I$(topdir)/lib -I$(topdir)/builtins \
-I$(BASHINCDIR) -I$(BUILD_DIR) -I$(LIBBUILD) \
-I$(BUILD_DIR)/builtins $(INTL_INC)
.c.o:
$(SHOBJ_CC) $(SHOBJ_CFLAGS) $(CCFLAGS) $(INC) -c -o $@ $<
ALLPROG = print truefalse sleep pushd finfo logname basename dirname \
tty pathchk tee head mkdir rmdir printenv id whoami \
uname sync push ln unlink cut realpath getconf strftime
OTHERPROG = necho hello cat
all: $(SHOBJ_STATUS)
supported: $(ALLPROG)
others: $(OTHERPROG)
unsupported:
@echo "Your system (${host_os}) is not supported by the"
@echo "${topdir}/support/shobj-conf script."
@echo "If your operating system provides facilities for dynamic"
@echo "loading of shared objects using the dlopen(3) interface,"
@echo "please update the script and re-run configure.
@echo "Please send the changes you made to bash-maintainers@gnu.org"
@echo "for inclusion in future bash releases."
everything: supported others
print: print.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ print.o $(SHOBJ_LIBS)
necho: necho.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ necho.o $(SHOBJ_LIBS)
getconf: getconf.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ getconf.o $(SHOBJ_LIBS)
hello: hello.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ hello.o $(SHOBJ_LIBS)
truefalse: truefalse.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ truefalse.o $(SHOBJ_LIBS)
sleep: sleep.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ sleep.o $(SHOBJ_LIBS)
finfo: finfo.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ finfo.o $(SHOBJ_LIBS)
cat: cat.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ cat.o $(SHOBJ_LIBS)
logname: logname.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ logname.o $(SHOBJ_LIBS)
basename: basename.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ basename.o $(SHOBJ_LIBS)
dirname: dirname.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ dirname.o $(SHOBJ_LIBS)
tty: tty.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ tty.o $(SHOBJ_LIBS)
pathchk: pathchk.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ pathchk.o $(SHOBJ_LIBS)
tee: tee.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ tee.o $(SHOBJ_LIBS)
mkdir: mkdir.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ mkdir.o $(SHOBJ_LIBS)
rmdir: rmdir.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ rmdir.o $(SHOBJ_LIBS)
head: head.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ head.o $(SHOBJ_LIBS)
printenv: printenv.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ printenv.o $(SHOBJ_LIBS)
id: id.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ id.o $(SHOBJ_LIBS)
whoami: whoami.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ whoami.o $(SHOBJ_LIBS)
uname: uname.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ uname.o $(SHOBJ_LIBS)
sync: sync.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ sync.o $(SHOBJ_LIBS)
push: push.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ push.o $(SHOBJ_LIBS)
ln: ln.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ ln.o $(SHOBJ_LIBS)
unlink: unlink.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ unlink.o $(SHOBJ_LIBS)
cut: cut.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ cut.o $(SHOBJ_LIBS)
realpath: realpath.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ realpath.o $(SHOBJ_LIBS)
strftime: strftime.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ strftime.o $(SHOBJ_LIBS)
# pushd is a special case. We use the same source that the builtin version
# uses, with special compilation options.
#
pushd.c: ${topdir}/builtins/pushd.def
$(RM) $@
${BUILD_DIR}/builtins/mkbuiltins -D ${topdir}/builtins ${topdir}/builtins/pushd.def
pushd.o: pushd.c
$(RM) $@
$(SHOBJ_CC) -DHAVE_CONFIG_H -DPUSHD_AND_POPD -DLOADABLE_BUILTIN $(SHOBJ_CFLAGS) $(CFLAGS) $(CPPFLAGS) $(INC) -c -o $@ $<
pushd: pushd.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ pushd.o $(SHOBJ_LIBS)
clean:
$(RM) $(ALLPROG) $(OTHERPROG) *.o
-( cd perl && ${MAKE} ${MFLAGS} $@ )
mostlyclean: clean
-( cd perl && ${MAKE} ${MFLAGS} $@ )
distclean maintainer-clean: clean
$(RM) Makefile pushd.c
-( cd perl && ${MAKE} ${MFLAGS} $@ )
print.o: print.c
truefalse.o: truefalse.c
sleep.o: sleep.c
finfo.o: finfo.c
logname.o: logname.c
basename.o: basename.c
dirname.o: dirname.c
tty.o: tty.c
pathchk.o: pathchk.c
tee.o: tee.c
head.o: head.c
rmdir.o: rmdir.c
necho.o: necho.c
getconf.o: getconf.c
hello.o: hello.c
cat.o: cat.c
printenv.o: printenv.c
id.o: id.c
whoami.o: whoami.c
uname.o: uname.c
sync.o: sync.c
push.o: push.c
mkdir.o: mkdir.c
realpath.o: realpath.c
strftime.o: strftime.c
-111
View File
@@ -1,111 +0,0 @@
/* basename - return nondirectory portion of pathname */
/* See Makefile for compilation details. */
#include "config.h"
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include <stdio.h>
#include "builtins.h"
#include "shell.h"
#include "common.h"
basename_builtin (list)
WORD_LIST *list;
{
int slen, sufflen, off;
char *string, *suffix, *fn;
if (list == 0)
{
builtin_usage ();
return (EX_USAGE);
}
if (no_options (list))
return (EX_USAGE);
string = list->word->word;
suffix = (char *)NULL;
if (list->next)
{
list = list->next;
suffix = list->word->word;
}
if (list->next)
{
builtin_usage ();
return (EX_USAGE);
}
slen = strlen (string);
/* Strip trailing slashes */
while (slen > 0 && string[slen - 1] == '/')
slen--;
/* (2) If string consists entirely of slash characters, string shall be
set to a single slash character. In this case, skip steps (3)
through (5). */
if (slen == 0)
{
fputs ("/\n", stdout);
return (EXECUTION_SUCCESS);
}
/* (3) If there are any trailing slash characters in string, they
shall be removed. */
string[slen] = '\0';
/* (4) If there are any slash characters remaining in string, the prefix
of string up to an including the last slash character in string
shall be removed. */
while (--slen >= 0)
if (string[slen] == '/')
break;
fn = string + slen + 1;
/* (5) If the suffix operand is present, is not identical to the
characters remaining in string, and is identical to a suffix
of the characters remaining in string, the suffix suffix
shall be removed from string. Otherwise, string shall not be
modified by this step. */
if (suffix)
{
sufflen = strlen (suffix);
slen = strlen (fn);
if (sufflen < slen)
{
off = slen - sufflen;
if (strcmp (fn + off, suffix) == 0)
fn[off] = '\0';
}
}
printf ("%s\n", fn);
return (EXECUTION_SUCCESS);
}
char *basename_doc[] = {
"Return non-directory portion of pathname.",
"",
"The STRING is converted to a filename corresponding to the last",
"pathname component in STRING. If the suffix string SUFFIX is",
"supplied, it is removed.",
(char *)NULL
};
/* The standard structure describing a builtin command. bash keeps an array
of these structures. */
struct builtin basename_struct = {
"basename", /* builtin name */
basename_builtin, /* function implementing the builtin */
BUILTIN_ENABLED, /* initial flags for builtin */
basename_doc, /* array of long documentation strings. */
"basename string [suffix]", /* usage synopsis */
0 /* reserved for internal use */
};
-602
View File
@@ -1,602 +0,0 @@
/*
* finfo - print file info
*
* Chet Ramey
* chet@po.cwru.edu
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include "posixstat.h"
#include <stdio.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#include "posixtime.h"
#include "bashansi.h"
#include "shell.h"
#include "builtins.h"
#include "common.h"
#ifndef errno
extern int errno;
#endif
extern char **make_builtin_argv ();
static int printst();
static int printsome();
static int printfinfo();
static int finfo_main();
extern int sh_optind;
extern char *sh_optarg;
extern char *this_command_name;
static char *prog;
static int pmask;
#define OPT_UID 0x00001
#define OPT_GID 0x00002
#define OPT_DEV 0x00004
#define OPT_INO 0x00008
#define OPT_PERM 0x00010
#define OPT_LNKNAM 0x00020
#define OPT_FID 0x00040
#define OPT_NLINK 0x00080
#define OPT_RDEV 0x00100
#define OPT_SIZE 0x00200
#define OPT_ATIME 0x00400
#define OPT_MTIME 0x00800
#define OPT_CTIME 0x01000
#define OPT_BLKSIZE 0x02000
#define OPT_BLKS 0x04000
#define OPT_FTYPE 0x08000
#define OPT_PMASK 0x10000
#define OPT_OPERM 0x20000
#define OPT_ASCII 0x1000000
#define OPTIONS "acdgiflmnopsuACGMP:U"
static int
octal(s)
char *s;
{
int r;
r = *s - '0';
while (*++s >= '0' && *s <= '7')
r = (r * 8) + (*s - '0');
return r;
}
static int
finfo_main(argc, argv)
int argc;
char **argv;
{
register int i;
int mode, flags, opt;
sh_optind = 0; /* XXX */
prog = base_pathname(argv[0]);
if (argc == 1) {
builtin_usage();
return(1);
}
flags = 0;
while ((opt = sh_getopt(argc, argv, OPTIONS)) != EOF) {
switch(opt) {
case 'a': flags |= OPT_ATIME; break;
case 'A': flags |= OPT_ATIME|OPT_ASCII; break;
case 'c': flags |= OPT_CTIME; break;
case 'C': flags |= OPT_CTIME|OPT_ASCII; break;
case 'd': flags |= OPT_DEV; break;
case 'i': flags |= OPT_INO; break;
case 'f': flags |= OPT_FID; break;
case 'g': flags |= OPT_GID; break;
case 'G': flags |= OPT_GID|OPT_ASCII; break;
case 'l': flags |= OPT_LNKNAM; break;
case 'm': flags |= OPT_MTIME; break;
case 'M': flags |= OPT_MTIME|OPT_ASCII; break;
case 'n': flags |= OPT_NLINK; break;
case 'o': flags |= OPT_OPERM; break;
case 'p': flags |= OPT_PERM; break;
case 'P': flags |= OPT_PMASK; pmask = octal(sh_optarg); break;
case 's': flags |= OPT_SIZE; break;
case 'u': flags |= OPT_UID; break;
case 'U': flags |= OPT_UID|OPT_ASCII; break;
default: builtin_usage (); return(1);
}
}
argc -= sh_optind;
argv += sh_optind;
if (argc == 0) {
builtin_usage();
return(1);
}
for (i = 0; i < argc; i++)
opt = flags ? printsome (argv[i], flags) : printfinfo(argv[i]);
return(opt);
}
static struct stat *
getstat(f)
char *f;
{
static struct stat st;
int fd, r;
intmax_t lfd;
if (strncmp(f, "/dev/fd/", 8) == 0) {
if ((legal_number(f + 8, &lfd) == 0) || (int)lfd != lfd) {
builtin_error("%s: invalid fd", f + 8);
return ((struct stat *)0);
}
fd = lfd;
r = fstat(fd, &st);
} else
#ifdef HAVE_LSTAT
r = lstat(f, &st);
#else
r = stat(f, &st);
#endif
if (r < 0) {
builtin_error("%s: cannot stat: %s", f, strerror(errno));
return ((struct stat *)0);
}
return (&st);
}
static int
printfinfo(f)
char *f;
{
struct stat *st;
st = getstat(f);
return (st ? printst(st) : 1);
}
static int
getperm(m)
int m;
{
return (m & (S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID));
}
static int
perms(m)
int m;
{
char ubits[4], gbits[4], obits[4]; /* u=rwx,g=rwx,o=rwx */
int i;
i = 0;
if (m & S_IRUSR)
ubits[i++] = 'r';
if (m & S_IWUSR)
ubits[i++] = 'w';
if (m & S_IXUSR)
ubits[i++] = 'x';
ubits[i] = '\0';
i = 0;
if (m & S_IRGRP)
gbits[i++] = 'r';
if (m & S_IWGRP)
gbits[i++] = 'w';
if (m & S_IXGRP)
gbits[i++] = 'x';
gbits[i] = '\0';
i = 0;
if (m & S_IROTH)
obits[i++] = 'r';
if (m & S_IWOTH)
obits[i++] = 'w';
if (m & S_IXOTH)
obits[i++] = 'x';
obits[i] = '\0';
if (m & S_ISUID)
ubits[2] = (m & S_IXUSR) ? 's' : 'S';
if (m & S_ISGID)
gbits[2] = (m & S_IXGRP) ? 's' : 'S';
if (m & S_ISVTX)
obits[2] = (m & S_IXOTH) ? 't' : 'T';
printf ("u=%s,g=%s,o=%s", ubits, gbits, obits);
}
static int
printmode(mode)
int mode;
{
if (S_ISBLK(mode))
printf("S_IFBLK ");
if (S_ISCHR(mode))
printf("S_IFCHR ");
if (S_ISDIR(mode))
printf("S_IFDIR ");
if (S_ISREG(mode))
printf("S_IFREG ");
if (S_ISFIFO(mode))
printf("S_IFIFO ");
if (S_ISLNK(mode))
printf("S_IFLNK ");
if (S_ISSOCK(mode))
printf("S_IFSOCK ");
#ifdef S_ISWHT
if (S_ISWHT(mode))
printf("S_ISWHT ");
#endif
perms(getperm(mode));
printf("\n");
}
static int
printst(st)
struct stat *st;
{
struct passwd *pw;
struct group *gr;
char *owner;
int ma, mi, d;
ma = major (st->st_rdev);
mi = minor (st->st_rdev);
#if defined (makedev)
d = makedev (ma, mi);
#else
d = st->st_rdev & 0xFF;
#endif
printf("Device (major/minor): %d (%d/%d)\n", d, ma, mi);
printf("Inode: %d\n", (int) st->st_ino);
printf("Mode: (%o) ", (int) st->st_mode);
printmode((int) st->st_mode);
printf("Link count: %d\n", (int) st->st_nlink);
pw = getpwuid(st->st_uid);
owner = pw ? pw->pw_name : "unknown";
printf("Uid of owner: %d (%s)\n", (int) st->st_uid, owner);
gr = getgrgid(st->st_gid);
owner = gr ? gr->gr_name : "unknown";
printf("Gid of owner: %d (%s)\n", (int) st->st_gid, owner);
printf("Device type: %d\n", (int) st->st_rdev);
printf("File size: %ld\n", (long) st->st_size);
printf("File last access time: %s", ctime (&st->st_atime));
printf("File last modify time: %s", ctime (&st->st_mtime));
printf("File last status change time: %s", ctime (&st->st_ctime));
fflush(stdout);
return(0);
}
static int
printsome(f, flags)
char *f;
int flags;
{
struct stat *st;
struct passwd *pw;
struct group *gr;
int p;
char *b;
st = getstat(f);
if (st == NULL)
return (1);
/* Print requested info */
if (flags & OPT_ATIME) {
if (flags & OPT_ASCII)
printf("%s", ctime(&st->st_atime));
else
printf("%ld\n", st->st_atime);
} else if (flags & OPT_MTIME) {
if (flags & OPT_ASCII)
printf("%s", ctime(&st->st_mtime));
else
printf("%ld\n", st->st_mtime);
} else if (flags & OPT_CTIME) {
if (flags & OPT_ASCII)
printf("%s", ctime(&st->st_ctime));
else
printf("%ld\n", st->st_ctime);
} else if (flags & OPT_DEV)
printf("%d\n", st->st_dev);
else if (flags & OPT_INO)
printf("%d\n", st->st_ino);
else if (flags & OPT_FID)
printf("%d:%ld\n", st->st_dev, st->st_ino);
else if (flags & OPT_NLINK)
printf("%d\n", st->st_nlink);
else if (flags & OPT_LNKNAM) {
#ifdef S_ISLNK
b = xmalloc(4096);
p = readlink(f, b, 4096);
if (p >= 0 && p < 4096)
b[p] = '\0';
else {
p = errno;
strcpy(b, prog);
strcat(b, ": ");
strcat(b, strerror(p));
}
printf("%s\n", b);
free(b);
#else
printf("%s\n", f);
#endif
} else if (flags & OPT_PERM) {
perms(st->st_mode);
printf("\n");
} else if (flags & OPT_OPERM)
printf("%o\n", getperm(st->st_mode));
else if (flags & OPT_PMASK)
printf("%o\n", getperm(st->st_mode) & pmask);
else if (flags & OPT_UID) {
pw = getpwuid(st->st_uid);
if (flags & OPT_ASCII)
printf("%s\n", pw ? pw->pw_name : "unknown");
else
printf("%d\n", st->st_uid);
} else if (flags & OPT_GID) {
gr = getgrgid(st->st_gid);
if (flags & OPT_ASCII)
printf("%s\n", gr ? gr->gr_name : "unknown");
else
printf("%d\n", st->st_gid);
} else if (flags & OPT_SIZE)
printf("%ld\n", (long) st->st_size);
return (0);
}
#ifndef NOBUILTIN
int
finfo_builtin(list)
WORD_LIST *list;
{
int c, r;
char **v;
WORD_LIST *l;
v = make_builtin_argv (list, &c);
r = finfo_main (c, v);
free (v);
return r;
}
static char *finfo_doc[] = {
"Display information about file attributes.",
"",
"Display information about each FILE. Only single operators should",
"be supplied. If no options are supplied, a summary of the info",
"available about each FILE is printed. If FILE is of the form",
"/dev/fd/XX, file descriptor XX is described. Operators, if supplied,",
"have the following meanings:",
"",
" -a last file access time",
" -A last file access time in ctime format",
" -c last file status change time",
" -C last file status change time in ctime format",
" -m last file modification time",
" -M last file modification time in ctime format",
" -d device",
" -i inode",
" -f composite file identifier (device:inode)",
" -g gid of owner",
" -G group name of owner",
" -l name of file pointed to by symlink",
" -n link count",
" -o permissions in octal",
" -p permissions in ascii",
" -P mask permissions ANDed with MASK (like with umask)",
" -s file size in bytes",
" -u uid of owner",
" -U user name of owner",
(char *)0
};
struct builtin finfo_struct = {
"finfo",
finfo_builtin,
BUILTIN_ENABLED,
finfo_doc,
"finfo [-acdgiflmnopsuACGMPU] file [file...]",
0
};
#endif
#ifdef NOBUILTIN
#if defined (PREFER_STDARG)
# include <stdarg.h>
#else
# if defined (PREFER_VARARGS)
# include <varargs.h>
# endif
#endif
char *this_command_name;
main(argc, argv)
int argc;
char **argv;
{
this_command_name = argv[0];
exit(finfo_main(argc, argv));
}
void
builtin_usage()
{
fprintf(stderr, "%s: usage: %s [-%s] [file ...]\n", prog, OPTIONS);
}
#ifndef HAVE_STRERROR
char *
strerror(e)
int e;
{
static char ebuf[40];
extern int sys_nerr;
extern char *sys_errlist[];
if (e < 0 || e > sys_nerr) {
sprintf(ebuf,"Unknown error code %d", e);
return (&ebuf[0]);
}
return (sys_errlist[e]);
}
#endif
char *
xmalloc(s)
size_t s;
{
char *ret;
extern char *malloc();
ret = malloc(s);
if (ret)
return (ret);
fprintf(stderr, "%s: cannot malloc %d bytes\n", prog, s);
exit(1);
}
char *
base_pathname(p)
char *p;
{
char *t;
if (t = strrchr(p, '/'))
return(++t);
return(p);
}
int
legal_number (string, result)
char *string;
long *result;
{
int sign;
long value;
sign = 1;
value = 0;
if (result)
*result = 0;
/* Skip leading whitespace characters. */
while (whitespace (*string))
string++;
if (!*string)
return (0);
/* We allow leading `-' or `+'. */
if (*string == '-' || *string == '+')
{
if (!digit (string[1]))
return (0);
if (*string == '-')
sign = -1;
string++;
}
while (digit (*string))
{
if (result)
value = (value * 10) + digit_value (*string);
string++;
}
/* Skip trailing whitespace, if any. */
while (whitespace (*string))
string++;
/* Error if not at end of string. */
if (*string)
return (0);
if (result)
*result = value * sign;
return (1);
}
int sh_optind;
char *sh_optarg;
int sh_opterr;
extern int optind;
extern char *optarg;
int
sh_getopt(c, v, o)
int c;
char **v, *o;
{
int r;
r = getopt(c, v, o);
sh_optind = optind;
sh_optarg = optarg;
return r;
}
#if defined (USE_VARARGS)
void
#if defined (PREFER_STDARG)
builtin_error (const char *format, ...)
#else
builtin_error (format, va_alist)
const char *format;
va_dcl
#endif
{
va_list args;
if (this_command_name && *this_command_name)
fprintf (stderr, "%s: ", this_command_name);
#if defined (PREFER_STDARG)
va_start (args, format);
#else
va_start (args);
#endif
vfprintf (stderr, format, args);
va_end (args);
fprintf (stderr, "\n");
}
#else
void
builtin_error (format, arg1, arg2, arg3, arg4, arg5)
char *format, *arg1, *arg2, *arg3, *arg4, *arg5;
{
if (this_command_name && *this_command_name)
fprintf (stderr, "%s: ", this_command_name);
fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5);
fprintf (stderr, "\n");
fflush (stderr);
}
#endif /* !USE_VARARGS */
#endif
-64
View File
@@ -1,64 +0,0 @@
/* Sample builtin to be dynamically loaded with enable -f and create a new
builtin. */
/* See Makefile for compilation details. */
#include <config.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include <stdio.h>
#include "builtins.h"
#include "shell.h"
#include "bashgetopt.h"
/* A builtin `xxx' is normally implemented with an `xxx_builtin' function.
If you're converting a command that uses the normal Unix argc/argv
calling convention, use argv = make_builtin_argv (list, &argc) and call
the original `main' something like `xxx_main'. Look at cat.c for an
example.
Builtins should use internal_getopt to parse options. It is the same as
getopt(3), but it takes a WORD_LIST *. Look at print.c for an example
of its use.
If the builtin takes no options, call no_options(list) before doing
anything else. If it returns a non-zero value, your builtin should
immediately return EX_USAGE. Look at logname.c for an example.
A builtin command returns EXECUTION_SUCCESS for success and
EXECUTION_FAILURE to indicate failure. */
int
hello_builtin (list)
WORD_LIST *list;
{
printf("hello world\n");
fflush (stdout);
return (EXECUTION_SUCCESS);
}
/* An array of strings forming the `long' documentation for a builtin xxx,
which is printed by `help xxx'. It must end with a NULL. By convention,
the first line is a short description. */
char *hello_doc[] = {
"Sample builtin.",
"",
"this is the long doc for the sample hello builtin",
(char *)NULL
};
/* The standard structure describing a builtin command. bash keeps an array
of these structures. The flags must include BUILTIN_ENABLED so the
builtin can be used. */
struct builtin hello_struct = {
"hello", /* builtin name */
hello_builtin, /* function implementing the builtin */
BUILTIN_ENABLED, /* initial flags for builtin */
hello_doc, /* array of long documentation strings. */
"hello", /* usage synopsis; becomes short_doc */
0 /* reserved for internal use */
};
-24
View File
@@ -1,24 +0,0 @@
#! /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
-137
View File
@@ -1,137 +0,0 @@
#
# shprompt -- give a prompt and get an answer satisfying certain criteria
#
# shprompt [-dDfFsy] prompt
# s = prompt for string
# f = prompt for filename
# F = prompt for full pathname to a file or directory
# d = prompt for a directory name
# D = prompt for a full pathname to a directory
# y = prompt for y or n answer
#
# Chet Ramey
# chet@ins.CWRU.Edu
type=file
OPTS=dDfFsy
succeed()
{
echo "$1"
exit 0
}
while getopts "$OPTS" c
do
case "$c" in
s) type=string
;;
f) type=file
;;
F) type=path
;;
d) type=dir
;;
D) type=dirpath
;;
y) type=yesno
;;
?) echo "usage: $0 [-$OPTS] prompt" 1>&2
exit 2
;;
esac
done
if [ "$OPTIND" -gt 1 ] ; then
shift $(( $OPTIND - 1 ))
fi
while :
do
case "$type" in
string)
echo -n "$1" 1>&2
read ans || exit 1
if [ -n "$ans" ] ; then
succeed "$ans"
fi
;;
file|path)
echo -n "$1" 1>&2
read ans || exit 1
#
# use `fn' and eval so that bash will do tilde expansion for
# me
#
eval fn="$ans"
case "$fn" in
/*) if test -e "$fn" ; then
succeed "$fn"
else
echo "$0: '$fn' does not exist" 1>&2
fi
;;
*) if [ "$type" = "path" ] ; then
echo "$0: must give full pathname to file" 1>&2
else
if test -e "$fn" ; then
succeed "$fn"
else
echo "$0: '$fn' does not exist" 1>&2
fi
fi
;;
esac
;;
dir|dirpath)
echo -n "$1" 1>&2
read ans || exit 1
#
# use `fn' and eval so that bash will do tilde expansion for
# me
#
eval fn="$ans"
case "$fn" in
/*) if test -d "$fn" ; then
succeed "$fn"
elif test -e "$fn" ; then
echo "$0 '$fn' is not a directory" 1>&2
else
echo "$0: '$fn' does not exist" 1>&2
fi
;;
*) if [ "$type" = "dirpath" ] ; then
echo "$0: must give full pathname to directory" 1>&2
else
if test -d "$fn" ; then
succeed "$fn"
elif test -e "$fn" ; then
echo "$0 '$fn' is not a directory" 1>&2
else
echo "$0: '$fn' does not exist" 1>&2
fi
fi
;;
esac
;;
yesno)
echo -n "$1" 1>&2
read ans || exit 1
case "$ans" in
y|Y|[yY][eE][sS])
succeed "yes"
;;
n|N|[nN][oO])
succeed "no"
exit 0
;;
*)
echo "$0: yes or no required" 1>&2
;;
esac
;;
esac
done
exit 1
-21
View File
@@ -1,21 +0,0 @@
#!/bin/bash
#
# spin.bash -- provide a `spinning wheel' to show progress
#
# Chet Ramey
# chet@po.cwru.edu
#
bs=$'\b'
chars="|${bs} \\${bs} -${bs} /${bs}"
# Infinite loop for demo. purposes
while :
do
for letter in $chars
do
echo -n ${letter}
done
done
exit 0
-27
View File
@@ -1,27 +0,0 @@
#! /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
-26
View File
@@ -1,26 +0,0 @@
#! /bin/bash
#
# zprintf - function that calls gawk to do printf for those systems that
# don't have a printf executable
#
# The format and arguments can have trailing commas, just like gawk
#
# example:
# zprintf 'Eat %x %x and suck %x!\n' 57005 48879 64206
#
# Chet Ramey
# chet@po.cwru.edu
[ $# -lt 1 ] && {
echo "zprintf: usage: zprintf format [args ...]" >&2
exit 2
}
fmt="${1%,}"
shift
for a in "$@"; do
args="$args,\"${a%,}\""
done
gawk "BEGIN { printf \"$fmt\" $args }"
-21
View File
@@ -1,21 +0,0 @@
Some sample startup files. The ones starting with capital letters
are originally from Brian Fox. The ones starting with lowercase
letters are from Chet Ramey.
They will require changes for your environment.
Bash_aliases Some useful aliases (Fox).
Bash_profile Sample startup file for bash login shells (Fox).
bash-profile Sample startup file for bash login shells (Ramey).
bashrc Sample Bourne Again SHell init file (Ramey).
Bashrc.bfox Sample Bourne Again SHell init file (Fox).
README README
apple Example Start-up files for Mac OS X.
apple/aliases Sample aliases for Mac OS X.
apple/bash.defaults Sample User preferences file.
apple/environment Sample Bourne Again Shell environment file.
apple/login Sample login wrapper.
apple/logout Sample logout wrapper.
apple/rc Sample Bourne Again Shell config file.
apple/README README
-1303
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-76
View File
@@ -1,76 +0,0 @@
# This makefile for Readline library documentation is in -*- text -*- mode.
# Emacs likes it that way.
RM = rm -f
MAKEINFO = makeinfo
TEXI2DVI = texi2dvi
TEXI2HTML = texi2html
QUIETPS = #set this to -q to shut up dvips
DVIPS = dvips -D 300 $(QUIETPS) -o $@ # tricky
INSTALL_DATA = cp
infodir = /usr/local/info
RLSRC = rlman.texinfo rluser.texinfo rltech.texinfo
HISTSRC = hist.texinfo hsuser.texinfo hstech.texinfo
DVIOBJ = readline.dvi history.dvi
INFOOBJ = readline.info history.info
PSOBJ = readline.ps history.ps
HTMLOBJ = readline.html history.html
all: info dvi html ps
nodvi: info html
readline.dvi: $(RLSRC)
$(TEXI2DVI) rlman.texinfo
mv rlman.dvi readline.dvi
readline.info: $(RLSRC)
$(MAKEINFO) --no-split -o $@ rlman.texinfo
history.dvi: ${HISTSRC}
$(TEXI2DVI) hist.texinfo
mv hist.dvi history.dvi
history.info: ${HISTSRC}
$(MAKEINFO) --no-split -o $@ hist.texinfo
readline.ps: readline.dvi
$(RM) $@
$(DVIPS) readline.dvi
history.ps: history.dvi
$(RM) $@
$(DVIPS) history.dvi
readline.html: ${RLSRC}
$(TEXI2HTML) rlman.texinfo
sed -e 's:rlman.html:readline.html:' -e 's:rlman_toc.html:readline_toc.html:' rlman.html > readline.html
sed -e 's:rlman.html:readline.html:' -e 's:rlman_toc.html:readline_toc.html:' rlman_toc.html > readline_toc.html
$(RM) rlman.html rlman_toc.html
history.html: ${HISTSRC}
$(TEXI2HTML) hist.texinfo
sed -e 's:hist.html:history.html:' -e 's:hist_toc.html:history_toc.html:' hist.html > history.html
sed -e 's:hist.html:history.html:' -e 's:hist_toc.html:history_toc.html:' hist_toc.html > history_toc.html
$(RM) hist.html hist_toc.html
info: $(INFOOBJ)
dvi: $(DVIOBJ)
ps: $(PSOBJ)
html: $(HTMLOBJ)
clean:
$(RM) *.aux *.cp *.fn *.ky *.log *.pg *.toc *.tp *.vr *.cps *.pgs \
*.fns *.kys *.tps *.vrs *.o core
distclean: clean
mostlyclean: clean
maintainer-clean: clean
$(RM) *.dvi *.info *.info-* *.ps *.html
install: info
${INSTALL_DATA} readline.info $(infodir)/readline.info
${INSTALL_DATA} history.info $(infodir)/history.info
-77
View File
@@ -1,77 +0,0 @@
/* quit.h -- How to handle SIGINT gracefully. */
/* Copyright (C) 1993-2013 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined (_QUIT_H_)
#define _QUIT_H_
/* Non-zero means SIGINT has already ocurred. */
extern volatile sig_atomic_t interrupt_state;
extern volatile sig_atomic_t terminating_signal;
/* Macro to call a great deal. SIGINT just sets the interrupt_state variable.
When it is safe, put QUIT in the code, and the "interrupt" will take
place. The same scheme is used for terminating signals (e.g., SIGHUP)
and the terminating_signal variable. That calls a function which will
end up exiting the shell. */
#define QUIT \
do { \
if (terminating_signal) termsig_handler (terminating_signal); \
if (interrupt_state) throw_to_top_level (); \
} while (0)
#define CHECK_ALRM \
do { \
if (sigalrm_seen) \
longjmp (alrmbuf, 1); \
} while (0)
#define SETINTERRUPT interrupt_state = 1
#define CLRINTERRUPT interrupt_state = 0
#define ADDINTERRUPT interrupt_state++
#define DELINTERRUPT interrupt_state--
/* The same sort of thing, this time just for signals that would ordinarily
cause the shell to terminate. */
#define CHECK_TERMSIG \
do { \
if (terminating_signal) termsig_handler (terminating_signal); \
} while (0)
#define LASTSIG() \
(terminating_signal ? terminating_signal : (interrupt_state ? SIGINT : 0))
#define CHECK_WAIT_INTR \
do { \
if (wait_signal_received && this_shell_builtin && (this_shell_builtin == wait_builtin)) \
longjmp (wait_intr_buf, 1); \
} while (0)
#define RESET_SIGTERM \
do { \
sigterm_received = 0; \
} while (0)
#define CHECK_SIGTERM \
do { \
if (sigterm_received) termsig_handler (SIGTERM); \
} while (0)
#endif /* _QUIT_H_ */
-9
View File
@@ -1,9 +0,0 @@
BUILD_DIR=/usr/local/build/chet/bash/bash-current
THIS_SH=$BUILD_DIR/bash
PATH=$PATH:$BUILD_DIR
export THIS_SH PATH
rm -f /tmp/xx
/bin/sh "$@"
-126
View File
@@ -1,126 +0,0 @@
export LC_ALL=C
export LANG=C
if [ $UID -eq 0 ]; then
echo "execscript: the test suite should not be run as root" >&2
fi
set -- one two three
echo before exec1.sub: "$@"
echo calling exec1.sub
./exec1.sub aa bb cc dd ee
echo after exec1.sub with args: $?
./exec1.sub
echo after exec1.sub without args: $?
# set up a fixed path so we know notthere will not be found
PATH=/usr/bin:/bin:/usr/local/bin:
export PATH
notthere
echo $?
# this is iffy, since the error messages may vary from system to system
# and /tmp might not exist
ln -s ${THIS_SH} /tmp/bash 2>/dev/null
if [ -f /tmp/bash ]; then
/tmp/bash notthere
else
${THIS_SH} notthere
fi
echo $?
rm -f /tmp/bash
# /bin/sh should be there on all systems
${THIS_SH} /bin/sh
echo $?
# try executing a directory
/
echo $?
${THIS_SH} /
echo $?
# try sourcing a directory
. /
echo $?
# try sourcing a binary file -- post-2.04 versions don't do the binary file
# check, and will probably fail with `command not found', or status 127
# bash-4.1 and later check for 256 NUL characters and fail as binary files
# if there are more than that, it's probably binary
. ${THIS_SH} 2>/dev/null
echo $?
# post-bash-2.05 versions allow sourcing non-regular files
. /dev/null
echo $?
# kill two birds with one test -- test out the BASH_ENV code
echo echo this is bashenv > /tmp/bashenv
export BASH_ENV=/tmp/bashenv
${THIS_SH} ./exec3.sub
rm -f /tmp/bashenv
unset BASH_ENV
# we're resetting the $PATH to empty, so this should be last
PATH=
notthere
echo $?
command notthere
echo $?
command -p notthere
echo $?
# but -p should guarantee that we find all the standard utilities, even
# with an empty or unset $PATH
command -p sh -c 'echo this is $0'
unset PATH
command -p sh -c 'echo this is $0'
# a bug in bash before bash-2.01 caused PATH to be set to the empty string
# when command -p was run with PATH unset
echo ${PATH-unset}
echo "echo ok" | ${THIS_SH} -t
${THIS_SH} ./exec2.sub
echo $?
${THIS_SH} ./exec4.sub
# try exec'ing a command that cannot be found in $PATH
${THIS_SH} ./exec5.sub
# this was a bug in bash versions before bash-2.04
${THIS_SH} -c 'cat </dev/null | cat >/dev/null' >&-
# checks for proper return values in subshell commands with inverted return
# values
${THIS_SH} ./exec6.sub
# checks for properly deciding what constitutes an executable file
${THIS_SH} ./exec7.sub
${THIS_SH} -i ./exec8.sub
${THIS_SH} ./exec9.sub
true | `echo true` &
echo after
# Problem with bash at least back to version 3.0
${THIS_SH} -c 'VAR=0; VAR=1 command exec; exit ${VAR}'
# problem with bash through bash-4.1
(
exec /var/empty/nosuch
echo bad
) 2>/dev/null
[ $? = 127 ] || echo FAIL: bad exit status $? at $LINENO
-50
View File
@@ -1,50 +0,0 @@
:; ./shx
sh:
<&$fd ok
nlbq Mon Aug 3 02:45:00 EDT 1992
bang geoff
quote 712824302
setbq defmsgid=<1992Aug3.024502.6176@host>
bgwait sleep done... wait 6187
bash:
<&$fd ok
nlbq Mon Aug 3 02:45:09 EDT 1992
bang geoff
quote 712824311
setbq defmsgid=<1992Aug3.024512.6212@host>
bgwait sleep done... wait 6223
ash:
<&$fd shx1: 4: Syntax error: Bad fd number
nlbq Mon Aug 3 02:45:19 EDT 1992
bang geoff
quote getdate: `"now"' not a valid date
setbq defmsgid=<1992Aug3.` echo 024521
bgwait sleep done... wait 6241
ksh:
<&$fd ok
nlbq ./shx: 6248 Memory fault - core dumped
bang geoff
quote getdate: `"now"' not a valid date
setbq defmsgid=<1992Aug3.024530.6257@host>
bgwait no such job: 6265
wait 6265
sleep done...
zsh:
<&$fd ok
nlbq Mon Aug 3 02:45:36 EDT 1992
bang shx3: event not found: /s/ [4]
quote 712824337
setbq defmsgid=<..6290@host>
bgwait shx7: unmatched " [9]
sleep done...
:;
-10
View File
@@ -1,10 +0,0 @@
#! /bin/sh
for cmd in sh bash ash ksh zsh
do
echo
echo $cmd:
for demo in shx?
do
$cmd $demo
done
done
-94
View File
@@ -1,94 +0,0 @@
/* version.c -- distribution and version numbers. */
/* Copyright (C) 1989-2012 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdio.h>
#include "stdc.h"
#include "version.h"
#include "patchlevel.h"
#include "conftypes.h"
#include "bashintl.h"
extern char *shell_name;
/* Defines from version.h */
const char * const dist_version = DISTVERSION;
const int patch_level = PATCHLEVEL;
const int build_version = BUILDVERSION;
#ifdef RELSTATUS
const char * const release_status = RELSTATUS;
#else
const char * const release_status = (char *)0;
#endif
const char * const sccs_version = SCCSVERSION;
const char * const bash_copyright = N_("Copyright (C) 2012 Free Software Foundation, Inc.");
const char * const bash_license = N_("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
/* If == 31, shell compatible with bash-3.1, == 32 with bash-3.2, and so on */
int shell_compatibility_level = DEFAULT_COMPAT_LEVEL;
/* Functions for getting, setting, and displaying the shell version. */
/* Forward declarations so we don't have to include externs.h */
extern char *shell_version_string __P((void));
extern void show_shell_version __P((int));
/* Give version information about this shell. */
char *
shell_version_string ()
{
static char tt[32] = { '\0' };
if (tt[0] == '\0')
{
if (release_status)
#if defined (HAVE_SNPRINTF)
snprintf (tt, sizeof (tt), "%s.%d(%d)-%s", dist_version, patch_level, build_version, release_status);
#else
sprintf (tt, "%s.%d(%d)-%s", dist_version, patch_level, build_version, release_status);
#endif
else
#if defined (HAVE_SNPRINTF)
snprintf (tt, sizeof (tt), "%s.%d(%d)", dist_version, patch_level, build_version);
#else
sprintf (tt, "%s.%d(%d)", dist_version, patch_level, build_version);
#endif
}
return tt;
}
void
show_shell_version (extended)
int extended;
{
printf (_("GNU bash, version %s (%s)\n"), shell_version_string (), MACHTYPE);
if (extended)
{
printf ("%s\n", _(bash_copyright));
printf ("%s\n", _(bash_license));
printf ("%s\n", _("This is free software; you are free to change and redistribute it."));
printf ("%s\n", _("There is NO WARRANTY, to the extent permitted by law."));
}
}