diff options
Diffstat (limited to 'examples')
31 files changed, 493 insertions, 101 deletions
diff --git a/examples/complete/bashcc-1.0.1.tar.gz b/examples/complete/bashcc-1.0.1.tar.gz Binary files differnew file mode 100644 index 0000000..d680435 --- /dev/null +++ b/examples/complete/bashcc-1.0.1.tar.gz diff --git a/examples/functions/coproc.bash b/examples/functions/coproc.bash index d9175a1..61dc8d7 100644 --- a/examples/functions/coproc.bash +++ b/examples/functions/coproc.bash @@ -63,7 +63,7 @@ function coprocess () shift local old_trap=$(trap -p SIGPIPE) trap 'coprocess close -SIGPIPE' SIGPIPE - if [ $# -eq 1 -a "$1" = "--stdin" ] ; then + if [ $# -eq 1 ] && [ "$1" = "--stdin" ] ; then cat >&61 else echo "$@" >&61 @@ -106,4 +106,3 @@ function coprocess () coprocess status return $? } - diff --git a/examples/functions/csh-compat b/examples/functions/csh-compat index a855eaf..b8dcf8f 100644 --- a/examples/functions/csh-compat +++ b/examples/functions/csh-compat @@ -33,15 +33,16 @@ function alias () then declare -f $1 else - echo $2 | egrep -s '(\!|#)' 2>/dev/null - if [ $? -eq 0 ] - then + case $2 in + *[#\!]*) comm=$(echo $2 | sed 's/\\!\*/\"$\@\"/g s/\\!:\([1-9]\)/\"$\1\"/g s/#/\\#/g') - else - comm="$2 \"\$@\"" - fi + ;; + *) + comm="$2 \"\$@\"" ;; + esac + eval function $1 \(\) "{" command "$comm" "; }" fi } diff --git a/examples/functions/exitstat b/examples/functions/exitstat index 2828a89..f49ebf5 100644 --- a/examples/functions/exitstat +++ b/examples/functions/exitstat @@ -8,7 +8,7 @@ function check_exit_status () local status="$?" local signal="" - if [ ${status} -ne 0 -a ${status} != 128 ]; then + if [ ${status} -ne 0 ] && [ ${status} != 128 ]; then # If process exited by a signal, determine name of signal. if [ ${status} -gt 128 ]; then signal="$(builtin kill -l $((${status} - 128)) 2>/dev/null)" diff --git a/examples/functions/getoptx.bash b/examples/functions/getoptx.bash index 23e5de5..d402c7d 100644 --- a/examples/functions/getoptx.bash +++ b/examples/functions/getoptx.bash @@ -134,7 +134,7 @@ function getoptex() let OPTIND || OPTIND=1 [ $OPTIND -lt $# ] || return 1 shift $OPTIND - if [ "$1" != "-" -a "$1" != "${1#-}" ] + if [ "$1" != "-" ] && [ "$1" != "${1#-}" ] then OPTIND=$[OPTIND+1]; if [ "$1" != "--" ] then local o @@ -299,4 +299,3 @@ function getopt() #************************************** #*** (end of getopt2) *** - diff --git a/examples/functions/kshenv b/examples/functions/kshenv index 2b9a6eb..7594f2d 100644 --- a/examples/functions/kshenv +++ b/examples/functions/kshenv @@ -207,7 +207,7 @@ substring () ;; esac # test for too few or too many arguments - if [ x"$1" = x -o $# -gt 2 ]; then + if [ x"$1" = x ] || [ $# -gt 2 ]; then print -u2 'substring: bad argument count' return 1 fi diff --git a/examples/functions/manpage b/examples/functions/manpage index 224643e..60f9aed 100644 --- a/examples/functions/manpage +++ b/examples/functions/manpage @@ -70,7 +70,7 @@ function whatis () function apropos () { - whatis_internal "$1" "fgrep" + whatis_internal "$1" "grep -F" } # Note: "-" and "-t" together not supported. This man could be @@ -102,7 +102,7 @@ function man () g="grep -w" a=$(basename "$2") else - g=fgrep + g="grep -F" a="$2" fi whatis_internal "$a" "$g" diff --git a/examples/functions/recurse b/examples/functions/recurse index 14c4b9e..f69cd50 100644 --- a/examples/functions/recurse +++ b/examples/functions/recurse @@ -44,15 +44,15 @@ function recurse if cd "$1" ; then for file in $2; do - if [ -f "$file" -o -d "$file" ]; then + if [ -f "$file" ] || [ -d "$file" ]; then eval "$3" fi done for file in .* * ; do - if [ "$file" = "." -o "$file" = ".." ] ; then + if [ "$file" = "." ] || [ "$file" = ".." ] ; then continue fi - if [ -d "$file" -a ! -L "$file" ]; then + if [ -d "$file" ] && [ ! -L "$file" ]; then recurse "$file" "$2" "$3" "$path" fi done @@ -61,4 +61,3 @@ function recurse } recurse "$1" "$2" 'echo "$path$file"' - diff --git a/examples/functions/substr b/examples/functions/substr index c557677..a80b3b4 100644 --- a/examples/functions/substr +++ b/examples/functions/substr @@ -30,7 +30,7 @@ substr() ;; esac - if [ "$#" -eq 0 -o "$#" -gt 2 ] ; then + if [ "$#" -eq 0 ] || [ "$#" -gt 2 ] ; then echo "substr: bad argument count" return 2 fi diff --git a/examples/functions/substr2 b/examples/functions/substr2 index f5e7547..2bb8d36 100644 --- a/examples/functions/substr2 +++ b/examples/functions/substr2 @@ -32,7 +32,7 @@ substr() shift $[ $OPTIND -1 ] fi - if [ "$#" -eq 0 -o "$#" -gt 2 ] ; then + if [ "$#" -eq 0 ] || [ "$#" -gt 2 ] ; then echo "substr: bad argument count" return 2 fi diff --git a/examples/functions/xalias.bash b/examples/functions/xalias.bash index 29e8bfb..88a00dc 100644 --- a/examples/functions/xalias.bash +++ b/examples/functions/xalias.bash @@ -7,15 +7,16 @@ function xalias () then declare -f $1 else - echo $2 | egrep -q '(\!|#)' - if [ $? -eq 0 ] - then + case $2 in + *[#\!]*) comm=$(echo $2 | sed 's/\\!\*/\"$\@\"/g s/\\!:\([1-9]\)/\"$\1\"/g s/#/\\#/g') - else - comm="$2 \"\$@\"" - fi + ;; + *) + comm="$2 \"\$@\"" ;; + esac + eval function $1 \(\) "{" command "$comm" "; }" fi } diff --git a/examples/functions/xfind.bash b/examples/functions/xfind.bash index 578e883..6d29038 100644 --- a/examples/functions/xfind.bash +++ b/examples/functions/xfind.bash @@ -39,7 +39,7 @@ xfind() # and directories that start with a period. for x in * ; do - if [ -d "$x" -a ! -L "$x" ] ; then + if [ -d "$x" ] && [ ! -L "$x" ] ; then $FUNCNAME "$x" "$2" "$action" fi done diff --git a/examples/loadables/Makefile.in b/examples/loadables/Makefile.in index ed1721f..356baef 100644 --- a/examples/loadables/Makefile.in +++ b/examples/loadables/Makefile.in @@ -72,7 +72,7 @@ INC = -I. -I.. -I$(topdir) -I$(topdir)/lib -I$(topdir)/builtins \ 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 + uname sync push ln unlink cut realpath getconf strftime OTHERPROG = necho hello cat all: $(SHOBJ_STATUS) @@ -172,6 +172,9 @@ cut: cut.o 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. # @@ -221,3 +224,4 @@ sync.o: sync.c push.o: push.c mkdir.o: mkdir.c realpath.o: realpath.c +strftime.o: strftime.c diff --git a/examples/loadables/finfo.c b/examples/loadables/finfo.c index b633629..c1682ed 100644 --- a/examples/loadables/finfo.c +++ b/examples/loadables/finfo.c @@ -247,10 +247,17 @@ 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("Device (major/minor): %d (%d/%d)\n", (int) (st->st_dev & 0xFF), - (int) major (st->st_dev), - (int) minor (st->st_dev)); printf("Inode: %d\n", (int) st->st_ino); printf("Mode: (%o) ", (int) st->st_mode); printmode((int) st->st_mode); diff --git a/examples/loadables/getconf.c b/examples/loadables/getconf.c index 5d079b6..cc6d50b 100644 --- a/examples/loadables/getconf.c +++ b/examples/loadables/getconf.c @@ -78,7 +78,7 @@ extern int errno; struct conf_variable { const char *name; - enum { SYSCONF, CONFSTR, PATHCONF, CONSTANT, G_UNDEF } type; + enum { SYSCONF, CONFSTR, PATHCONF, CONSTANT, LLCONST, G_UNDEF } type; long value; }; @@ -94,6 +94,11 @@ static long sysconf __P((int)); static long pathconf __P((const char *, int)); #endif +/* Hack to `encode' values wider than long into a conf_variable */ +#define VAL_LLONG_MIN -1000 +#define VAL_LLONG_MAX -1001 +#define VAL_ULLONG_MAX -1002 + static const struct conf_variable conf_table[] = { /* POSIX.2 Configurable Variable Values */ @@ -169,6 +174,8 @@ static const struct conf_variable conf_table[] = { "POSIX_V6_ILP32_OFF32_CFLAGS", CONFSTR, _CS_POSIX_V6_ILP32_OFF32_CFLAGS }, { "POSIX_V6_ILP32_OFF32_LDFLAGS", CONFSTR, _CS_POSIX_V6_ILP32_OFF32_LDFLAGS }, { "POSIX_V6_ILP32_OFF32_LIBS", CONFSTR, _CS_POSIX_V6_ILP32_OFF32_LIBS }, +#endif +#if defined (_CS_POSIX_V6_ILP32_OFF32_LINTFLAGS) { "POSIX_V6_ILP32_OFF32_LINTFLAGS", CONFSTR, _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS }, #endif #if defined (_SC_POSIX_V6_ILP32_OFFBIG) @@ -178,6 +185,8 @@ static const struct conf_variable conf_table[] = { "POSIX_V6_ILP32_OFFBIG_CFLAGS", CONFSTR, _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS }, { "POSIX_V6_ILP32_OFFBIG_LDFLAGS", CONFSTR, _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS }, { "POSIX_V6_ILP32_OFFBIG_LIBS", CONFSTR, _CS_POSIX_V6_ILP32_OFFBIG_LIBS }, +#endif +#if defined (_CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS) { "POSIX_V6_ILP32_OFFBIG_LINTFLAGS", CONFSTR, _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS }, #endif #if defined (_SC_POSIX_V6_LP64_OFF64) @@ -187,6 +196,8 @@ static const struct conf_variable conf_table[] = { "POSIX_V6_LP64_OFF64_CFLAGS", CONFSTR, _CS_POSIX_V6_LP64_OFF64_CFLAGS }, { "POSIX_V6_LP64_OFF64_LDFLAGS", CONFSTR, _CS_POSIX_V6_LP64_OFF64_LDFLAGS }, { "POSIX_V6_LP64_OFF64_LIBS", CONFSTR, _CS_POSIX_V6_LP64_OFF64_LIBS }, +#endif +#if defined (CS_POSIX_V6_LP64_OFF64_LINTFLAGS) { "POSIX_V6_LP64_OFF64_LINTFLAGS", CONFSTR, _CS_POSIX_V6_LP64_OFF64_LINTFLAGS }, #endif #if defined (_SC_POSIX_V6_LPBIG_OFFBIG) @@ -196,9 +207,15 @@ static const struct conf_variable conf_table[] = { "POSIX_V6_LPBIG_OFFBIG_CFLAGS", CONFSTR, _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS }, { "POSIX_V6_LPBIG_OFFBIG_LDFLAGS", CONFSTR, _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS }, { "POSIX_V6_LPBIG_OFFBIG_LIBS", CONFSTR, _CS_POSIX_V6_LPBIG_OFFBIG_LIBS }, +#endif +#if defined (_CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS) { "POSIX_V6_LPBIG_OFFBIG_LINTFLAGS", CONFSTR, _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS }, #endif +#if defined (_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS) + { "POSIX_6_WIDTH_RESTRICTED_ENVS", CONFSTR, _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS }, +#endif + /* POSIX.2 Utility Limit Minimum Values */ #ifdef _POSIX2_BC_BASE_MAX { "POSIX2_BC_BASE_MAX", CONSTANT, _POSIX2_BC_BASE_MAX }, @@ -220,6 +237,11 @@ static const struct conf_variable conf_table[] = #else { "POSIX2_BC_STRING_MAX", G_UNDEF, -1 }, #endif +#ifdef _POSIX2_CHARCLASS_NAME_MAX + { "POSIX2_CHARCLASS_NAME_MAX", CONSTANT, _POSIX2_CHARCLASS_NAME_MAX }, +#else + { "POSIX2_CHARCLASS_NAME_MAX", G_UNDEF, -1 }, +#endif #ifdef _POSIX2_COLL_WEIGHTS_MAX { "POSIX2_COLL_WEIGHTS_MAX", CONSTANT, _POSIX2_COLL_WEIGHTS_MAX }, #else @@ -251,7 +273,83 @@ static const struct conf_variable conf_table[] = # endif #endif +#ifdef _POSIX2_BC_BASE_MAX + { "_POSIX2_BC_BASE_MAX", CONSTANT, _POSIX2_BC_BASE_MAX }, +#else + { "_POSIX2_BC_BASE_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX2_BC_DIM_MAX + { "_POSIX2_BC_DIM_MAX", CONSTANT, _POSIX2_BC_DIM_MAX }, +#else + { "_POSIX2_BC_DIM_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX2_BC_SCALE_MAX + { "_POSIX2_BC_SCALE_MAX", CONSTANT, _POSIX2_BC_SCALE_MAX }, +#else + { "_POSIX2_BC_SCALE_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX2_BC_STRING_MAX + { "_POSIX2_BC_STRING_MAX", CONSTANT, _POSIX2_BC_STRING_MAX }, +#else + { "_POSIX2_BC_STRING_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX2_CHARCLASS_NAME_MAX + { "_POSIX2_CHARCLASS_NAME_MAX", CONSTANT, _POSIX2_CHARCLASS_NAME_MAX }, +#else + { "_POSIX2_CHARCLASS_NAME_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX2_COLL_WEIGHTS_MAX + { "_POSIX2_COLL_WEIGHTS_MAX", CONSTANT, _POSIX2_COLL_WEIGHTS_MAX }, +#else + { "_POSIX2_COLL_WEIGHTS_MAX", G_UNDEF, -1 }, +#endif +#if defined (_POSIX2_EQUIV_CLASS_MAX) + { "POSIX2_EQUIV_CLASS_MAX", CONSTANT, _POSIX2_EQUIV_CLASS_MAX }, +#endif +#ifdef _POSIX2_EXPR_NEST_MAX + { "_POSIX2_EXPR_NEST_MAX", CONSTANT, _POSIX2_EXPR_NEST_MAX }, +#else + { "_POSIX2_EXPR_NEST_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX2_LINE_MAX + { "_POSIX2_LINE_MAX", CONSTANT, _POSIX2_LINE_MAX }, +#else + { "_POSIX2_LINE_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX2_RE_DUP_MAX + { "_POSIX2_RE_DUP_MAX", CONSTANT, _POSIX2_RE_DUP_MAX }, +#else + { "_POSIX2_RE_DUP_MAX", G_UNDEF, -1 }, +#endif + + /* X/OPEN Maxmimum Values */ +#ifdef _XOPEN_IOV_MAX + { "_XOPEN_IOV_MAX", CONSTANT, _XOPEN_IOV_MAX }, +#else + { "_XOPEN_IOV_MAX", G_UNDEF, -1 }, +#endif +#ifdef _XOPEN_NAME_MAX + { "_XOPEN_NAME_MAX", CONSTANT, _XOPEN_NAME_MAX }, +#else + { "_XOPEN_NAME_MAX", G_UNDEF, -1 }, +#endif +#ifdef _XOPEN_PATH_MAX + { "_XOPEN_PATH_MAX", CONSTANT, _XOPEN_PATH_MAX }, +#else + { "_XOPEN_PATH_MAX", G_UNDEF, -1 }, +#endif + /* POSIX.1 Minimum Values */ +#ifdef _POSIX_AIO_LISTIO_MAX + { "_POSIX_AIO_LISTIO_MAX", CONSTANT, _POSIX_AIO_LISTIO_MAX }, +#else + { "_POSIX_AIO_LISTIO_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_AIO_MAX + { "_POSIX_AIO_MAX", CONSTANT, _POSIX_AIO_MAX }, +#else + { "_POSIX_AIO_MAX", G_UNDEF, -1 }, +#endif #ifdef _POSIX_ARG_MAX { "_POSIX_ARG_MAX", CONSTANT, _POSIX_ARG_MAX }, #else @@ -260,13 +358,28 @@ static const struct conf_variable conf_table[] = #ifdef _POSIX_CHILD_MAX { "_POSIX_CHILD_MAX", CONSTANT, _POSIX_CHILD_MAX }, #else - { "_POSIX_CHILD_MAX", G_UNDEF, -1 }, + { "_POSIX_CHILD_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_DELAYTIMER_MAX + { "_POSIX_DELAYTIMER_MAX", CONSTANT, _POSIX_DELAYTIMER_MAX }, +#else + { "_POSIX_DELAYTIMER_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_HOST_NAME_MAX + { "_POSIX_HOST_NAME_MAX", CONSTANT, _POSIX_HOST_NAME_MAX }, +#else + { "_POSIX_HOST_NAME_MAX", G_UNDEF, -1 }, #endif #ifdef _POSIX_LINK_MAX { "_POSIX_LINK_MAX", CONSTANT, _POSIX_LINK_MAX }, #else { "_POSIX_LINK_MAX", G_UNDEF, -1 }, #endif +#ifdef _POSIX_LOGIN_NAME_MAX + { "_POSIX_LOGIN_NAME_MAX", CONSTANT, _POSIX_LOGIN_NAME_MAX }, +#else + { "_POSIX_LOGIN_NAME_MAX", G_UNDEF, -1 }, +#endif #ifdef _POSIX_MAX_CANON { "_POSIX_MAX_CANON", CONSTANT, _POSIX_MAX_CANON }, #else @@ -277,6 +390,16 @@ static const struct conf_variable conf_table[] = #else { "_POSIX_MAX_INPUT", G_UNDEF, -1 }, #endif +#ifdef _POSIX_MQ_OPEN_MAX + { "_POSIX_MQ_OPEN_MAX", CONSTANT, _POSIX_MQ_OPEN_MAX }, +#else + { "_POSIX_MQ_OPEN_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_MQ_PRIO_MAX + { "_POSIX_MQ_PRIO_MAX", CONSTANT, _POSIX_MQ_PRIO_MAX }, +#else + { "_POSIX_MQ_PRIO_MAX", G_UNDEF, -1 }, +#endif #ifdef _POSIX_NAME_MAX { "_POSIX_NAME_MAX", CONSTANT, _POSIX_NAME_MAX }, #else @@ -302,20 +425,129 @@ static const struct conf_variable conf_table[] = #else { "_POSIX_PIPE_BUF", G_UNDEF, -1 }, #endif +#ifdef _POSIX_RE_DUP_MAX + { "_POSIX_RE_DUP_MAX", CONSTANT, _POSIX_RE_DUP_MAX }, +#else + { "_POSIX_RE_DUP_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_RTSIG_MAX + { "_POSIX_RTSIG_MAX", CONSTANT, _POSIX_RTSIG_MAX }, +#else + { "_POSIX_RTSIG_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_SEM_NSEMS_MAX + { "_POSIX_SEM_NSEMS_MAX", CONSTANT, _POSIX_SEM_NSEMS_MAX }, +#else + { "_POSIX_SEM_NSEMS_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_SEM_VALUE_MAX + { "_POSIX_SEM_VALUE_MAX", CONSTANT, _POSIX_SEM_VALUE_MAX }, +#else + { "_POSIX_SEM_VALUE_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_SIGQUEUE_MAX + { "_POSIX_SIGQUEUE_MAX", CONSTANT, _POSIX_SIGQUEUE_MAX }, +#else + { "_POSIX_SIGQUEUE_MAX", G_UNDEF, -1 }, +#endif #ifdef _POSIX_SSIZE_MAX { "_POSIX_SSIZE_MAX", CONSTANT, _POSIX_SSIZE_MAX }, #else { "_POSIX_SSIZE_MAX", G_UNDEF, -1 }, #endif +#ifdef _POSIX_SS_REPL_MAX + { "_POSIX_SS_REPL_MAX", CONSTANT, _POSIX_SS_REPL_MAX }, +#else + { "_POSIX_SS_REPL_MAX", G_UNDEF, -1 }, +#endif #ifdef _POSIX_STREAM_MAX { "_POSIX_STREAM_MAX", CONSTANT, _POSIX_STREAM_MAX }, #else { "_POSIX_STREAM_MAX", G_UNDEF, -1 }, #endif +#ifdef _POSIX_SYMLINK_MAX + { "_POSIX_SYMLINK_MAX", CONSTANT, _POSIX_SYMLINK_MAX }, +#else + { "_POSIX_SYMLINK_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_SYMLOOP_MAX + { "_POSIX_SYMLOOP_MAX", CONSTANT, _POSIX_SYMLOOP_MAX }, +#else + { "_POSIX_SYMLOOP_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_THREAD_DESTRUCTOR_ITERATIONS + { "_POSIX_THREAD_DESTRUCTOR_ITERATIONS", CONSTANT, _POSIX_THREAD_DESTRUCTOR_ITERATIONS }, +#else + { "_POSIX_THREAD_DESTRUCTOR_ITERATIONS", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_THREAD_KEYS_MAX + { "_POSIX_THREAD_KEYS_MAX", CONSTANT, _POSIX_THREAD_KEYS_MAX }, +#else + { "_POSIX_THREAD_KEYS_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_THREAD_THREADS_MAX + { "_POSIX_THREAD_THREADS_MAX",CONSTANT, _POSIX_THREAD_THREADS_MAX }, +#else + { "_POSIX_THREAD_THREADS_MAX",G_UNDEF, -1 }, +#endif +#ifdef _POSIX_TIMER_MAX + { "_POSIX_TIMER_MAX", CONSTANT, _POSIX_TIMER_MAX }, +#else + { "_POSIX_TIMER_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_TRACE_EVENT_NAME_MAX + { "_POSIX_TRACE_EVENT_NAME_MAX", CONSTANT, _POSIX_TRACE_EVENT_NAME_MAX }, +#else + { "_POSIX_TRACE_EVENT_NAME_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_TRACE_NAME_MAX + { "_POSIX_TRACE_NAME_MAX", CONSTANT, _POSIX_TRACE_NAME_MAX }, +#else + { "_POSIX_TRACE_NAME_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_TRACE_SYS_MAX + { "_POSIX_TRACE_SYS_MAX", CONSTANT, _POSIX_TRACE_SYS_MAX }, +#else + { "_POSIX_TRACE_SYS_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_TRACE_USER_EVENT_MAX + { "_POSIX_TRACE_USER_EVENT_MAX", CONSTANT, _POSIX_TRACE_USER_EVENT_MAX }, +#else + { "_POSIX_TRACE_USER_EVENT_MAX", G_UNDEF, -1 }, +#endif +#ifdef _POSIX_TTY_NAME_MAX + { "_POSIX_TTY_NAME_MAX", CONSTANT, _POSIX_TTY_NAME_MAX }, +#else + { "_POSIX_TTY_NAME_MAX", G_UNDEF, -1 }, +#endif #ifdef _POSIX_TZNAME_MAX { "_POSIX_TZNAME_MAX", CONSTANT, _POSIX_TZNAME_MAX }, #else - { "_POSIX_TZNAME_MAX", G_UNDEF, -1 }, + { "_POSIX_TZNAME_MAX", G_UNDEF, -1 }, +#endif + + /* POSIX.1 Maximum Values */ +#ifdef _POSIX_CLOCKRES_MIN + { "_POSIX_CLOCKRES_MIN", CONSTANT, _POSIX_CLOCKRES_MIN }, +#else + { "_POSIX_CLOCKRES_MIN", G_UNDEF, -1 }, +#endif + + /* POSIX.1-2001/XPG6 (and later) Runtime Invariants from <limits.h> */ +#ifdef _SC_SS_REPL_MAX + { "SS_REPL_MAX", SYSCONF, _SC_SS_REPL_MAX }, +#endif +#ifdef _SC_TRACE_EVENT_NAME_MAX + { "TRACE_EVENT_NAME_MAX", SYSCONF, _SC_TRACE_EVENT_NAME_MAX }, +#endif +#ifdef _SC_TRACE_NAME_MAX + { "TRACE_NAME_MAX", SYSCONF, _SC_TRACE_NAME_MAX }, +#endif +#ifdef _SC_TRACE_SYS_MAX + { "TRACE_SYS_MAX", SYSCONF, _SC_TRACE_SYS_MAX }, +#endif +#ifdef _SC_TRACE_USER_EVENT_MAX + { "TRACE_USER_EVENT_MAX", SYSCONF, _SC_TRACE_USER_EVENT_MAX }, #endif /* POSIX.2/XPG 4.2 (and later) Symbolic Utility Limits */ @@ -361,55 +593,58 @@ static const struct conf_variable conf_table[] = #ifdef NL_TEXTMAX { "NL_TEXTMAX", CONSTANT, NL_TEXTMAX }, #endif +#ifdef _SC_RAW_SOCKET + { "RAW_SOCKET", SYSCONF, _SC_RAW_SOCKET }, +#endif #ifdef _SC_RE_DUP_MAX { "RE_DUP_MAX", SYSCONF, _SC_RE_DUP_MAX }, #endif /* POSIX.2 Optional Facility Configuration Values */ #ifdef _SC_2_C_BIND - { "_POSIX2_C_BIND", SYSCONF, _SC_2_C_BIND }, + { "POSIX2_C_BIND", SYSCONF, _SC_2_C_BIND }, #else - { "_POSIX2_C_BIND", G_UNDEF, -1 }, + { "POSIX2_C_BIND", G_UNDEF, -1 }, #endif #ifdef _SC_2_C_DEV - { "_POSIX2_C_DEV", SYSCONF, _SC_2_C_DEV }, + { "POSIX2_C_DEV", SYSCONF, _SC_2_C_DEV }, #else - { "_POSIX2_C_DEV", G_UNDEF, -1 }, + { "POSIX2_C_DEV", G_UNDEF, -1 }, #endif #if defined (_SC_2_C_VERSION) - { "_POSIX2_C_VERSION", SYSCONF, _SC_2_C_VERSION }, + { "POSIX2_C_VERSION", SYSCONF, _SC_2_C_VERSION }, #else - { "_POSIX2_C_VERSION", G_UNDEF, -1 }, + { "POSIX2_C_VERSION", G_UNDEF, -1 }, #endif #if defined (_SC_2_CHAR_TERM) - { "_POSIX2_CHAR_TERM", SYSCONF, _SC_2_CHAR_TERM }, + { "POSIX2_CHAR_TERM", SYSCONF, _SC_2_CHAR_TERM }, #else - { "_POSIX2_CHAR_TERM", G_UNDEF, -1 }, + { "POSIX2_CHAR_TERM", G_UNDEF, -1 }, #endif #ifdef _SC_2_FORT_DEV - { "_POSIX2_FORT_DEV", SYSCONF, _SC_2_FORT_DEV }, + { "POSIX2_FORT_DEV", SYSCONF, _SC_2_FORT_DEV }, #else - { "_POSIX2_FORT_DEV", G_UNDEF, -1 }, + { "POSIX2_FORT_DEV", G_UNDEF, -1 }, #endif #ifdef _SC_2_FORT_RUN - { "_POSIX2_FORT_RUN", SYSCONF, _SC_2_FORT_RUN }, + { "POSIX2_FORT_RUN", SYSCONF, _SC_2_FORT_RUN }, #else - { "_POSIX2_FORT_RUN", G_UNDEF, -1 }, + { "POSIX2_FORT_RUN", G_UNDEF, -1 }, #endif #ifdef _SC_2_LOCALEDEF - { "_POSIX2_LOCALEDEF", SYSCONF, _SC_2_LOCALEDEF }, + { "POSIX2_LOCALEDEF", SYSCONF, _SC_2_LOCALEDEF }, #else - { "_POSIX2_LOCALEDEF", G_UNDEF, -1 }, + { "POSIX2_LOCALEDEF", G_UNDEF, -1 }, #endif #ifdef _SC_2_SW_DEV - { "_POSIX2_SW_DEV", SYSCONF, _SC_2_SW_DEV }, + { "POSIX2_SW_DEV", SYSCONF, _SC_2_SW_DEV }, #else - { "_POSIX2_SW_DEV", G_UNDEF, -1 }, + { "POSIX2_SW_DEV", G_UNDEF, -1 }, #endif #if defined (_SC2_UPE) - { "_POSIX2_UPE", SYSCONF, _SC_2_UPE }, + { "POSIX2_UPE", SYSCONF, _SC_2_UPE }, #else - { "_POSIX2_UPE", G_UNDEF, -1 }, + { "POSIX2_UPE", G_UNDEF, -1 }, #endif #if !defined (_POSIX2_VERSION) && defined (_SC_2_VERSION) { "_POSIX2_VERSION", SYSCONF, _SC_2_VERSION }, @@ -418,13 +653,18 @@ static const struct conf_variable conf_table[] = #endif #if defined (_SC_REGEX_VERSION) { "REGEX_VERSION", SYSCONF, _SC_REGEX_VERSION }, + { "_REGEX_VERSION", SYSCONF, _SC_REGEX_VERSION }, #else { "REGEX_VERSION", G_UNDEF, -1 }, + { "_REGEX_VERSION", G_UNDEF, -1 }, #endif #if defined (_SC_2_PBS) { "_POSIX2_PBS", SYSCONF, _SC_2_PBS }, { "_POSIX2_PBS_ACCOUNTING", SYSCONF, _SC_2_PBS_ACCOUNTING }, +# if defined (_SC_2_PBS_CHECKPOINT) + { "_POSIX2_PBS_CHECKPOINT", SYSCONF, _SC_2_PBS_CHECKPOINT }, +# endif { "_POSIX2_PBS_LOCATE", SYSCONF, _SC_2_PBS_LOCATE }, { "_POSIX2_PBS_MESSAGE", SYSCONF, _SC_2_PBS_MESSAGE }, { "_POSIX2_PBS_TRACK", SYSCONF, _SC_2_PBS_TRACK }, @@ -517,6 +757,9 @@ static const struct conf_variable conf_table[] = #if defined (_SC_FSYNC) { "_POSIX_FSYNC", SYSCONF, _SC_FSYNC }, #endif +#if defined (_SC_IPV6) + { "_POSIX_IPV6", SYSCONF, _SC_IPV6 }, +#endif #if defined (_SC_JOB_CONTROL) { "_POSIX_JOB_CONTROL", SYSCONF, _SC_JOB_CONTROL }, #endif @@ -556,6 +799,9 @@ static const struct conf_variable conf_table[] = #if defined (_SC_READER_WRITER_LOCKS) { "_POSIX_READER_WRITER_LOCKS", SYSCONF, _SC_READER_WRITER_LOCKS }, #endif +#if defined (_SC_RAW_SOCKETS) + { "_POSIX_RAW_SOCKETS", SYSCONF, _SC_RAW_SOCKETS }, +#endif #if defined (_SC_REALTIME_SIGNALS) { "_POSIX_REALTIME_SIGNALS", SYSCONF, _SC_REALTIME_SIGNALS }, #endif @@ -587,6 +833,9 @@ static const struct conf_variable conf_table[] = #if defined (_SC_SPORADIC_SERVER) { "_POSIX_SPORADIC_SERVER", SYSCONF, _SC_SPORADIC_SERVER }, #endif +#if defined (_SC_SYMLOOP_MAX) + { "_POSIX_SYMLOOP_MAX", SYSCONF, _SC_SYMLOOP_MAX }, +#endif #if defined (_SC_SYNCHRONIZED_IO) { "_POSIX_SYNCHRONIZED_IO", SYSCONF, _SC_SYNCHRONIZED_IO }, #endif @@ -701,9 +950,6 @@ static const struct conf_variable conf_table[] = #if defined (_SC_AIO_PRIO_DELTA_MAX) { "AIO_PRIO_DELTA_MAX", SYSCONF, _SC_AIO_PRIO_DELTA_MAX }, #endif -#if defined (_SC_DELAYTIMER_MAX) - { "DELAYTIMER_MAX", SYSCONF, _SC_DELAYTIMER_MAX }, -#endif #if defined (_SC_MQ_OPEN_MAX) { "MQ_OPEN_MAX", SYSCONF, _SC_MQ_OPEN_MAX }, #endif @@ -758,6 +1004,9 @@ static const struct conf_variable conf_table[] = #if defined (_SC_XOPEN_SHM) { "_XOPEN_SHM", SYSCONF, _SC_XOPEN_SHM }, #endif +#if defined (_SC_XOPEN_STREAMS) + { "_XOPEN_STREAMS", SYSCONF, _SC_XOPEN_STREAMS }, +#endif #if defined (_SC_XOPEN_UNIX) { "_XOPEN_UNIX", SYSCONF, _SC_XOPEN_UNIX }, #endif @@ -842,6 +1091,10 @@ static const struct conf_variable conf_table[] = { "INT_BIT", CONSTANT, INT_BIT }, { "INT_MAX", CONSTANT, INT_MAX }, { "INT_MIN", CONSTANT, INT_MIN }, +#ifdef LLONG_MAX + { "LLONG_MAX", LLCONST, VAL_LLONG_MAX }, + { "LLONG_MIN", LLCONST, VAL_LLONG_MIN }, +#endif { "LONG_BIT", CONSTANT, LONG_BIT }, { "LONG_MAX", CONSTANT, LONG_MAX }, { "LONG_MIN", CONSTANT, LONG_MIN }, @@ -856,6 +1109,9 @@ static const struct conf_variable conf_table[] = { "SSIZE_MAX", CONSTANT, SSIZE_MAX }, { "UCHAR_MAX", CONSTANT, UCHAR_MAX }, { "UINT_MAX", CONSTANT, UINT_MAX }, +#ifdef ULLONG_MAX + { "ULLONG_MAX", LLCONST, VAL_ULLONG_MAX }, +#endif { "ULONG_MAX", CONSTANT, ULONG_MAX }, { "USHRT_MAX", CONSTANT, USHRT_MAX }, { "WORD_BIT", CONSTANT, WORD_BIT }, @@ -940,6 +1196,24 @@ int all; printf("undefined\n"); break; +#ifdef LLONG_MAX + case LLCONST: + switch (cp->value) { + default: + case VAL_LLONG_MIN: + printf ("%lld\n", LLONG_MIN); + break; + case VAL_LLONG_MAX: + printf ("%lld\n", LLONG_MAX); + break; +# if (ULLONG_MAX != LLONG_MAX) + case VAL_ULLONG_MAX: + printf ("%llu\n", ULLONG_MAX); + break; +# endif + } + break; +#endif case CONSTANT: switch (cp->value) { case UCHAR_MAX: diff --git a/examples/loadables/strftime.c b/examples/loadables/strftime.c new file mode 100644 index 0000000..92f489e --- /dev/null +++ b/examples/loadables/strftime.c @@ -0,0 +1,105 @@ +/* strftime - loadable builtin interface to strftime(3) */ + +/* See Makefile for compilation details. */ + +#include <config.h> + +#if defined (HAVE_UNISTD_H) +# include <unistd.h> +#endif + +#include "bashtypes.h" +#include "posixtime.h" + +#include <stdio.h> + +#include "builtins.h" +#include "shell.h" +#include "common.h" + +int +strftime_builtin (list) + WORD_LIST *list; +{ + char *format, *tbuf; + size_t tbsize, tsize; + time_t secs; + struct tm *t; + int n; + intmax_t i; + + if (list == 0) + { + builtin_usage (); + return (EX_USAGE); + } + + if (no_options (list)) + return (EX_USAGE); + + format = list->word->word; + if (format == 0 || *format == 0) + { + printf ("\n"); + return (EXECUTION_SUCCESS); + } + + list = list->next; + + if (list && list->word->word) + { + n = legal_number (list->word->word, &i); + if (n == 0 || i < 0 || i != (time_t)i) + { + sh_invalidnum (list->word->word); + return (EXECUTION_FAILURE); + } + else + secs = i; + } + else + secs = NOW; + + t = localtime (&secs); + + tbsize = strlen (format) * 4; + tbuf = 0; + + /* Now try to figure out how big the buffer should really be. strftime(3) + will return the number of bytes placed in the buffer unless it's greater + than MAXSIZE, in which case it returns 0. */ + for (n = 1; n < 4; n++) + { + tbuf = xrealloc (tbuf, tbsize * n); + tsize = strftime (tbuf, tbsize * n, format, t); + if (tsize) + break; + } + + printf ("%s\n", tbuf); + free (tbuf); + + 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. */ +char *strftime_doc[] = { + "Converts date and time format to a string and displays it on the", + "standard output. If the optional second argument is supplied, it", + "is used as the number of seconds since the epoch to use in the", + "conversion, otherwise the current time is used.", + (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 strftime_struct = { + "strftime", /* builtin name */ + strftime_builtin, /* function implementing the builtin */ + BUILTIN_ENABLED, /* initial flags for builtin */ + strftime_doc, /* array of long documentation strings. */ + "strftime format [seconds]", /* usage synopsis; becomes short_doc */ + 0 /* reserved for internal use */ +}; diff --git a/examples/misc/aliasconv.bash b/examples/misc/aliasconv.bash index 3fbe877..d3b5776 100755 --- a/examples/misc/aliasconv.bash +++ b/examples/misc/aliasconv.bash @@ -14,16 +14,16 @@ T=$'\t' cat << \EOF >/tmp/cb$$.1 mkalias () { - if [ "x$2" = "x" ]; then - echo alias ${1}="''" - elif echo "$2" | egrep -s '(\!|#)' >/dev/null 2>&1; then + case $2 in + '') echo alias ${1}="''" ;; + *[#\!]*) comm=$(echo $2 | sed 's/\!\*/"$\@"/g s/\!:\([1-9]\)/"$\1"/g s/#/\#/g') echo $1 \(\) "{" command "$comm" "; }" - else - echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':")\' - fi + ;; + *) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':")\' ;; + esac } EOF diff --git a/examples/misc/aliasconv.sh b/examples/misc/aliasconv.sh index 29e1ead..75db077 100755 --- a/examples/misc/aliasconv.sh +++ b/examples/misc/aliasconv.sh @@ -14,16 +14,16 @@ T=' ' cat << \EOF >/tmp/cb$$.1 mkalias () { - if [ "x$2" = "x" ]; then - echo alias ${1}="''" - elif echo "$2" | egrep -s '(\!|#)' >/dev/null 2>&1; then + case $2 in + '') echo alias ${1}="''" ;; + *[#\!]*) comm=`echo $2 | sed 's/\\!\*/"$\@"/g s/\\!:\([1-9]\)/"$\1"/g s/#/\#/g'` echo $1 \(\) "{" command "$comm" "; }" - else - echo alias ${1}=\'`echo "${2}" | sed "s:':'\\\\\\\\'':"`\' - fi + ;; + *) echo alias ${1}=\'`echo "${2}" | sed "s:':'\\\\\\\\'':"`\' ;; + esac } EOF diff --git a/examples/misc/cshtobash b/examples/misc/cshtobash index 9369622..8e2b05c 100755 --- a/examples/misc/cshtobash +++ b/examples/misc/cshtobash @@ -36,16 +36,16 @@ EOF cat << \EOF >/tmp/cb$$.1 mkalias () { - if [ -z "$2" ]; then - echo alias ${1}="''" - elif echo "$2" | egrep -s '(\!|#)' >/dev/null 2>&1; then + case $2 in + '') echo alias ${1}="''" ;; + *[#\!]*) comm=$(echo $2 | sed 's/\!\*/"$\@"/g s/\!:\([1-9]\)/"$\1"/g s/#/\#/g') echo $1 \(\) "{" command "$comm" "; }" - else - echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':")\' - fi + ;; + *) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':")\' ;; + esac } EOF diff --git a/examples/obashdb/README b/examples/obashdb/README index aa3aea7..3373f5f 100644 --- a/examples/obashdb/README +++ b/examples/obashdb/README @@ -4,5 +4,9 @@ and Associates (ISBN 1-56592-054-6). The original `kshdb' is available for anonymous FTP with the URL -ftp://ftp.uu.net/published/oreilly/nutshell/ksh/ksh.tar.Z +http://examples.oreilly.com/korn/ksh.tar.Z + +A revised edition is available at: + +http://examples.oreilly.com/korn2/korn2_examples.tar.gz diff --git a/examples/obashdb/bashdb.fns b/examples/obashdb/bashdb.fns index 79d9737..ac0612c 100644 --- a/examples/obashdb/bashdb.fns +++ b/examples/obashdb/bashdb.fns @@ -88,7 +88,7 @@ _at_linenumbp() { if [ -z "${_linebp}" ]; then return 1 fi - echo "${_curline}" | egrep "(${_linebp%\|})" >/dev/null 2>&1 + echo "${_curline}" | grep -E "(${_linebp%\|})" >/dev/null 2>&1 return $? } @@ -101,7 +101,7 @@ _at_stringbp() { return 1; fi l=${_lines[$_curline-$_firstline+1]} - echo "${l}" | egrep "*(${_stringbp%\|})*" >/dev/null 2>&1 + echo "${l}" | grep -E "\\*(${_stringbp%\|})\\*" >/dev/null 2>&1 return $? } diff --git a/examples/scripts.noah/number.bash b/examples/scripts.noah/number.bash index 23e58b4..37b62b6 100644 --- a/examples/scripts.noah/number.bash +++ b/examples/scripts.noah/number.bash @@ -108,7 +108,7 @@ function number () ;; 0 ) : ;; * ) - if test ".${val2}" != '.' -a ".${d1}" != '.0' ; then + if test ".${val2}" != '.' && test ".${d1}" != '.0' ; then val2="${val2}-" fi case "${d1}" in diff --git a/examples/scripts.noah/string.bash b/examples/scripts.noah/string.bash index 38c0af8..d80ebe8 100644 --- a/examples/scripts.noah/string.bash +++ b/examples/scripts.noah/string.bash @@ -95,11 +95,11 @@ function strcmp () ###;;;autoload function strncmp () { - if [ -z "${3}" -o "${3}" -le "0" ]; then + if [ -z "${3}" ] || [ "${3}" -le "0" ]; then return 0 fi - if [ ${3} -ge ${#1} -a ${3} -ge ${#2} ]; then + if [ ${3} -ge ${#1} ] && [ ${3} -ge ${#2} ]; then strcmp "$1" "$2" return $? else diff --git a/examples/scripts.v2/cdhist.bash b/examples/scripts.v2/cdhist.bash index 39bec88..df8aea7 100644 --- a/examples/scripts.v2/cdhist.bash +++ b/examples/scripts.v2/cdhist.bash @@ -39,7 +39,7 @@ cd() set -- $HOME fi - if [ "$CDHISTFILE" -a -r "$CDHISTFILE" ] # if directory history exists + if [ "$CDHISTFILE" ] && [ -r "$CDHISTFILE" ] # if directory history exists then typeset CDHIST i=-1 @@ -49,7 +49,7 @@ cd() done <$CDHISTFILE fi - if [ "${CDHIST[0]}" != "$PWD" -a "$PWD" != "" ] + if [ "${CDHIST[0]}" != "$PWD" ] && [ -n "$PWD" ] then _cdins # insert $PWD into cd history fi diff --git a/examples/scripts.v2/fman b/examples/scripts.v2/fman index c9cf301..1e94d21 100644 --- a/examples/scripts.v2/fman +++ b/examples/scripts.v2/fman @@ -56,13 +56,13 @@ FindSectionsInIndex () fi done [ -z "$indexes" ] && return - # Make egrep give filename + # Make grep give filename [ NIndex -lt 2 ] && indexes="$indexes /dev/null" # set positional parameters to # indexfile:searchname pagename section ... # e.g. # /usr/man/index:FP_OFF Routines DOS - set -- `egrep "^$page[ ]" $indexes` + set -- `grep "^$page[ ]" $indexes` while [ $# -gt 2 ]; do FileNames[i]=${1%%index*}cat$3/$2.$3 Sections[i]=$3 diff --git a/examples/scripts.v2/frcp b/examples/scripts.v2/frcp index 08028e1..572aa7b 100755 --- a/examples/scripts.v2/frcp +++ b/examples/scripts.v2/frcp @@ -110,7 +110,7 @@ function CopyFiles { */) ;; # don't add / if trailing / already present *) if [ $# -gt 2 ] || # if more than two args given, last must be a dir # If dest in on local machine, check whether it is a directory - [ $DestMach = $LocalMach -a -d $DestPath ] || + [ $DestMach = $LocalMach ] && [ -d "$DestPath" ] || # If dest ends with . or .., it is a directory lastisdot "$DestPath" then diff --git a/examples/scripts.v2/repeat b/examples/scripts.v2/repeat index 315d36e..b6fccac 100644 --- a/examples/scripts.v2/repeat +++ b/examples/scripts.v2/repeat @@ -103,7 +103,7 @@ esac shift -[ -z "$end" -o $count -le "$end" ] && increment=1 || increment=-1 +[ -z "$end" ] && [ $count -le "$end" ] && increment=1 || increment=-1 istrue $verbose && echo "start=$count end=$end" 1>&2 diff --git a/examples/scripts.v2/vtree b/examples/scripts.v2/vtree index 60583b0..7523cc8 100644 --- a/examples/scripts.v2/vtree +++ b/examples/scripts.v2/vtree @@ -38,7 +38,7 @@ for i in "$@"; do vars="$vars $i" ;; *) - if [ ! -x $i -o ! -d $i ]; then # arg must be a dir and executable + if [ ! -x $i ] || [ ! -d $i ]; then # arg must be a dir and executable echo "$i: directory not accessible." exit fi diff --git a/examples/scripts/bcsh.sh b/examples/scripts/bcsh.sh index 509fe88..b810cab 100755 --- a/examples/scripts/bcsh.sh +++ b/examples/scripts/bcsh.sh @@ -389,7 +389,7 @@ esac trap ':' 2 trap exit 3 -trap "tail -$savehist $histfile>/tmp/hist$$;uniq /tmp/hist$$ > $histfile;\ +trap "tail -n $savehist $histfile>/tmp/hist$$;uniq /tmp/hist$$ > $histfile;\ rm -f /tmp/*$$;exit 0" 15 getcmd=yes @@ -517,7 +517,7 @@ do esac cmd="${cmd};$line" - while test "$line" != "done" -a "$line" != "end" + while test "$line" != "done" && test "$line" != "end" do echo $n "$PS2$c" read line @@ -531,7 +531,7 @@ do echo "$cmd" > /tmp/bcsh$$ ;; if[\ \ ]*) - while test "$line" != "fi" -a "$line" != "endif" + while test "$line" != "fi" && test "$line" != "endif" do echo $n "$PS2$c" read line @@ -659,7 +659,7 @@ esac/ -[0-9]*) wanted="`expr \"$i\" : '-\([0-9][0-9]*\).*'`" rest="`expr \"$i\" : '-[0-9][0-9]*\(.*\)'`" - i="`tail -$wanted $histfile | sed -e "1q"`" + i="`tail -n $wanted $histfile | sed -e "1q"`" ;; esac ;; @@ -917,14 +917,14 @@ esac/ continue ;; exec[\ \ ]*) - tail -$savehist $histfile>/tmp/hist$$ + tail -n $savehist $histfile>/tmp/hist$$ uniq /tmp/hist$$ > $histfile rm -f /tmp/*$$ echo $cmd > /tmp/cmd$$ . /tmp/cmd$$ ;; login[\ \ ]*|newgrp[\ \ ]*) - tail -$savehist $histfile>/tmp/hist$$ + tail -n $savehist $histfile>/tmp/hist$$ uniq /tmp/hist$$ > $histfile rm -f /tmp/*$$ echo $cmd > /tmp/cmd$$ @@ -936,22 +936,22 @@ esac/ # sh $logoutfile $SHELL $logoutfile fi - tail -$savehist $histfile > /tmp/hist$$ + tail -n $savehist $histfile > /tmp/hist$$ uniq /tmp/hist$$ > $histfile rm -f /tmp/*$$ exit 0 ;; h|history) - grep -n . $histfile | tail -$history | sed -e 's@:@ @' | $PAGER + grep -n . $histfile | tail -n $history | sed -e 's@:@ @' | $PAGER continue ;; h[\ \ ]\|*|h[\ \ ]\>*|h\|*|h\>*) - cmd="`echo \"$cmd\" | sed -e \"s@h@grep -n . $histfile | tail -$history | sed -e 's@:@ @'@\"`" + cmd="`echo \"$cmd\" | sed -e \"s@h@grep -n . $histfile | tail -n $history | sed -e 's@:@ @'@\"`" getcmd=no continue ;; history[\ \ ]*\|*|history[\ \ ]*\>*) - cmd="`echo \"$cmd\" | sed -e \"s@history@grep -n . $histfile | tail -$history | sed -e 's@:@ @'@\"`" + cmd="`echo \"$cmd\" | sed -e \"s@history@grep -n . $histfile | tail -n $history | sed -e 's@:@ @'@\"`" getcmd=no continue ;; diff --git a/examples/scripts/fixfiles.bash b/examples/scripts/fixfiles.bash index 67311ee..15f3ba8 100644 --- a/examples/scripts/fixfiles.bash +++ b/examples/scripts/fixfiles.bash @@ -62,7 +62,7 @@ processdir() set +f for file in * ; do set -f - if [ "$file" != "." -a "$file" != ".." ] ; then + if [ "$file" != "." ] && [ "$file" != ".." ] ; then if [ -L "$file" ] ; then echo "skipping symlink" $file in `pwd` elif [ -d "$file" ] ; then diff --git a/examples/scripts/line-input.bash b/examples/scripts/line-input.bash index 02c2bc2..3f2efae 100644 --- a/examples/scripts/line-input.bash +++ b/examples/scripts/line-input.bash @@ -125,11 +125,11 @@ function getline unset linesave # forget temp var ;; ) - while [ "${line% }" != "$line" -a ${#line} != 0 ] ; do + while [ "${line% }" != "$line" ] && [ ${#line} != 0 ] ; do echo -n " " line="${line%?}" done - while [ "${line% }" = "$line" -a ${#line} != 0 ] ; do + while [ "${line% }" = "$line" ] && [ ${#line} != 0 ] ; do echo -n " " line="${line%?}" done @@ -151,7 +151,7 @@ function getline # If length is restricted, and the line is too # long, then beep... - if [ "$2" != 0 -a $(( ${#line} >= $2 )) = 1 ] ; then + if [ "$2" != 0 ] && [ $(( ${#line} >= $2 )) = 1 ] ; then echo -n else # Otherwise add line="$line$key" # the character. @@ -182,4 +182,3 @@ getline LINE 50 restore echo "<$LINE>" - |