├── .gitattributes ├── .gitignore ├── AUTHORS ├── CHANGES ├── CHANGES6 ├── DEDICATIONS ├── INSTALL ├── LICENSE ├── Makefile ├── Makefile.config ├── NOTES ├── PROJECT ├── README ├── defs.h ├── err.c ├── err.h ├── examples ├── FILEPREP ├── LICENSE ├── README ├── dot.osh.login ├── dot.osh.logout ├── dot.oshrc ├── etc.osh.login ├── etc.osh.logout └── etc.osh.oshrc ├── fd2.1 ├── fd2.c ├── glob6.1 ├── glob6.c ├── goto.1 ├── goto.c ├── if.1 ├── if.c ├── mkconfig ├── osh.1 ├── osh.c ├── pexec.c ├── pexec.h ├── sasignal.c ├── sasignal.h ├── sh.h ├── sh6.1 ├── sh6.c ├── strtoint.c ├── strtoint.h ├── tests ├── LICENSE ├── README ├── bin │ └── now ├── input ├── run.osh ├── syntax.list ├── syntax_error.in ├── test01 ├── test01_osh.log ├── test01_sh6.log ├── test02 ├── test02_osh.log ├── test02_sh6.log ├── test03 ├── test03_osh.log ├── test03_sh6.log ├── test04 ├── test04_osh.log ├── test04_sh6.log ├── test05 ├── test05_osh.log ├── test05_sh6.log ├── test06 ├── test06_osh.log ├── test07 ├── test07_osh.log ├── test08 ├── test08_osh.log └── test08_sh6.log ├── util.c └── v.c /.gitattributes: -------------------------------------------------------------------------------- 1 | [A-Z]* ident 2 | mkconfig ident 3 | *.[1ch] ident 4 | examples/*osh* -ident 5 | tests/[ist]* -ident 6 | tests/run* -ident 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.1.out 2 | *.o 3 | .release 4 | GIT.LOG 5 | config.h 6 | fd2 7 | glob6 8 | goto 9 | if 10 | osh 11 | sh6 12 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | The original Thompson shell was principally written by Ken Thompson 2 | of Bell Labs. However, it should be noted that other individuals 3 | at Bell Labs also had a role in its development: Dennis M. Ritchie, 4 | M. D. McIlroy, J. F. Ossanna, and quite likely others as well. 5 | 6 | Jeffrey Allen Neitzel is the principal developer and maintainer of 7 | the enhanced, backward-compatible port of the Sixth Edition (V6) 8 | UNIX Thompson shell (and all other software) released as part of 9 | the osh project. 10 | 11 | ============ 12 | Definitions: 13 | compatibility - backward compatibility 14 | 15 | osh - enhanced port of the Sixth Edition (V6) UNIX Thompson shell 16 | 17 | sh6 - port of the Sixth Edition (V6) UNIX Thompson shell 18 | (sh6 references implicitly include glob6) 19 | === 20 | 21 | Notice that I have released three different implementations of 22 | osh(1) since July 2003. The origin and primary objectives of 23 | each one are described below. 24 | 25 | ================================ 26 | [osh-030730 through osh-060124]: 27 | The first implementation was originally authored by Gunnar 28 | Ritter as osh-020214/osh.c and was then adopted by Jeffrey 29 | Allen Neitzel. 30 | 31 | Unfortunately, the design of Gunnar's implementation was 32 | incompatible with the Thompson shell in several respects. 33 | Thus, it required a lot of workarounds in order to fix the 34 | design incompatibilities. 35 | 36 | I modified Gunnar's design to separate command-line parsing 37 | and execution so that the shell could at least be compatible 38 | in the most basic sense. The only catch was that word 39 | splitting was still incompatible. Thus, this partial 40 | solution was always destined for eventual replacement. 41 | 42 | Primary objective was compatibility. 43 | === 44 | 45 | ==================================== 46 | [osh-20061230 through osh-20100228]: 47 | The second implementation was originally authored by Ken 48 | Thompson as Sixth Edition UNIX /usr/source/s2/sh.c and was 49 | then ported by Jeffrey Allen Neitzel for personal use in 50 | January 2004. 51 | 52 | I eventually released it as sh6(1) in osh-060124. Then, 53 | after its release, I realized that the design of the original 54 | shell (see: osh-060124/*6.c) offered a far better starting 55 | point for making osh(1) truly backward-compatible with the 56 | Thompson shell. 57 | 58 | Bothered by the fact that osh(1) still had incompatible 59 | word-splitting behavior, I abandoned the design used in the 60 | first implementation, adapted sh6.c and glob6.c, copied 61 | them to osh.c, and began working on it during my free time 62 | in 2006. Finally, I released the new implementation of 63 | osh(1) in osh-20061230. 64 | 65 | Primary objective was compatibility. 66 | === 67 | 68 | =================================== 69 | [osh-20100430 through osh-current]: 70 | The third implementation continues with primary objectives 71 | of compatibility and long-term stability. Consequently, 72 | all new features (if/when added) must work in concert 73 | with primary objectives. Otherwise, they will not 74 | be added. 75 | === 76 | 77 | I wish to thank the original authors very much for their efforts. 78 | Without their previous work, none of this software or documentation 79 | would exist today. 80 | 81 | See the DEDICATIONS file for further info. 82 | 83 | Jeffrey Allen Neitzel 2012/06/02 84 | 85 | @(#)$Id: bcb06f71559f3f534cb7958cc75d4d9decbe94ce $ 86 | -------------------------------------------------------------------------------- /DEDICATIONS: -------------------------------------------------------------------------------- 1 | From the outset, I have dedicated all releases of the osh project 2 | to the individuals at Bell Labs who started the UNIX ball rolling 3 | in 1969. 4 | 5 | Due to the untimely passing of Dennis M. Ritchie (dmr), I hereby 6 | dedicate osh-20111027 (and all future osh releases) in his memory. 7 | 8 | * Dennis Ritchie Home Page - http://cm.bell-labs.com/who/dmr/ 9 | 10 | * Rob Pike's Google+ post sharing news of dmr's passing - 11 | https://plus.google.com/u/0/101960720994009339267/posts/ENuEDDYfvKP 12 | 13 | See the AUTHORS file for further info about origins of this software. 14 | 15 | Jeffrey Allen Neitzel 2012/06/02 16 | 17 | @(#)$Id: 4586b8a609cdcc5f79f38f02cd62471720ebf6cc $ 18 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Build and install instructions for osh! 2 | 3 | -------- 4 | SYNOPSIS 5 | env [variable=value ...] make [target ...] 6 | make [variable=value ...] [target ...] 7 | 8 | If the defaults described below match your desires and/or the 9 | requirements of your system, you can build and install the entire 10 | osh package by doing the following. 11 | 12 | % make 13 | # make install 14 | 15 | ... 16 | Otherwise, continue reading for full build and install details. 17 | See the EXAMPLES section at the end of this file for additional 18 | help if needed. 19 | 20 | --------- 21 | VARIABLES 22 | The Makefile defines the following configuration variables (default 23 | value listed). The user can modify the default configuration by 24 | passing the desired variable=value pair(s) on the command line. 25 | 26 | DESTDIR Unset by default. This may be used as a 27 | target directory for building/packaging 28 | binary packages if needed. 29 | 30 | PREFIX Defaults to /usr/local. This is the target 31 | directory where BINDIR, DOCDIR, MANDIR, and 32 | SYSCONFDIR are located by default. 33 | 34 | BINDIR Defaults to $(PREFIX)/bin. This is the target 35 | directory where the binaries are installed. 36 | 37 | DOCDIR Defaults to $(PREFIX)/share/doc/$(OSH_VERSION). 38 | This is the target directory for the [ACDILNPR]* 39 | package documentation files. 40 | 41 | EXPDIR Defaults to $(DOCDIR)/examples. This is the 42 | target directory for the examples/* files. 43 | 44 | MANDIR Defaults to $(PREFIX)/share/man/man1. This is 45 | the target directory where the manual pages are 46 | installed. 47 | 48 | SYSCONFDIR Defaults to $(PREFIX)/etc. This is the target 49 | directory where the shell shall search for its 50 | system-wide rc (init and logout) files if such 51 | files are available on the system. See also: 52 | 53 | http://v6shell.org/rc_files 54 | 55 | ... 56 | for example rc files. 57 | 58 | INSTALL Defaults to /usr/bin/install. The install(1) 59 | utility is used to copy the resulting binaries, 60 | manual pages, and other files to final targets. 61 | 62 | Mac OS X only: 63 | The following configuration variable specifies the desired target 64 | architecture(s) for compiling universal binaries and/or 64-bit 65 | binaries and/or 32-bit binaries for Mac OS X running on Intel 66 | and PowerPC Macs. 67 | 68 | MOXARCH Unset by default. Possible value(s) may include 69 | one or more of the following on supported systems: 70 | -arch x86_64, -arch ppc64, -arch i386, -arch ppc. 71 | See also EXAMPLES. 72 | 73 | ------- 74 | TARGETS 75 | The following targets are available. 76 | 77 | all Default target is the same as typing `make'. 78 | Compiles everything and generates manual pages. 79 | 80 | oshall Compiles osh and generates manual pages. 81 | 82 | sh6all Compiles sh6, glob6, if, goto, fd2 and 83 | generates manual pages. 84 | 85 | check Runs the regression test suite with osh and sh6. 86 | 87 | check-newlog Generates new test logs for the osh and sh6 88 | regression test suite. 89 | 90 | install Installs all binaries and manual pages. 91 | 92 | install-oshall Installs osh binary and manual pages. 93 | 94 | install-sh6all Installs sh6all binaries and manual pages. 95 | 96 | install-doc Installs package documentation. 97 | 98 | install-exp Installs examples. 99 | 100 | clean-obj Removes all object files. 101 | 102 | clean Removes all binaries, object files, and other 103 | files generated during the build. 104 | 105 | -------- 106 | EXAMPLES 107 | The following compiles osh for /opt/local. 108 | Then, it installs the osh binary into /opt/local/bin, manual pages 109 | into /opt/local/share/man/man1, package documentation and examples 110 | into /opt/local/share/doc/$(OSH_VERSION), and also sets SYSCONFDIR 111 | to /opt/local/etc. 112 | 113 | % make PREFIX=/opt/local oshall 114 | # make PREFIX=/opt/local install-oshall install-doc install-exp 115 | 116 | The following compiles sh6, glob6, if, goto, and fd2 for /usr/pkg. 117 | Then, it installs these binaries into /usr/pkg/bin, manual pages 118 | into /usr/pkg/share/man/man1, and package documentation into 119 | /usr/pkg/share/doc/$(OSH_VERSION). 120 | 121 | % make PREFIX=/usr/pkg sh6all 122 | # make PREFIX=/usr/pkg install-sh6all install-doc 123 | 124 | The following compiles everything, configuring the shell to search 125 | for its system-wide rc files in /etc instead of /usr/local/etc by 126 | default. Then, it installs the entire osh package, including package 127 | documentation and examples, into the default location. 128 | 129 | % make SYSCONFDIR=/etc 130 | # make install install-doc install-exp 131 | 132 | The following compiles each program as a 2-way 64/32-bit universal 133 | binary for Mac OS X running on Intel Macs. Then, it installs the 134 | entire osh package, including package documentation and examples, 135 | into the default location. 136 | 137 | % make MOXARCH='-arch x86_64 -arch i386' 138 | # make install install-doc install-exp 139 | 140 | The following compiles and installs the entire osh package, including 141 | package documentation and examples, into the default location on 142 | OpenSolaris. 143 | 144 | % uname -srvm 145 | SunOS 5.11 snv_111b i86pc 146 | % which cc gmake ginstall 147 | /usr/gnu/bin/cc 148 | /usr/bin/gmake 149 | /usr/bin/ginstall 150 | % gmake 151 | # gmake INSTALL=/usr/bin/ginstall install install-doc install-exp 152 | 153 | Jeffrey Allen Neitzel 2012/07/01 154 | 155 | @(#)$Id: 7c431f66793bd480d0ab49d032fc0df085b056a4 $ 156 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for osh 2 | # 3 | # @(#)$Id: e0b59582a9dc45a4f45bba8da19cc76022eae2cf $ 4 | # 5 | # Begin CONFIGURATION 6 | # 7 | # See the INSTALL file for build and install instructions. 8 | # 9 | 10 | # 11 | # Choose where and how to install the binaries and manual pages. 12 | # 13 | DESTDIR?= 14 | PREFIX?= /usr/local 15 | BINDIR?= $(PREFIX)/bin 16 | DOCDIR?= $(PREFIX)/share/doc/$(OSH_VERSION) 17 | EXPDIR?= $(DOCDIR)/examples 18 | MANDIR?= $(PREFIX)/share/man/man1 19 | SYSCONFDIR?= $(PREFIX)/etc 20 | #BINGRP= -g bin 21 | BINMODE= -m 0555 22 | #MANGRP= -g bin 23 | MANMODE= -m 0444 24 | 25 | # 26 | # Build utilities (SHELL must be POSIX-compliant) 27 | # 28 | INSTALL?= /usr/bin/install 29 | SHELL= /bin/sh 30 | 31 | # 32 | # Preprocessor, compiler, and linker flags 33 | # 34 | # If the compiler gives errors about any of flags specified 35 | # by `OPTIONS' or `WARNINGS' below, comment the appropriate 36 | # line(s) with a `#' character to fix the compiler errors. 37 | # Then, try to build again by doing a `make clean ; make'. 38 | # 39 | #CPPFLAGS= 40 | OPTIONS= -std=c99 -pedantic 41 | #OPTIONS+= -fstack-protector 42 | WARNINGS= -Wall -W 43 | # NOTE: It seems that -Wno-unused-result first appeared in gcc-4.4.0 . 44 | #WARNINGS= -Wno-unused-result 45 | #WARNINGS+= -Wstack-protector 46 | #WARNINGS+= -Wshorten-64-to-32 47 | #CFLAGS+= -g 48 | CFLAGS+= -Os $(OPTIONS) $(WARNINGS) 49 | #LDFLAGS+= -static 50 | 51 | # 52 | # End CONFIGURATION 53 | # 54 | # !!! ================= Developer stuff below... ================= !!! 55 | 56 | # 57 | # Adjust CFLAGS and LDFLAGS for MOXARCH if needed. 58 | # 59 | MOXARCH?= 60 | CFLAGS+= $(MOXARCH) 61 | LDFLAGS+= $(MOXARCH) 62 | 63 | # 64 | # Include osh date and version from Makefile.config . 65 | # 66 | include ./Makefile.config 67 | 68 | OSH= osh 69 | SH6= sh6 glob6 70 | UBIN= fd2 goto if 71 | GHEAD= config.h defs.h 72 | ERRSRC= err.h err.c 73 | PEXSRC= pexec.h pexec.c 74 | SIGSRC= sasignal.h sasignal.c 75 | INTSRC= strtoint.h strtoint.c 76 | OBJ= err.o fd2.o glob6.o goto.o if.o osh.o pexec.o sasignal.o sh6.o strtoint.o util.o v.o 77 | OSHMAN= osh.1.out 78 | SH6MAN= sh6.1.out glob6.1.out 79 | UMAN= fd2.1.out goto.1.out if.1.out 80 | MANALL= $(OSHMAN) $(SH6MAN) $(UMAN) 81 | SEDSUB= -e 's|@OSH_DATE@|$(OSH_DATE)|' \ 82 | -e 's|@OSH_VERSION@|$(OSH_VERSION)|' \ 83 | -e 's|@SYSCONFDIR@|$(SYSCONFDIR)|' 84 | 85 | DEFS= -DOSH_VERSION='"$(OSH_VERSION)"' -DSYSCONFDIR='"$(SYSCONFDIR)"' 86 | 87 | .SUFFIXES: .1 .1.out .c .o 88 | 89 | .1.1.out: 90 | sed $(SEDSUB) <$< >$@ 91 | 92 | .c.o: 93 | $(CC) -c $(CFLAGS) $(CPPFLAGS) $(DEFS) $< 94 | 95 | # 96 | # Build targets 97 | # 98 | all: oshall sh6all 99 | 100 | oshall: $(OSH) $(OSHMAN) $(UMAN) 101 | 102 | sh6all: $(SH6) $(SH6MAN) utils 103 | 104 | utils: $(UBIN) $(UMAN) 105 | 106 | man: $(MANALL) 107 | 108 | osh: sh.h v.c osh.c util.c $(GHEAD) $(ERRSRC) $(PEXSRC) $(SIGSRC) $(INTSRC) 109 | @$(MAKE) $@bin 110 | 111 | sh6: sh.h v.c sh6.c $(GHEAD) $(ERRSRC) $(PEXSRC) $(SIGSRC) 112 | @$(MAKE) $@bin 113 | 114 | glob6: v.c glob6.c $(GHEAD) $(ERRSRC) $(PEXSRC) 115 | @$(MAKE) $@bin 116 | 117 | if: v.c if.c $(GHEAD) $(ERRSRC) $(PEXSRC) $(SIGSRC) $(INTSRC) 118 | @$(MAKE) $@bin 119 | 120 | goto: v.c goto.c $(GHEAD) $(ERRSRC) 121 | @$(MAKE) $@bin 122 | 123 | fd2: v.c fd2.c $(GHEAD) $(ERRSRC) $(PEXSRC) 124 | @$(MAKE) $@bin 125 | 126 | $(OBJ) : $(GHEAD) 127 | fd2.o glob6.o goto.o if.o osh.o pexec.o sh6.o util.o strtoint.o: err.h 128 | fd2.o glob6.o if.o osh.o sh6.o util.o : pexec.h 129 | if.o osh.o sh6.o : sasignal.h 130 | if.o osh.o util.o : strtoint.h 131 | osh.o sh6.o util.o : sh.h 132 | err.o : $(ERRSRC) 133 | pexec.o : $(PEXSRC) 134 | sasignal.o : $(SIGSRC) 135 | strtoint.o : $(INTSRC) 136 | 137 | config.h: Makefile Makefile.config mkconfig 138 | $(SHELL) ./mkconfig 139 | 140 | oshbin: v.o osh.o err.o util.o pexec.o sasignal.o strtoint.o 141 | $(CC) $(LDFLAGS) -o osh v.o osh.o err.o util.o pexec.o sasignal.o strtoint.o $(LIBS) 142 | 143 | sh6bin: v.o sh6.o err.o pexec.o sasignal.o 144 | $(CC) $(LDFLAGS) -o sh6 v.o sh6.o err.o pexec.o sasignal.o $(LIBS) 145 | 146 | glob6bin: v.o glob6.o err.o pexec.o 147 | $(CC) $(LDFLAGS) -o glob6 v.o glob6.o err.o pexec.o $(LIBS) 148 | 149 | ifbin: v.o if.o err.o pexec.o sasignal.o strtoint.o 150 | $(CC) $(LDFLAGS) -o if v.o if.o err.o pexec.o sasignal.o strtoint.o $(LIBS) 151 | 152 | gotobin: v.o goto.o err.o 153 | $(CC) $(LDFLAGS) -o goto v.o goto.o err.o $(LIBS) 154 | 155 | fd2bin: v.o fd2.o err.o pexec.o 156 | $(CC) $(LDFLAGS) -o fd2 v.o fd2.o err.o pexec.o $(LIBS) 157 | 158 | # 159 | # Test targets 160 | # 161 | check: all 162 | @( trap '' INT QUIT && cd tests && ../osh run.osh osh sh6 ) 163 | check-newlog: all 164 | @( trap '' INT QUIT && cd tests && ../osh run.osh -newlog osh sh6 ) 165 | 166 | # 167 | # Install targets 168 | # 169 | DESTBINDIR= $(DESTDIR)$(BINDIR) 170 | DESTDOCDIR= $(DESTDIR)$(DOCDIR) 171 | DESTEXPDIR= $(DESTDIR)$(EXPDIR) 172 | DESTMANDIR= $(DESTDIR)$(MANDIR) 173 | install: install-oshall install-sh6all 174 | 175 | install-oshall: oshall install-osh install-uman 176 | 177 | install-sh6all: sh6all install-sh6 install-utils 178 | 179 | install-utils: install-ubin install-uman 180 | 181 | install-osh: $(OSH) $(OSHMAN) install-dest 182 | $(INSTALL) -c -s $(BINGRP) $(BINMODE) osh $(DESTBINDIR) 183 | $(INSTALL) -c $(MANGRP) $(MANMODE) osh.1.out $(DESTMANDIR)/osh.1 184 | 185 | install-sh6: $(SH6) $(SH6MAN) install-dest 186 | $(INSTALL) -c -s $(BINGRP) $(BINMODE) sh6 $(DESTBINDIR) 187 | $(INSTALL) -c $(MANGRP) $(MANMODE) sh6.1.out $(DESTMANDIR)/sh6.1 188 | $(INSTALL) -c -s $(BINGRP) $(BINMODE) glob6 $(DESTBINDIR) 189 | $(INSTALL) -c $(MANGRP) $(MANMODE) glob6.1.out $(DESTMANDIR)/glob6.1 190 | 191 | install-ubin: $(UBIN) install-dest 192 | $(INSTALL) -c -s $(BINGRP) $(BINMODE) fd2 $(DESTBINDIR) 193 | $(INSTALL) -c -s $(BINGRP) $(BINMODE) goto $(DESTBINDIR) 194 | $(INSTALL) -c -s $(BINGRP) $(BINMODE) if $(DESTBINDIR) 195 | 196 | install-uman: $(UMAN) install-dest 197 | $(INSTALL) -c $(MANGRP) $(MANMODE) fd2.1.out $(DESTMANDIR)/fd2.1 198 | $(INSTALL) -c $(MANGRP) $(MANMODE) goto.1.out $(DESTMANDIR)/goto.1 199 | $(INSTALL) -c $(MANGRP) $(MANMODE) if.1.out $(DESTMANDIR)/if.1 200 | 201 | install-dest: 202 | test -d $(DESTBINDIR) || { umask 0022 && mkdir -p $(DESTBINDIR) ; } 203 | test -d $(DESTMANDIR) || { umask 0022 && mkdir -p $(DESTMANDIR) ; } 204 | 205 | install-doc: 206 | test -d $(DESTDOCDIR) || { umask 0022 && mkdir -p $(DESTDOCDIR) ; } 207 | $(INSTALL) -c $(MANGRP) $(MANMODE) [ACDILNPR]* $(DESTDOCDIR) 208 | 209 | install-exp: 210 | test -d $(DESTEXPDIR) || { umask 0022 && mkdir -p $(DESTEXPDIR) ; } 211 | $(INSTALL) -c $(MANGRP) $(MANMODE) examples/* $(DESTEXPDIR) 212 | 213 | # 214 | # Cleanup targets 215 | # 216 | clean-man: 217 | rm -f $(MANALL) 218 | clean-obj: 219 | rm -f $(OBJ) 220 | clean: clean-man clean-obj 221 | rm -f $(OSH) $(SH6) $(UBIN) config.h 222 | 223 | # 224 | # Release target 225 | # 226 | release: clean 227 | rm -rf .release 228 | oshrelease .release $(OSH_VERSION) 229 | -------------------------------------------------------------------------------- /Makefile.config: -------------------------------------------------------------------------------- 1 | # Makefile.config for osh 2 | # 3 | # @(#)$Id: 74db8d6578f1d440d80e00d9bc5e0148fce1bf78 $ 4 | # 5 | # See INSTALL and Makefile for full details. 6 | # 7 | 8 | # 9 | # The following specifies the osh date and version: 10 | # 11 | # osh-current == current master branch development 12 | # osh-YYYYMMDD-current == current development snapshot 13 | # osh-YYYYMMDD-beta[1-9] == beta release 14 | # osh-YYYYMMDD == official release 15 | # osh-YYYYMMDD-p[1-9] == patched release 16 | # 17 | OSH_DATE= January 1, 2014 18 | OSH_VERSION= osh-current 19 | -------------------------------------------------------------------------------- /NOTES: -------------------------------------------------------------------------------- 1 | This file provides an implementation overview of the software 2 | released as part of the osh project, focusing on history and 3 | compatibility since these are the primary project objectives. 4 | 5 | --------------------------------------- 6 | Historical notes for osh(1) and sh6(1): 7 | 8 | The Thompson shell, by Ken Thompson of Bell Labs, was distributed 9 | as the standard command interpreter through Sixth Edition UNIX. 10 | Then, in the Seventh Edition, it was replaced by the Bourne shell. 11 | However, the Thompson shell was still distributed with the system 12 | as osh because of known portability problems with the Bourne shell's 13 | memory management in Seventh Edition UNIX. 14 | 15 | The name of the Thompson shell's binary executable was `sh'. 16 | It was installed as `/bin/sh' through Sixth Edition UNIX and 17 | made use of the following external utilities: 18 | 19 | 1) /bin/exit was used to terminate command files. 20 | 21 | 2) /bin/goto was used to transfer the shell's control 22 | from one point to another within a command file. 23 | 24 | 3) /bin/if was used to evaluate conditional expressions. 25 | This is the predecessor of test(1), which was first 26 | released in Seventh Edition UNIX. 27 | 28 | 4) /etc/glob was used to expand `*', `?', and `[...]' 29 | in command arguments. 30 | 31 | The functionality of each of the above-mentioned utilities is 32 | provided here. However, the `exit' utility is implemented as a 33 | special built-in command for both osh(1) and sh6(1). 34 | 35 | For osh(1), ports of `glob', `goto', and `if' are built into the 36 | shell. For sh6(1), however, each of these utilities remains as an 37 | external utility. 38 | 39 | For sh6(1), the Thompson-shell port's binary executable has been 40 | renamed from `sh' to `sh6' to avoid name conflict and confusion 41 | with the system shell, sh(1), on modern UNIX systems. Similarly, 42 | the `glob' utility has been renamed to `glob6' and is installed 43 | into the same directory as the shell, /usr/local/bin by default, 44 | rather than being installed into the /etc directory. 45 | 46 | Additionally, see the glob6(1), goto(1), and if(1) manual pages for 47 | full details regarding the ports of the above-mentioned utilities. 48 | 49 | ------------------------------- 50 | Compatibility notes for osh(1): 51 | 52 | This is an enhanced, backward-compatible port of the Thompson shell 53 | from Sixth Edition UNIX. However, when it is known to differ in 54 | some way from the original, this fact is indicated with a `(+)' in 55 | the osh(1) manual page. 56 | 57 | Unlike the original, this port of the shell can handle 8-bit character 58 | sets, as well as the UTF-8 encoding. The original, on the other 59 | hand, can only handle 7-bit ASCII. 60 | 61 | Further details regarding some of the known differences: 62 | 63 | 1) This port of the shell uses PATH to search for external commands, 64 | but the original always uses the equivalent of `.:/bin:/usr/bin'. 65 | The sh(1) manual page from Sixth Edition UNIX reads as follows: 66 | 67 | If the first argument is the name of an executable file, 68 | it is invoked; otherwise the string `/bin/' is prepended 69 | to the argument. (In this way most standard commands, 70 | which reside in `/bin', are found.) If no such command is 71 | found, the string `/usr' is further prepended (to give 72 | `/usr/bin/command') and another attempt is made to execute 73 | the resulting file. (Certain lesser-used commands live in 74 | `/usr/bin'.) 75 | 76 | ... 77 | The primary reason this port of the shell uses PATH instead of a 78 | procedure like that described above is for both user convenience 79 | and security. The behavior described above can conceivably be 80 | quite dangerous as an unchangeable default. 81 | 82 | Using PATH allows the user to choose the search behavior. 83 | If search behavior like that of the original is desired, the 84 | user can set PATH to a value of `.:/bin:/usr/bin' in order to 85 | accomplish this. 86 | 87 | 2) This port of the shell integrates the previously external `echo', 88 | `fd2', `glob', `goto', and `if' shell utilities as special built-in 89 | commands in order to improve shell performance and reliability. 90 | This does not change the user-visible behavior of the shell or 91 | utilities. 92 | 93 | 3) This port of the shell prints a progname prefix (e.g., `osh: ') 94 | for all diagnostics. This results in `osh: file: cannot open' 95 | instead of `file: cannot open', `osh: syntax error' instead of 96 | `syntax error', and so forth. 97 | 98 | 4) This port of the shell ignores the first line of a command file 99 | if it begins with `#!' in order to play nicely with kernels which 100 | support the `#!' mechanism. For example, the first line might be 101 | `#!/usr/local/bin/osh' or `#!/usr/bin/env osh'. This is just for 102 | user convenience in the face of conflicting shell languages. 103 | 104 | 5) The original implementation of the shell does shell accounting 105 | in order to record command execution data; this port does not. 106 | 107 | ------------------------------- 108 | Compatibility notes for sh6(1): 109 | 110 | This is a port of the Thompson shell from Sixth Edition UNIX. 111 | However, when it is known to differ in some way from the original, 112 | this fact is indicated with a `(+)' in the sh6(1) manual page. 113 | 114 | Like the original, this port of the shell is not 8-bit clean as it 115 | uses the high-order bit of characters for quoting. Thus, the only 116 | complete character set it can handle is 7-bit ASCII. 117 | 118 | Aside from those differences which are detailed either here or in 119 | the manual page, the CHANGES6 file contains further information 120 | regarding how this port differs from the original. 121 | 122 | Further details regarding the substantial differences: 123 | 124 | 1) This port of the shell uses PATH to search for external commands, 125 | but the original always uses the equivalent of `.:/bin:/usr/bin'. 126 | The sh(1) manual page from Sixth Edition UNIX reads as follows: 127 | 128 | If the first argument is the name of an executable file, 129 | it is invoked; otherwise the string `/bin/' is prepended 130 | to the argument. (In this way most standard commands, 131 | which reside in `/bin', are found.) If no such command is 132 | found, the string `/usr' is further prepended (to give 133 | `/usr/bin/command') and another attempt is made to execute 134 | the resulting file. (Certain lesser-used commands live in 135 | `/usr/bin'.) 136 | 137 | ... 138 | The primary reason this port of the shell uses PATH instead of a 139 | procedure like that described above is for both user convenience 140 | and security. The behavior described above can conceivably be 141 | quite dangerous as an unchangeable default. 142 | 143 | Using PATH allows the user to choose the search behavior. 144 | If search behavior like that of the original is desired, the 145 | user can set PATH to a value of `.:/bin:/usr/bin' in order to 146 | accomplish this. 147 | 148 | 2) This port of the shell ignores the first line of a command file 149 | if it begins with `#!' in order to play nicely with kernels which 150 | support the `#!' mechanism. For example, the first line might be 151 | `#!/usr/local/bin/sh6' or `#!/usr/bin/env sh6'. This is just for 152 | user convenience in the face of conflicting shell languages. 153 | 154 | 3) The original implementation of the shell does shell accounting 155 | in order to record command execution data; this port does not. 156 | 157 | Jeffrey Allen Neitzel 2012/06/02 158 | 159 | @(#)$Id: 6689ef8096bd066b6ad90e04239ae493ddb6f503 $ 160 | -------------------------------------------------------------------------------- /PROJECT: -------------------------------------------------------------------------------- 1 | % cat < $h/.project 2 | 3 | Osh Project (V6Shell) 4 | 5 | __ ____ ____ _ _ _ 6 | \ \ / / /_/ ___|| |__ ___| | | 7 | \ \ / / '_ \___ \| '_ \ / _ \ | | 8 | \ V /| (_) |__) | | | | __/ | | 9 | \_/ \___/____/|_| |_|\___|_|_| 10 | 11 | http://v6shell.org/ - Home Page 12 | http://v6shell.org/git - GitHub Repo 13 | http://v6shell.org/wiki - GitHub Wiki 14 | http://v6shell.org/blog - V6Shell Blog 15 | http://v6shell.org/twitter - V6Shell Twitter 16 | 17 | Osh is an enhanced, backward-compatible port of the 18 | Sixth Edition (V6) UNIX Thompson shell (circa 1975). 19 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Welcome to Osh (V6Shell) - osh-current ! 2 | 3 | The osh package provides two ports of the original /bin/sh from 4 | Sixth Edition (V6) UNIX (circa 1975). 5 | 6 | Osh(1) is an enhanced, backward-compatible port of the Sixth Edition 7 | Thompson shell. Sh6(1) is an unenhanced port of the shell, and 8 | glob6(1) is a port of its global command. Together, sh6 and glob6 9 | provide a user interface which is backward compatible with that 10 | provided by the Sixth Edition Thompson shell and global command, 11 | but without the obvious enhancements found in osh. 12 | 13 | The original Thompson shell was principally written by Ken Thompson 14 | of Bell Labs. 15 | 16 | Notice that this package also includes the following shell utilities: 17 | 18 | if(1) - conditional command (ported from Sixth Edition UNIX) 19 | 20 | goto(1) - transfer command (ported from Sixth Edition UNIX) 21 | 22 | fd2(1) - redirect from/to file descriptor 2 23 | 24 | ------- 25 | See the INSTALL file for build and install instructions. 26 | 27 | ------- 28 | The osh package should build successfully on any POSIX-compliant 29 | UNIX system. It has been reported to build successfully on the 30 | following systems: 31 | 32 | System Releases / Distributions / Additional Info 33 | ---------------------------------------------------------- 34 | DragonFly BSD 2.0.1 35 | FreeBSD 6.1, 7.0, 8.2 36 | Mac OS X 10.4, 10.5, 10.6, 10.7, 10.8, 10.9 37 | NetBSD 2.1, 3.1.1, 4.0, 4.0.1, 5.0, 5.1, 6.1 38 | OpenBSD 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 5.0 39 | OpenSolaris 2008.05, 2008.11, 2009.06 (See last example 40 | in EXAMPLES section of INSTALL file.) 41 | GNU/Linux CentOS 6.2, Debian 6.0.8 (squeeze), Linpus, 42 | Slackware 13.0, Ubuntu 10.04.[34] LTS 43 | 44 | If your system is not reported above, simply try to build the osh 45 | package to see if it works or not. In either case, please report 46 | the results to the developer if possible. The resulting "config.h" 47 | file and the compiler name/version is most helpful. 48 | 49 | Please send osh bug reports to . Before 50 | reporting a bug, please try to reproduce it with the latest version 51 | of the code. With bug reports, please try to ensure that enough 52 | information to reproduce the problem is enclosed. Also, if a known 53 | fix for it exists, then please include that as well. 54 | 55 | If you have any comments or questions about this software, I encourage 56 | you to contact me via email. Thanks & Enjoy! 57 | 58 | Jeffrey Allen Neitzel 59 | 60 | http://v6shell.org/ 2013/11/10 61 | 62 | @(#)$Id: 583b7e10c151fbbfa8f791a76b87cb842f854cdf $ 63 | -------------------------------------------------------------------------------- /defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * osh - an enhanced port of the Sixth Edition (V6) UNIX Thompson shell 3 | */ 4 | /*- 5 | * Copyright (c) 2004-2014 6 | * Jeffrey Allen Neitzel . 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | * @(#)$Id: 7f8c8ed98075bd83addd78eba490716674a5b171 $ 30 | */ 31 | 32 | #ifndef DEFS_H 33 | #define DEFS_H 34 | 35 | /* 36 | * required header files 37 | */ 38 | #include "config.h" 39 | 40 | #ifndef S_SPLINT_S 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #endif 58 | 59 | #ifdef PATH_MAX 60 | #if PATH_MAX > 1024 61 | #define PATHMAX 1024 62 | #else 63 | #define PATHMAX PATH_MAX 64 | #endif 65 | #else 66 | #define PATHMAX 1024 67 | #endif 68 | 69 | #ifdef ARG_MAX 70 | #define GAVMAX ARG_MAX 71 | #else 72 | #define GAVMAX 1048576 73 | #endif 74 | #define GAVMULT 2U /* base GAVNEW reallocation multiplier */ 75 | #define GAVNEW 128U /* base # of new arguments per gav allocation */ 76 | 77 | #ifdef _POSIX_OPEN_MAX 78 | #define FDFREEMIN _POSIX_OPEN_MAX 79 | #else 80 | #define FDFREEMIN 20 /* Value is the same as _POSIX_OPEN_MAX. */ 81 | #endif 82 | #define FDFREEMAX 4096 /* Arbitrary maximum value for fd_free(). */ 83 | 84 | #define SOURCEMAX 64 /* Maximum # of nested source invocations */ 85 | 86 | #define LINEMAX 2048 /* 1000 in the original Sixth Edition shell */ 87 | #define TREEMAX 512 /* 100 ... */ 88 | #define WORDMAX 1024 /* 50 ... */ 89 | 90 | #define ASCII 0177 91 | #define QUOTE 0200 92 | 93 | #define SBUFMM(m) ((32 * (m)) + 1)/* small buffer max multiplier */ 94 | #define DOLMAX SBUFMM(1) /* used by osh(1) and sh6(1) shells */ 95 | #define LABELMAX SBUFMM(2) /* used by goto(1) utility */ 96 | 97 | /* 98 | * Following standard conventions, file descriptors 0, 1, and 2 are used 99 | * for standard input, standard output, and standard error respectively. 100 | */ 101 | #define FD0 STDIN_FILENO 102 | #define FD1 STDOUT_FILENO 103 | #define FD2 STDERR_FILENO 104 | 105 | #define F_GZ 1 /* `-s' primary for if(1) utility */ 106 | #define F_OT 2 /* `-ot' ... */ 107 | #define F_NT 3 /* `-nt' ... */ 108 | #define F_EF 4 /* `-ef' ... */ 109 | 110 | #define DOLSUB true 111 | #define FORKED true 112 | #define RETERR true 113 | 114 | #define EQUAL(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) 115 | #define IS_DIGIT(d, c) ((d) >= 0 && (d) <= 9 && "0123456789"[(d) % 10] == (c)) 116 | 117 | /* 118 | * special character literals 119 | */ 120 | #define BANG '!' 121 | #define COLON ':' 122 | #define DOLLAR '$' 123 | #define DOT '.' 124 | #define EOL '\n' 125 | #define EOS '\0' 126 | #define HASH '#' 127 | #define SLASH '/' 128 | #define SPACE ' ' 129 | #define TAB '\t' 130 | #define BQUOT '\\' 131 | #define DQUOT '"' 132 | #define SQUOT '\'' 133 | 134 | #define LPARENTHESIS '(' 135 | #define RPARENTHESIS ')' 136 | #define SEMICOLON ';' 137 | #define AMPERSAND '&' 138 | #define VERTICALBAR '|' 139 | #define CARET '^' 140 | #define LESSTHAN '<' 141 | #define GREATERTHAN '>' 142 | 143 | #define ASTERISK '*' 144 | #define QUESTION '?' 145 | #define LBRACKET '[' 146 | #define RBRACKET ']' 147 | #define HYPHEN '-' 148 | 149 | /* 150 | * special string literals 151 | */ 152 | #define BANCHARS " \t$\"'\\();&|^<>*?[\n" 153 | #define EOC ";&\n" 154 | #define GLOBCHARS "*?[" 155 | #define QUOTPACK "\"'" 156 | #define REDIRERR "(<>" 157 | #define WORDPACK " \t\"'();&|^<>\n" 158 | 159 | /* 160 | * typedefs and related macros 161 | */ 162 | typedef unsigned char UChar; 163 | #define UCHAR(c) ((UChar)(c)) 164 | #define UCPTR(p) ((UChar *)(p)) 165 | 166 | #endif /* !DEFS_H */ 167 | -------------------------------------------------------------------------------- /err.c: -------------------------------------------------------------------------------- 1 | /* 2 | * err.c - shell and utility error-handling routines 3 | */ 4 | /*- 5 | * Copyright (c) 2004-2014 6 | * Jeffrey Allen Neitzel . 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | * @(#)$Id: 064023797b32ff7fee61dd98f46c506c65af1349 $ 30 | */ 31 | 32 | #include "defs.h" 33 | #include "err.h" 34 | 35 | #define FMTMAX SBUFMM(2) 36 | #define MSGMAX (FMTMAX + LINEMAX) 37 | 38 | #define MYNAME "unknown" 39 | 40 | static void (*myerrexit)(int) = NULL; 41 | /*@observer@*/ 42 | static const char *myname = NULL; 43 | static pid_t mypid = -1; 44 | 45 | static void wmsg(int, const char *, va_list); 46 | 47 | /* 48 | * Handle all errors for the calling process. This includes printing 49 | * any specified non-NULL message to the standard error and calling 50 | * the error exit function pointed to by the global myerrexit. 51 | * This function may or may not return. 52 | */ 53 | void 54 | err(int es, const char *msgfmt, ...) 55 | { 56 | va_list va; 57 | 58 | if (msgfmt != NULL) { 59 | va_start(va, msgfmt); 60 | wmsg(FD2, msgfmt, va); 61 | va_end(va); 62 | } 63 | if (myerrexit == NULL) { 64 | fd_print(FD2, FMT1S, "err: Invalid myerrexit function pointer"); 65 | abort(); 66 | } 67 | 68 | (*myerrexit)(es); 69 | } 70 | 71 | /* 72 | * Print any specified non-NULL message to the file descriptor pfd. 73 | */ 74 | void 75 | fd_print(int pfd, const char *msgfmt, ...) 76 | { 77 | va_list va; 78 | 79 | if (msgfmt != NULL) { 80 | va_start(va, msgfmt); 81 | wmsg(pfd, msgfmt, va); 82 | va_end(va); 83 | } 84 | } 85 | 86 | /* 87 | * Get the line number for the offset of the file descriptor FD0. 88 | * Return line number on success. 89 | * Return -1 on error. 90 | */ 91 | long 92 | get_lnum(void) 93 | { 94 | struct stat sb; 95 | off_t o, o1; 96 | long n; 97 | UChar c; 98 | bool b; 99 | 100 | if (fstat(FD0, &sb) == -1 || !S_ISREG(sb.st_mode)) 101 | return -1; 102 | if ((o = lseek(FD0, (off_t)0, SEEK_CUR)) == -1) 103 | return -1; 104 | if ((o1 = lseek(FD0, (off_t)0, SEEK_SET)) != 0) 105 | return -1; 106 | for (b = false, n = 0; o1 != -1 && o1 < o; ) { 107 | if (read(FD0, &c, (size_t)1) != 1) 108 | break; 109 | o1 = lseek(FD0, (off_t)0, SEEK_CUR); 110 | if (c == EOS) { 111 | b = true; 112 | continue; 113 | } 114 | if (c == EOL) 115 | if (n > -1 && n < LONG_MAX) 116 | n += 1; 117 | } 118 | if (b) 119 | if (n > -1 && n < LONG_MAX) 120 | n += 1; 121 | n = (lseek(FD0, o, SEEK_SET) == o && n > -1 && n < LONG_MAX) ? n : -1; 122 | 123 | #ifdef DEBUG 124 | fd_print(FD2, "get_lnum: n == %ld;\n", n); 125 | #endif 126 | 127 | return n; 128 | } 129 | 130 | /* 131 | * Return a pointer to the global myname on success. 132 | * Return a pointer to "(null)" on error. 133 | * 134 | * NOTE: Must call setmyname(argv[0]) first. 135 | */ 136 | const char * 137 | getmyname(void) 138 | { 139 | 140 | if (myname == NULL) 141 | return "(null)"; 142 | 143 | return myname; 144 | } 145 | 146 | /* 147 | * Return the global mypid on success. 148 | * Return 0 on error. 149 | * 150 | * NOTE: Must call setmypid(getpid()) first. 151 | */ 152 | pid_t 153 | getmypid(void) 154 | { 155 | 156 | if (mypid == -1) 157 | return 0; 158 | 159 | return mypid; 160 | } 161 | 162 | /* 163 | * Set the global myerrexit to the function pointed to by func. 164 | */ 165 | void 166 | setmyerrexit(void (*func)(int)) 167 | { 168 | 169 | if (func == NULL) 170 | return; 171 | 172 | myerrexit = func; 173 | } 174 | 175 | /* 176 | * Set the global myname to the basename of the string pointed to by s. 177 | */ 178 | void 179 | setmyname(const char *s) 180 | { 181 | const char *p; 182 | 183 | if (s != NULL && *s != EOS) { 184 | if ((p = strrchr(s, SLASH)) != NULL) 185 | p++; 186 | else 187 | p = s; 188 | if (*p == HYPHEN && *(p + 1) != EOS) 189 | p++; 190 | else if (*p == EOS) 191 | /* should never (but can) be true */ 192 | p = MYNAME; 193 | } else 194 | /* should never (but can) be true */ 195 | p = MYNAME; 196 | 197 | myname = p; 198 | } 199 | 200 | /* 201 | * Set the global mypid to the process ID p. 202 | */ 203 | void 204 | setmypid(const pid_t p) 205 | { 206 | 207 | if (mypid != -1) 208 | return; 209 | 210 | mypid = p; 211 | } 212 | 213 | /* 214 | * Cause all shell utility processes to exit appropriately on error. 215 | * This function is called by err() and never returns. 216 | */ 217 | void 218 | ut_errexit(int es) 219 | { 220 | 221 | #ifdef DEBUG 222 | fd_print(FD2, "ut_errexit: es == %d: Call %s(%d);\n", 223 | es, (getpid() == getmypid()) ? "exit" : "_exit", es); 224 | #endif 225 | 226 | EXIT(es); 227 | } 228 | 229 | /* 230 | * Write the specified message to the file descriptor wfd. 231 | * A diagnostic is written to FD2 on error. 232 | */ 233 | static void 234 | wmsg(int wfd, const char *msgfmt, va_list va) 235 | { 236 | char msg[MSGMAX]; 237 | char fmt[FMTMAX]; 238 | struct iovec ev[4]; 239 | int i; 240 | 241 | i = snprintf(fmt, sizeof(fmt), "%s", msgfmt); 242 | if (i >= 1 && i < (int)sizeof(fmt)) { 243 | i = vsnprintf(msg, sizeof(msg), fmt, va); 244 | if (i >= 0 && i < (int)sizeof(msg)) { 245 | if (write(wfd, msg, strlen(msg)) == -1) { 246 | ev[0].iov_base = (char *)getmyname(); 247 | ev[0].iov_len = strlen(getmyname()); 248 | ev[1].iov_base = ": "; 249 | ev[1].iov_len = (size_t)2; 250 | ev[2].iov_base = ERR_WRITE; 251 | ev[2].iov_len = strlen(ERR_WRITE); 252 | ev[3].iov_base = "\n"; 253 | ev[3].iov_len = (size_t)1; 254 | (void)writev(FD2, ev, 4); 255 | } 256 | } 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * osh - an enhanced port of the Sixth Edition (V6) UNIX Thompson shell 3 | */ 4 | /*- 5 | * Copyright (c) 2004-2014 6 | * Jeffrey Allen Neitzel . 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | * @(#)$Id: 4fb9bfd1ccd16812525e7cab95f743171eaef5db $ 30 | */ 31 | 32 | #ifndef ERR_H 33 | #define ERR_H 34 | 35 | /* 36 | * required header files 37 | */ 38 | #include 39 | 40 | /* 41 | * diagnostics 42 | */ 43 | #define ERR_PAREN ") expected" 44 | #define ERR_ALIASLOOP "Alias loop error" 45 | #define ERR_GARGCOUNT "Arg count" 46 | #define ERR_E2BIG "Arg list too long" 47 | #define ERR_FORK "Cannot fork - try again" 48 | #define ERR_PIPE "Cannot pipe - try again" 49 | #define ERR_TRIM "Cannot trim" 50 | #define ERR_WRITE "Cannot write" 51 | #define ERR_CLOVERFLOW "Command line overflow" 52 | #define ERR_GNOTFOUND "Command not found." 53 | #define ERR_ALINVAL "Invalid argument list" 54 | #define ERR_AVIINVAL "Invalid argv index" 55 | #define ERR_NODIR "No directory" 56 | #define ERR_NOHOMEDIR "No home directory" 57 | #define ERR_NOMATCH "No match" 58 | #define ERR_NOPWD "No previous directory" 59 | #define ERR_NOSHELL "No shell!" 60 | #define ERR_NOTTY "No terminal!" 61 | #define ERR_NOMEM "Out of memory" 62 | #define ERR_PATTOOLONG "Pattern too long" 63 | #define ERR_SETID "Set-ID execution denied" 64 | #define ERR_TMARGS "Too many args" 65 | #define ERR_TMCHARS "Too many characters" 66 | #define ERR_ARGCOUNT "arg count" 67 | #define ERR_ARGUMENT "argument expected" 68 | #define ERR_BADDIR "bad directory" 69 | #define ERR_BADMASK "bad mask" 70 | #define ERR_BADNAME "bad name" 71 | #define ERR_BADSIGNAL "bad signal" 72 | #define ERR_CREATE "cannot create" 73 | #define ERR_EXEC "cannot execute" 74 | #define ERR_OPEN "cannot open" 75 | #define ERR_SEEK "cannot seek" 76 | #define ERR_COMMAND "command expected" 77 | #define ERR_DIGIT "digit expected" 78 | #define ERR_GENERIC "error" 79 | #define ERR_EXPR "expression expected" 80 | #define ERR_LABNOTFOUND "label not found" 81 | #define ERR_LABTOOLONG "label too long" 82 | #define ERR_NOARGS "no args" 83 | #define ERR_NOTDIGIT "not a digit" 84 | #define ERR_NOTFOUND "not found" 85 | #define ERR_INTEGER "integer expected" 86 | #define ERR_NOTINTEGER "not an integer" 87 | #define ERR_OPERATOR "operator expected" 88 | #define ERR_RANGE "out of range" 89 | #define ERR_SYNTAX "syntax error" 90 | #define ERR_OPUNKNOWN "unknown operator" 91 | #define ERR_BRACE "} expected" 92 | #define FD2_USAGE "usage: %s [-e] [-f file] [--] command [arg ...]\n" 93 | 94 | #define FMT1S "%s\n" 95 | #define FMT2LS "%s: %ld: %s\n" 96 | #define FMT2S "%s: %s\n" 97 | #define FMT3LFS "%s: %ld: %s: %s\n" 98 | #define FMT3LS "%s: %s: %ld: %s\n" 99 | #define FMT3S "%s: %s: %s\n" 100 | #define FMT4LFS "%s: %ld: %s: %s: %s\n" 101 | #define FMT4LS "%s: %s: %ld: %s: %s\n" 102 | #define FMT4S "%s: %s: %s: %s\n" 103 | #define FMT5LS "%s: %s: %ld: %s: %s: %s\n" 104 | #define FMT5S "%s: %s: %s: %s: %s\n" 105 | #define FMTAT1LS "%s: %s: %ld: %s %s\n" 106 | #define FMTAT1S "%s: %s: %s %s\n" 107 | #define FMTATLS "%s: %ld: %s %s\n" 108 | #define FMTATS "%s: %s %s\n" 109 | 110 | /* 111 | * exit status values 112 | */ 113 | #define FC_ERR 124 /* fatal child error (changed in pwait()) */ 114 | #define SH_ERR 2 /* shell-detected error (default value) */ 115 | #define SH_FALSE 1 116 | #define SH_TRUE 0 117 | 118 | #define ESTATUS ((getpid() == getmypid()) ? SH_ERR : FC_ERR) 119 | #define EXIT(s) ((getpid() == getmypid()) ? exit((s)) : _exit((s))) 120 | 121 | /* 122 | * #undef DEBUG* for production build 123 | */ 124 | #undef DEBUG 125 | #undef DEBUG_ALIAS 126 | #undef DEBUG_GLOB 127 | #undef DEBUG_PROC 128 | 129 | /*@maynotreturn@*/ 130 | void err(int, /*@null@*/ const char *, /*@printflike@*/ ...); 131 | void fd_print(int, /*@null@*/ const char *, /*@printflike@*/ ...); 132 | long get_lnum(void); 133 | /*@observer@*/ 134 | const char *getmyname(void); 135 | pid_t getmypid(void); 136 | void setmyerrexit(void (*)(int)); 137 | void setmyname(/*@null@*/ /*@observer@*/ const char *); 138 | void setmypid(const pid_t); 139 | /*@noreturn@*/ 140 | void ut_errexit(int); 141 | 142 | #endif /* !ERR_H */ 143 | -------------------------------------------------------------------------------- /examples/FILEPREP: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env osh 2 | : 3 | : osh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; 4 | : 5 | : " @(#)$Id: b10404fd31e0a70804540c00a5ae6d957eb577d0 $ " 6 | : 7 | : " The author of this file, J.A. Neitzel , " 8 | : " hereby grants it to the public domain. " 9 | : 10 | 11 | : 12 | : " Prepare system-wide rc files (etc.*) & user rc files (dot.*) " 13 | : " for installation on current machine so interactive & login " 14 | : " instances of osh can execute them on user's behalf. " 15 | : 16 | : " Print message, and exit w/ zero status on success. " 17 | : " Print diagnostic, and exit w/ non-zero status on error. " 18 | : 19 | : " usage: osh FILEPREP /path/to/nonexistent_directory " 20 | : 21 | 22 | : " Check for correct usage. " 23 | 24 | if X$0 != XFILEPREP -a X$0 != X./FILEPREP\ 25 | if { exit } fd2 -e echo FILEPREP: $0: Invalid FILEPREP pathname ; false 26 | if $# != 1 -o X$1 = X\ 27 | if { exit } fd2 -e echo usage: osh $0 /path/to/nonexistent_directory ;\ 28 | false 29 | if -e $1'' -o -h $1''\ 30 | if { exit } fd2 -e echo FILEPREP: $1: File exists ; false 31 | if { fd2 which . >/dev/null }\ 32 | if { exit } fd2 -e echo $0: which: Invalid results ; false 33 | if ! { which chmod cp head mkdir pwd rm strings tee tr >/dev/null }\ 34 | if { exit } false 35 | 36 | : " Do needed setup. " 37 | 38 | trap '' 2 3 ; umask 0022 39 | if { mkdir -p $1'' } cp *osh* $1/ 40 | if $? != 0 if { exit } false 41 | cd $1'' ; chmod 0644 * 42 | if ! { mkdir tmp-$$ } if { exit } false 43 | setenv OSHDIR tmp-$$ 44 | 45 | : " Prepare files for installation. " 46 | 47 | echo -n '<$1 ( rm -f $1 ; sed "s,@SYSCONFDIR@,' >$d/sysconfdir 48 | which osh | sed 's,.*,strings &,' | osh |\ 49 | sed -n 's,\(.*\)/osh.login,\1,p' >$d/sysconfdir_path 50 | <$d/sysconfdir_path tr -d '\n' >>$d/sysconfdir 51 | echo '," >$1 )' >>$d/sysconfdir 52 | osh - etc.osh.login etc.osh.oshrc etc.osh.logout ; goto EXECSHELL 53 | : Loop 54 | osh $d/sysconfdir $1 ; shift 55 | if $# = 0 exit 56 | goto Loop 57 | 58 | : EXECSHELL 59 | 60 | (\ 61 | echo -n '<$1 ( rm -f $1 ; sed "s,@EXECSHELL@,' ;\ 62 | which osh | tr -d '\n' ; echo '," >$1 )' ;\ 63 | ) >$d/execshell 64 | osh $d/execshell dot.osh.login 65 | : fallthrough 66 | 67 | : OSHDIR 68 | 69 | if ! { fd2 which oshdir >/dev/null } goto NotFound 70 | (\ 71 | echo -n '<$1 ( rm -f $1 ; sed "s,@SOURCE_OSHDIR@,source ' ;\ 72 | which oshdir | tr -d '\n' ; echo ' \$\$," >$1 )' ;\ 73 | ) >$d/oshdir 74 | goto Done 75 | 76 | : NotFound 77 | 78 | (\ 79 | echo -n '<$1 ( rm -f $1 ; sed "s,@SOURCE_OSHDIR@,' ;\ 80 | echo ': See http://v6shell.org/v6scripts/oshdir.osh .," >$1 )' ;\ 81 | ) >$d/oshdir 82 | : fallthrough 83 | 84 | : Done - " Finish, clean up, and exit w/ zero status. " 85 | 86 | osh $d/oshdir dot.osh.login 87 | : fallthrough 88 | 89 | (echo Successful File Prep! From the:;echo;echo -n ' ';pwd;echo;\ 90 | echo ...;echo directory, please manually copy:;echo)|tee fileprep.log 91 | 92 | (osh - *osh*;echo;echo ...;echo after modifying each file to taste.)|\ 93 | tee -a fileprep.log;rm -rf $d;: zero status;exit 94 | : Loop1 95 | echo -n ' '$1' to ' 96 | head -1 <$1 | sed 's,^: \(.*\) - .*$,echo \1,' | osh ; shift 97 | if $# = 0 exit 98 | goto Loop1 99 | -------------------------------------------------------------------------------- /examples/LICENSE: -------------------------------------------------------------------------------- 1 | =================================================================== 2 | 3 | The files in this directory are hereby granted to the public domain 4 | by the author, Jeffrey Allen Neitzel . 5 | 6 | === 7 | 8 | Jeffrey Allen Neitzel 2013/11/09 9 | 10 | @(#)$Id: 55aa7f4cd8dbc0b8fa65bc5b75a3b5a2d7386253 $ 11 | -------------------------------------------------------------------------------- /examples/README: -------------------------------------------------------------------------------- 1 | Welcome to Osh (V6Shell) RC Files! 2 | 3 | The Sixth Edition Thompson shell did not read/execute rc (init and 4 | logout) files. The fact that osh does so is simply one of its 5 | enhancements. This makes osh a much better login shell than it 6 | might be otherwise, as the ability to execute rc files can make 7 | things much easier for the user. An rc file is simply a regular 8 | shell script, aka command file, that the shell treats specially. 9 | 10 | For full details about how osh handles rc files, please refer to 11 | the "Startup and shutdown" subsection of osh(1) manual page @ 12 | http://v6shell.org/man/osh.1.html#StartupAndShutdown . 13 | 14 | This collection of osh(1) rc files may be studied as is, used as 15 | templates, modified, and/or installed for personal or general use. 16 | 17 | ------- 18 | INSTALL: 19 | 1) Run FILEPREP script to prepare rc files for installation. 20 | 21 | usage: osh FILEPREP /path/to/nonexistent_directory 22 | 23 | 2) cd or chdir to specified directory. 24 | 25 | 3) Modify *osh* files to taste (e.g., change PATH, etc). 26 | 27 | 4) Copy *osh* files to destinations noted in fileprep.log . 28 | 29 | ... 30 | Depending on system configuration, you may need to become superuser 31 | in order to successfully install system-wide rc files. 32 | 33 | ------- 34 | I install and use variations of these files on several different 35 | systems. This includes GNU/Linux, Mac OS X, NetBSD, OpenBSD, and 36 | OpenSolaris. On GNU/Linux systems, you may wish to refer to the 37 | manual pages for the utilities invoked in these files as there might 38 | be incompatibilities that I have not encountered. For example, 39 | this is true for stty(1). 40 | 41 | If you have any comments or questions about this software, I encourage 42 | you to contact me via email. Thanks & Enjoy! 43 | 44 | Jeffrey Allen Neitzel 45 | 46 | http://v6shell.org/rc_files 2012/06/02 47 | 48 | @(#)$Id: 97fe6521f64d1dc60fc0d1da1ccc2787d3f039e7 $ 49 | -------------------------------------------------------------------------------- /examples/dot.osh.login: -------------------------------------------------------------------------------- 1 | : $h/.osh.login - " Modify to taste. " 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/rc_files " 7 | : 8 | 9 | : fd2 -e echo "debug: Executing `"$h/.osh.login"' now..." 10 | 11 | if X$u != Xroot goto Continue 12 | 13 | : 14 | : " Give the superuser a different default PATH. " 15 | : 16 | setenv PATH /opt/local/bin:/usr/local/bin 17 | setenv PATH $p:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11/bin 18 | : fallthrough 19 | 20 | : Continue - " Continue as normal. " 21 | 22 | setenv MANPATH \ 23 | /opt/local/share/man:/usr/local/man:/usr/share/man:/usr/X11/share/man 24 | setenv PATH /usr/local/v6bin:$h/v6bin:$p:/usr/games 25 | setenv COMMAND_MODE unix2003 26 | setenv EXECSHELL @EXECSHELL@ 27 | setenv EDITOR '/bin/ed -p:' 28 | setenv VISUAL /opt/local/bin/vim 29 | setenv PAGER 'less -is' 30 | setenv LESS -M 31 | setenv TZ UTC 32 | 33 | : 34 | : " Make getopt(3) in the fd2 utility behave the same on " 35 | : " GNU/Linux systems as it does on *BSD & other systems. " 36 | : 37 | setenv POSIXLY_CORRECT '' 38 | 39 | alias logout '(trap)|if { grep "^trap .. 1$">/dev/null } fd2 -e echo "SIGHUP ignored - Type an EOT (^D) instead";trap "" 1;(trap)|if ! { grep "^trap .. 1$">/dev/null } fd2 -e echo "SIGHUP ignored - Type an EOT (^D) instead";kill -HUP $$;false' 40 | @SOURCE_OSHDIR@ 41 | 42 | : 43 | : " Start ssh-agent & ssh-add key(s) if possible. " 44 | : " Allow ssh key use across multiple login sessions. " 45 | : " Change `$h/.ssh/SshKeyFile' to private ssh key file. " 46 | : 47 | which ssh ssh-agent ssh-add >/dev/null 48 | if ! \( $? = 0 -a -e $h/.ssh/SshKeyFile \) goto NoSshAgentOrKey 49 | if { printenv SSH_AUTH_SOCK } -a ! { printenv IS_OSH_SSH_AGENT } goto AddOrReAddKey >/dev/null 50 | if -e $h/.osh-ssh-agent goto SourceSshAgent 51 | ( : ) >$h/.osh-ssh-agent ; chmod 0600 $h/.osh-ssh-agent 52 | echo ': Agent started by osh pid '$$ >$h/.osh-ssh-agent 53 | echo 'setenv IS_OSH_SSH_AGENT true;'>>$h/.osh-ssh-agent 54 | ssh-agent -c | head -2 >>$h/.osh-ssh-agent 55 | : fallthrough 56 | : SourceSshAgent 57 | source $h/.osh-ssh-agent 58 | : fallthrough 59 | : AddOrReAddKey 60 | ssh-add -l | grep $h/.ssh/SshKeyFile >/dev/null 61 | /dev/null 62 | : " Copy & adjust previous 2 lines for additional ssh keys... " 63 | : fallthrough 64 | : NoSshAgentOrKey 65 | 66 | : " Print a message or two at login time. " 67 | echo ; date '+%A, %Y-%m-%d, %T %Z' ; echo 68 | if -x /usr/games/fortune /usr/games/fortune -s 69 | : zero status 70 | -------------------------------------------------------------------------------- /examples/dot.osh.logout: -------------------------------------------------------------------------------- 1 | : $h/.osh.logout - " Modify to taste. " 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/rc_files " 7 | : 8 | 9 | trap '' 2 3 10 | 11 | : fd2 -e echo "debug: Executing `"$h/.osh.logout"' now..." 12 | 13 | : 14 | : " Check for ssh-agent started by $$, and kill it before logout. " 15 | : 16 | if ! -e $h/.osh-ssh-agent -o ! { printenv IS_OSH_SSH_AGENT } goto OshDir >/dev/null 17 | 18 | sed -n 1p <$h/.osh-ssh-agent | grep $$ >/dev/null 19 | if $? != 0 goto OshDir 20 | echo 'unsetenv IS_OSH_SSH_AGENT;' >$h/.osh-ssh-agent 21 | ssh-agent -c -k | head -2 >>$h/.osh-ssh-agent 22 | source $h/.osh-ssh-agent ; rm -f $h/.osh-ssh-agent 23 | 24 | : fallthrough 25 | 26 | : 27 | : " Check for OSHDIR ($d), and remove it before logout. " 28 | : 29 | : OshDir 30 | if X$d = X -o ! -d $d'' goto Logout 31 | 32 | chdir ; rm -r $d ; chdir - 33 | : fallthrough 34 | 35 | : Logout - " Log out or start new login shell according to user response. " 36 | 37 | chdir ; fd2 -e echo 38 | fd2 -e echo -n 'Do you want to log out now? ([y]/n) ' 39 | head -1 <- | tr -d ' \t' >osh-logout-$$ 40 | 41 | if ! -s osh-logout-$$ -o \ 42 | { egrep '^$|^[Yy][A-Za-z]*$' osh-logout-$$ >/dev/null } \ 43 | if { rm -f osh-logout-$$ } exit 44 | if ! { which osh >/dev/null } \ 45 | if { rm -f osh-logout-$$ } if { exit } sleep 5 46 | 47 | rm -f osh-logout-$$ ; unsetenv TTY ; chdir - 48 | clear <- ; trap - 2 3 ; exec osh -login <- 49 | -------------------------------------------------------------------------------- /examples/dot.oshrc: -------------------------------------------------------------------------------- 1 | : $h/.oshrc - " Modify to taste. " 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/rc_files " 7 | : 8 | 9 | : fd2 -e echo "debug: Executing `"$h/.oshrc"' now..." 10 | 11 | printenv TERM >/dev/null 12 | if $? = 0 goto TermIsSet 13 | 14 | setenv TERM vt100 15 | : fallthrough 16 | 17 | : TermIsSet 18 | printenv TTY | grep \^$t\$ >/dev/null 19 | if $? = 0 goto Continue 20 | 21 | setenv TTY $t 22 | 23 | printenv TERM | grep '^vt100$' >/dev/null 24 | if $? = 0 goto Continue 25 | printenv TERM | grep '^rxvt$' >/dev/null 26 | if $? = 0 goto C 27 | 28 | : 29 | : " The terminal I normally use is rxvt-unicode (urxvt), " 30 | : " but I also use others on occasion. Normally, they're " 31 | : " UTF-8 capable, but that's not always true. " 32 | : 33 | setenv LC_ALL en_US.UTF-8 34 | setenv LESSCHARSET utf-8 35 | printf "%b" '\033]701;en_US.UTF-8\007' >/dev/tty 36 | goto Continue 37 | 38 | : C - " Default to the C locale for rxvt. " 39 | 40 | setenv LC_ALL C 41 | : fallthrough 42 | 43 | : Continue - " Continue as normal. " 44 | 45 | : 46 | : " Set terminal options and window title if possible. " 47 | : 48 | uname -s | grep '^Linux$' >/dev/null 49 | if $? -eq 0 goto Uname-S-Linux 50 | ( stty altwerase imaxbel -oxtabs ; stty status '^T' ) <- 51 | : fallthrough 52 | : Uname-S-Linux 53 | xtitle 54 | 55 | : 56 | : " Set some useful aliases. " 57 | : " If you want an alias to ignore arguments, doing a: " 58 | : 59 | : alias foo ' echo foo bar baz ; : ' 60 | : 61 | : " or " 62 | : 63 | : alias foo 'echo foo bar baz;:' 64 | : 65 | : " ... " 66 | : " or similar (for example) is a simple way to do so. " 67 | : " The terminating ` ; : ' or `;:' (in effect) turns " 68 | : " alias arguments into a no-op. " 69 | : 70 | alias aliases '(alias;:)' 71 | alias aman 'setenv LC_ALL C;setenv LESSCHARSET ascii;man' 72 | alias anroff 'setenv LC_ALL C;setenv LESSCHARSET ascii;nroff -mandoc -Tascii' 73 | alias glob 'echo' 74 | alias hcount "setenv LC_ALL C;awk '{print \$1;}'<$h/.osh.history|sort|uniq -c|sort -k1 -rn|head -25;:" 75 | alias isset 'set' 76 | : " Set sysinfo alias (w/o system_profiler). " 77 | alias sysinfo "echo -n '==== ';uname -n|tr -d \\n;echo ' ====';echo;uname -srm;echo;now;echo;uptime;:" 78 | uname -s | grep '^Darwin$' >/dev/null 79 | if $? -ne 0 goto Uname-S-NotDarwin 80 | alias l 'leaks $$;:' 81 | : " If Darwin, reset sysinfo alias (w/ system_profiler). " 82 | alias sysinfo "echo -n '==== ';uname -n|tr -d \\n;echo ' ====';echo;uname -srm;system_profiler SPSoftwareDataType|grep 'System Version:'|sed 's/^.*: //';echo;now;echo;uptime;:" 83 | : fallthrough 84 | : Uname-S-NotDarwin 85 | alias lf 'ls -F' 86 | alias li 'ls -i' 87 | alias ll 'ls -AlF' 88 | alias loadavg "uname -n|sed 's/\([^.]*\).*/\1/'|tr -d \\n;echo -n ': ';uptime|sed 's/^.*user[s,][ ,] *//';:" 89 | alias manpath 'echo $m;:' 90 | alias n 'echo "日本語 Nihongo";:' 91 | alias now "date '+%A, %Y-%m-%d, %T %Z';:" 92 | alias ocpwd 'cd -;pwd;cd -;pwd' 93 | alias opwd 'cd -;pwd' 94 | alias path 'echo $p;:' 95 | alias pparm 'echo $0: $#: $*;:' 96 | alias sh6i 'sh6 -c xtitle;sh6;xtitle;:' 97 | alias s 'echo $?;:' 98 | alias status 's' 99 | alias v 'echo $v;:' 100 | alias v1 'version' 101 | ( alias logout ) | wc -c | tr -d ' \t' | grep '^0$' >/dev/null 102 | if $? != 0 goto Jump 103 | alias logout 'fd2 -e echo "Not an osh login shell - Type an EOT (^D) instead";false' 104 | : Jump 105 | : nothing 106 | -------------------------------------------------------------------------------- /examples/etc.osh.login: -------------------------------------------------------------------------------- 1 | : @SYSCONFDIR@/osh.login - " Modify to taste. " 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/rc_files " 7 | : 8 | 9 | trap '' 1 2 3 13 14 15 ; : " Ignore HUP, INT, QUIT, PIPE, ALRM, and TERM. " 10 | trap '' 18 21 22 ; : " Ignore job-control signals: TSTP, TTIN, TTOU " 11 | 12 | : 13 | : " Set a default PATH and umask for all users. " 14 | : 15 | setenv PATH /opt/local/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11/bin 16 | umask 0022 17 | 18 | : fd2 -e echo "debug: Executing `@SYSCONFDIR@/osh.login' now..." 19 | 20 | setenv MAIL /var/mail/$u 21 | setenv CTTY $t 22 | uname -s | grep '^Linux$' >/dev/null 23 | if $? -ne 0 stty status '^T' <- 24 | 25 | if X$h = X -o ! -d $h'' goto finish 26 | if ! { mkdir $h/.osh.setenv.$$ } goto finish 27 | 28 | : 29 | : " Use the output from `uname -n' to `setenv HOST value'. " 30 | : " Notice that doing so requires using a temporary file. " 31 | : 32 | uname -n | sed 's,\([^.]*\).*,setenv HOST \1,' >$h/.osh.setenv.$$/HOST 33 | source $h/.osh.setenv.$$/HOST 34 | rm -r $h/.osh.setenv.$$ 35 | : fallthrough 36 | 37 | : finish 38 | 39 | trap - 1 2 3 13 14 15 ; : " Reset the ignored, non-job-control signals. " 40 | -------------------------------------------------------------------------------- /examples/etc.osh.logout: -------------------------------------------------------------------------------- 1 | : @SYSCONFDIR@/osh.logout - " Modify to taste. " 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/rc_files " 7 | : 8 | 9 | trap '' 1 2 3 13 14 15 ; : " Ignore HUP, INT, QUIT, PIPE, ALRM, and TERM. " 10 | trap '' 18 21 22 ; : " Ignore job-control signals: TSTP, TTIN, TTOU " 11 | 12 | : fd2 -e echo "debug: Executing `@SYSCONFDIR@/osh.logout' now..." 13 | 14 | : Insert useful logout routines here. 15 | 16 | trap - 1 2 3 13 14 15 ; : " Reset the ignored, non-job-control signals. " 17 | -------------------------------------------------------------------------------- /examples/etc.osh.oshrc: -------------------------------------------------------------------------------- 1 | : @SYSCONFDIR@/osh.oshrc - " Modify to taste. " 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/rc_files " 7 | : 8 | 9 | trap '' 1 2 3 13 14 15 ; : " Ignore HUP, INT, QUIT, PIPE, ALRM, and TERM. " 10 | trap '' 18 21 22 ; : " Ignore job-control signals: TSTP, TTIN, TTOU " 11 | 12 | : fd2 -e echo "debug: Executing `@SYSCONFDIR@/osh.oshrc' now..." 13 | 14 | : Insert useful initialization routines here. 15 | 16 | trap - 1 2 3 13 14 15 ; : " Reset the ignored, non-job-control signals. " 17 | -------------------------------------------------------------------------------- /fd2.1: -------------------------------------------------------------------------------- 1 | .\" 2 | .\" Copyright (c) 2005-2014 3 | .\" Jeffrey Allen Neitzel . 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code must retain the above copyright 10 | .\" notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 15 | .\" THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 16 | .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | .\" DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 19 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 | .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24 | .\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | .\" 26 | .\" @(#)$Id: a2fbd1ccf3c4ccde9435951e8b5c3d6a084e0fac $ 27 | .\" 28 | .\" Includes public domain content derived from: 29 | .\" - /usr/src/bin/ksh/sh.1 30 | .\" $OpenBSD: sh.1,v 1.91 2011/09/03 22:59:08 jmc Exp $ 31 | .\" 32 | .TH FD2 1 "@OSH_DATE@" "@OSH_VERSION@" "General Commands" 33 | .SH NAME 34 | fd2 \- redirect from/to file descriptor 2 35 | .SH SYNOPSIS 36 | .B fd2 37 | [\fB\-e\fR] [\fB\-f\fR \fIfile\fR] [\fB\-\-\fR] \fIcommand\fR [\fIarg ...\fR] 38 | .SH DESCRIPTION 39 | Since the Sixth Edition UNIX shell provides 40 | no way to redirect the diagnostic output, 41 | .B fd2 42 | makes this possible by executing the specified 43 | .I command 44 | with the given arguments 45 | and redirecting file descriptor 2 (standard error) 46 | to file descriptor 1 (standard output) by default. 47 | .PP 48 | The options are as follows: 49 | .TP 50 | .B \-e 51 | Causes all conventional output from 52 | .I command 53 | to be redirected to the standard error 54 | as diagnostic output. 55 | .TP 56 | .BI \-f \ file 57 | Causes all diagnostic output from 58 | .I command 59 | to be redirected to \fIfile\fR, 60 | which is created if it does not exist. 61 | If it already exists, 62 | all diagnostic output is appended 63 | to the end of \fIfile\fR. 64 | .TP 65 | .B \-\- 66 | Causes 67 | .B fd2 68 | to stop further option processing, 69 | forcing it to treat all following arguments 70 | as \fIcommand\fR [\fIarg ...\fR] . 71 | .SH "EXIT STATUS" 72 | If 73 | .B fd2 74 | detects an error, 75 | it prints an appropriate diagnostic 76 | and exits with a non-zero status. 77 | Otherwise, 78 | the exit status is that 79 | of the executed command. 80 | .SH ENVIRONMENT 81 | .TP 82 | .B EXECSHELL 83 | If set to a non-empty string, 84 | the value of this variable is taken as the 85 | path name of the shell which is invoked to 86 | execute the specified command when it does not 87 | begin with the proper magic number 88 | or a `#!shell' sequence. 89 | .TP 90 | .B PATH 91 | If set to a non-empty string, 92 | the value of this variable is taken as the 93 | sequence of directories which is used to 94 | search for the specified command. 95 | .SH EXAMPLES 96 | The examples below which refer to `/tmp/$$' assume 97 | that this directory exists and is writable by the user. 98 | The following command line: 99 | .PP 100 | .RS 6 101 | fd2 \-e echo progname: Error message 102 | .RE 103 | .PP 104 | causes all conventional output from 105 | .I echo 106 | to be redirected to the standard error 107 | as diagnostic output. 108 | The following command line: 109 | .PP 110 | .RS 6 111 | fd2 make foo >/tmp/$$/foo.outerr 112 | .RE 113 | .PP 114 | causes all conventional and diagnostic output from 115 | .I make 116 | to be redirected to the file `/tmp/$$/foo.outerr', 117 | which is first created by the shell. 118 | In contrast: 119 | .PP 120 | .RS 6 121 | fd2 \-f /tmp/$$/foo.err make foo >/tmp/$$/foo.out 122 | .RE 123 | .PP 124 | causes all conventional output to be redirected 125 | to the file `/tmp/$$/foo.out', 126 | which is created by the shell. 127 | All diagnostic output is redirected 128 | to the file `/tmp/$$/foo.err', 129 | which is created by 130 | .B fd2 131 | if it does not already exist. 132 | .SH "SEE ALSO" 133 | osh(1), 134 | sh6(1) 135 | .PP 136 | Osh home page: 137 | http://v6shell.org/ 138 | .SH AUTHOR 139 | This implementation of 140 | .B fd2 141 | is written by Jeffrey Allen Neitzel. 142 | .SH LICENSE 143 | See either the LICENSE file which is distributed with 144 | .B osh 145 | or 146 | http://v6shell.org/license/ 147 | for full details. 148 | .SH COPYRIGHT 149 | .nf 150 | Copyright (c) 2005-2014 151 | Jeffrey Allen Neitzel. All rights reserved. 152 | 153 | Copyright (c) 1985, 1989, 1991, 1993 154 | The Regents of the University of California. All rights reserved. 155 | .fi 156 | -------------------------------------------------------------------------------- /fd2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * fd2.c - redirect from/to file descriptor 2 3 | */ 4 | /*- 5 | * Copyright (c) 2005-2014 6 | * Jeffrey Allen Neitzel . 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | * @(#)$Id: db0f5ca64bab8eef27339ebb08db8f809df66691 $ 30 | */ 31 | 32 | #include "defs.h" 33 | #include "err.h" 34 | #include "pexec.h" 35 | 36 | const char *name; 37 | bool no_lnum = true; /* no line number flag */ 38 | 39 | static bool fd_isopen(int); 40 | /*@noreturn@*/ 41 | static void usage(void); 42 | 43 | /* 44 | * NAME 45 | * fd2 - redirect from/to file descriptor 2 46 | * 47 | * SYNOPSIS 48 | * fd2 [-e] [-f file] [--] command [arg ...] 49 | * 50 | * DESCRIPTION 51 | * See the fd2(1) manual page for full details. 52 | */ 53 | int 54 | main(int argc, char **argv) 55 | { 56 | bool eopt; 57 | int efd, fd, nfd, ofd, opt; 58 | char *file; 59 | 60 | setmyerrexit(&ut_errexit); 61 | setmyname(argv[0]); 62 | setmypid(getpid()); 63 | 64 | /* 65 | * Set-ID execution is not supported. 66 | */ 67 | if (geteuid() != getuid() || getegid() != getgid()) 68 | err(FC_ERR, FMT2S, getmyname(), ERR_SETID); 69 | 70 | /* 71 | * File descriptors 0, 1, and 2 must be open. 72 | */ 73 | for (fd = 0; fd < 3; fd++) 74 | if (!fd_isopen(fd)) 75 | err(FC_ERR, "%s: %u: %s\n", 76 | getmyname(), (unsigned)fd, strerror(errno)); 77 | 78 | ofd = FD1, efd = FD2; 79 | eopt = false, file = NULL; 80 | while ((opt = getopt(argc, argv, ":ef:")) != -1) 81 | switch (opt) { 82 | case 'e': 83 | eopt = true; 84 | break; 85 | case 'f': 86 | file = optarg; 87 | break; 88 | default: 89 | usage(); 90 | } 91 | argc -= optind; 92 | argv += optind; 93 | if (argc < 1) 94 | usage(); 95 | 96 | if (file != NULL) { 97 | if ((nfd = open(file, O_WRONLY|O_APPEND|O_CREAT, 0666)) == -1) 98 | err(FC_ERR, FMT3S, getmyname(), file, ERR_CREATE); 99 | if (dup2(nfd, efd) == -1) 100 | err(FC_ERR, FMT2S, getmyname(), strerror(errno)); 101 | if (eopt && dup2(efd, ofd) == -1) 102 | err(FC_ERR, FMT2S, getmyname(), strerror(errno)); 103 | (void)close(nfd); 104 | } else { 105 | if (eopt) 106 | ofd = FD2, efd = FD1; 107 | if (dup2(ofd, efd) == -1) 108 | err(FC_ERR, FMT2S, getmyname(), strerror(errno)); 109 | } 110 | 111 | /* 112 | * Try to execute the specified command. 113 | */ 114 | (void)err_pexec(argv[0], argv); 115 | /*NOTREACHED*/ 116 | return FC_ERR; 117 | } 118 | 119 | static bool 120 | fd_isopen(int fd) 121 | { 122 | struct stat sb; 123 | 124 | return fstat(fd, &sb) == 0; 125 | } 126 | 127 | static void 128 | usage(void) 129 | { 130 | 131 | err(FC_ERR, FD2_USAGE, getmyname()); 132 | } 133 | -------------------------------------------------------------------------------- /glob6.1: -------------------------------------------------------------------------------- 1 | .\" 2 | .\" Copyright (c) 2006-2014 3 | .\" Jeffrey Allen Neitzel . 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code must retain the above copyright 10 | .\" notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 15 | .\" THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 16 | .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | .\" DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 19 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 | .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24 | .\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | .\" 26 | .\" @(#)$Id: 9b2f99a0156d23f5a68b3e1fe39f5a9e8db0e758 $ 27 | .\" 28 | .\" Derived from: 29 | .\" - Sixth Edition UNIX /usr/man/man1/sh.1 30 | .\" - Sixth Edition UNIX /usr/man/man8/glob.8 31 | .\" 32 | .\" Copyright (C) Caldera International Inc. 2001-2002. All rights reserved. 33 | .\" 34 | .\" Redistribution and use in source and binary forms, with or without 35 | .\" modification, are permitted provided that the following conditions 36 | .\" are met: 37 | .\" 1. Redistributions of source code and documentation must retain the above 38 | .\" copyright notice, this list of conditions and the following disclaimer. 39 | .\" 2. Redistributions in binary form must reproduce the above copyright 40 | .\" notice, this list of conditions and the following disclaimer in the 41 | .\" documentation and/or other materials provided with the distribution. 42 | .\" 3. All advertising materials mentioning features or use of this software 43 | .\" must display the following acknowledgement: 44 | .\" This product includes software developed or owned by Caldera 45 | .\" International, Inc. 46 | .\" 4. Neither the name of Caldera International, Inc. nor the names of other 47 | .\" contributors may be used to endorse or promote products derived from 48 | .\" this software without specific prior written permission. 49 | .\" 50 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 51 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 52 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 53 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 54 | .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 55 | .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 56 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 57 | .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 58 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 59 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 60 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 61 | .\" POSSIBILITY OF SUCH DAMAGE. 62 | .\" 63 | .\" Includes public domain content derived from: 64 | .\" - /usr/src/bin/ksh/sh.1 65 | .\" $OpenBSD: sh.1,v 1.91 2011/09/03 22:59:08 jmc Exp $ 66 | .\" 67 | .TH GLOB6 1 "@OSH_DATE@" "@OSH_VERSION@" "General Commands" 68 | .SH NAME 69 | glob6 \- global command (file name generation) 70 | .SH SYNOPSIS 71 | .B glob6 72 | \fIcommand\fR [\fIarg ...\fR] 73 | .SH DESCRIPTION 74 | .B Glob6 75 | is a port of the global command from Sixth Edition UNIX. 76 | It is passed an argument list by 77 | .IR sh6 (1) 78 | which contains one or more unquoted 79 | .I "pattern characters" 80 | (\fB*\fR, \fB?\fR, \fB[\fR) 81 | and performs the actions described below 82 | on behalf of the shell. 83 | .PP 84 | .B Glob6 85 | attempts to generate file-name arguments which match 86 | the given pattern arguments. 87 | The name of the specified 88 | .I command 89 | may also be given as a pattern. 90 | The meaning of each pattern character is as follows: 91 | .IP o 4 92 | The \fB*\fR character in a pattern matches any string of 93 | characters in a file name (including the null string). 94 | .IP o 95 | The \fB?\fR character in a pattern matches any single character 96 | in a file name. 97 | .IP o 98 | The \fB[...]\fR brackets in a pattern specifies a class of characters 99 | which matches any single file-name character in the class. 100 | Within the brackets, 101 | each character is taken to be a member of the class. 102 | A pair of characters separated by an unquoted \fB\-\fR specifies 103 | the class as a range which matches each character lexically 104 | between the first and second member of the pair, inclusive. 105 | A \fB\-\fR matches itself when quoted or when first or last 106 | in the class. 107 | .PP 108 | Any other character in a pattern matches itself in a file name. 109 | .PP 110 | Notice that the `.' character at the beginning of a file name, 111 | or immediately following a `/', 112 | is always special in that it must be matched explicitly. 113 | The same is true of the `/' character itself. 114 | .PP 115 | If the pattern contains no `/' characters, 116 | the current directory is always used. 117 | Otherwise, 118 | the specified directory is the one obtained by taking the pattern 119 | up to the last `/' before the first unquoted \fB*\fR, \fB?\fR, or \fB[\fR. 120 | The matching process matches the remainder of the pattern 121 | after this `/' against the files in the specified directory. 122 | .PP 123 | If the argument contains no unquoted pattern characters, 124 | .B glob6 125 | uses it as is. 126 | Otherwise, 127 | glob6 searches for file names in the current 128 | (or specified) directory which match the pattern. 129 | It then sorts them in ascending ASCII order, 130 | and the new sequence of arguments replaces the given pattern. 131 | The same process is carried out for each of the given arguments; 132 | the resulting lists are 133 | .I not 134 | merged. 135 | Finally, 136 | glob6 attempts to execute the command 137 | with the resulting argument list. 138 | .SH "EXIT STATUS" 139 | If 140 | .B glob6 141 | detects an error, 142 | it prints an appropriate diagnostic 143 | and exits with a non-zero status. 144 | Otherwise, 145 | the exit status is that 146 | of the executed command. 147 | .SH ENVIRONMENT 148 | Notice that the concept of `user environment' 149 | was not defined in Sixth Edition UNIX. 150 | Thus, 151 | use of the following environment variables 152 | by this port of the global command 153 | is an enhancement: 154 | .TP 155 | .B EXECSHELL 156 | If set to a non-empty string, 157 | the value of this variable is taken as the 158 | path name of the shell which is invoked to 159 | execute the specified command when it does not 160 | begin with the proper magic number 161 | or a `#!shell' sequence. 162 | .TP 163 | .B PATH 164 | If set to a non-empty string, 165 | the value of this variable is taken as the 166 | sequence of directories which is used to 167 | search for the specified command. 168 | Notice that the 169 | global command from Sixth Edition UNIX 170 | always used the equivalent of `.:/bin:/usr/bin', 171 | not PATH. 172 | .SH "SEE ALSO" 173 | sh6(1) 174 | .PP 175 | Osh home page: 176 | http://v6shell.org/ 177 | .SH HISTORY 178 | A 179 | .B glob 180 | command 181 | appeared as 182 | .I /etc/glob 183 | in First Edition UNIX. 184 | .SH LICENSE 185 | See either the LICENSE file which is distributed with 186 | .B osh 187 | or 188 | http://v6shell.org/license/ 189 | for full details. 190 | .SH COPYRIGHT 191 | .nf 192 | Copyright (c) 2006-2014 193 | Jeffrey Allen Neitzel. All rights reserved. 194 | 195 | Copyright (c) 2001-2002 196 | Caldera International Inc. All rights reserved. 197 | 198 | Copyright (c) 1985, 1989, 1991, 1993 199 | The Regents of the University of California. All rights reserved. 200 | .fi 201 | -------------------------------------------------------------------------------- /glob6.c: -------------------------------------------------------------------------------- 1 | /* 2 | * glob6.c - a port of the Sixth Edition (V6) UNIX global command 3 | */ 4 | /*- 5 | * Copyright (c) 2004-2014 6 | * Jeffrey Allen Neitzel . 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | * @(#)$Id: 918e35ed10609114595ab827323e206c68a2cddd $ 30 | */ 31 | /* 32 | * Derived from: Sixth Edition UNIX /usr/source/s1/glob.c 33 | */ 34 | /*- 35 | * Copyright (C) Caldera International Inc. 2001-2002. All rights reserved. 36 | * 37 | * Redistribution and use in source and binary forms, with or without 38 | * modification, are permitted provided that the following conditions 39 | * are met: 40 | * 1. Redistributions of source code and documentation must retain the above 41 | * copyright notice, this list of conditions and the following disclaimer. 42 | * 2. Redistributions in binary form must reproduce the above copyright 43 | * notice, this list of conditions and the following disclaimer in the 44 | * documentation and/or other materials provided with the distribution. 45 | * 3. All advertising materials mentioning features or use of this software 46 | * must display the following acknowledgement: 47 | * This product includes software developed or owned by Caldera 48 | * International, Inc. 49 | * 4. Neither the name of Caldera International, Inc. nor the names of other 50 | * contributors may be used to endorse or promote products derived from 51 | * this software without specific prior written permission. 52 | * 53 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 54 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 55 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 56 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 57 | * IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 58 | * INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 59 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 60 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 62 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 63 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 64 | * POSSIBILITY OF SUCH DAMAGE. 65 | */ 66 | 67 | #include "defs.h" 68 | #include "err.h" 69 | #include "pexec.h" 70 | 71 | const char *name; 72 | bool no_lnum = true; /* no line number flag */ 73 | 74 | static const char **gavp; /* points to current gav position */ 75 | static const char **gave; /* points to current gav end */ 76 | static size_t gavtot; /* total bytes used for all arguments */ 77 | 78 | /*@maynotreturn@*/ 79 | static const char **gnew(/*@only@*/ const char **); 80 | /*@maynotreturn@*/ 81 | static char *gcat(const char *, const char *); 82 | /*@maynotreturn@*/ 83 | static const char **glob1(/*@only@*/ const char **, char *, int *); 84 | static bool glob2(const UChar *, const UChar *); 85 | static void gsort(const char **); 86 | /*@null@*/ 87 | static DIR *gopendir(const char *); 88 | 89 | /* 90 | * NAME 91 | * glob6 - global command (file name generation) 92 | * 93 | * SYNOPSIS 94 | * glob6 command [arg ...] 95 | * 96 | * DESCRIPTION 97 | * See glob6(1) the manual page for full details. 98 | */ 99 | int 100 | main(int argc, char **argv) 101 | { 102 | const char **gav; /* points to generated argument vector */ 103 | int pmc = 0; /* pattern-match count */ 104 | 105 | setmyerrexit(&ut_errexit); 106 | setmyname(argv[0]); 107 | setmypid(getpid()); 108 | 109 | /* 110 | * Set-ID execution is not supported. 111 | */ 112 | if (geteuid() != getuid() || getegid() != getgid()) 113 | err(SH_ERR, FMT1S, ERR_SETID); 114 | 115 | if (argc < 2) 116 | err(SH_ERR, FMT1S, ERR_GARGCOUNT); 117 | 118 | if ((gav = malloc(GAVNEW * sizeof(char *))) == NULL) { 119 | err(SH_ERR, FMT1S, ERR_NOMEM); 120 | /*NOTREACHED*/ 121 | } 122 | 123 | *gav = NULL; 124 | gavp = gav; 125 | gave = &gav[GAVNEW - 1]; 126 | while (*++argv != NULL) 127 | gav = glob1(gav, *argv, &pmc); 128 | gavp = NULL; 129 | 130 | if (pmc == 0) { 131 | err(SH_ERR, FMT1S, ERR_NOMATCH); 132 | /*NOTREACHED*/ 133 | } 134 | 135 | (void)err_pexec(gav[0], (char *const *)gav); 136 | /*NOTREACHED*/ 137 | return SH_ERR; 138 | } 139 | 140 | static const char ** 141 | gnew(const char **gav) 142 | { 143 | size_t siz; 144 | ptrdiff_t gidx; 145 | const char **nav; 146 | static unsigned mult = 1; 147 | 148 | if (gavp == gave) { 149 | mult *= GAVMULT; 150 | #ifdef DEBUG 151 | #ifdef DEBUG_GLOB 152 | fd_print(FD2, "gnew: mult == %u;\n", mult); 153 | #endif 154 | #endif 155 | gidx = (ptrdiff_t)(gavp - gav); 156 | siz = (size_t)((gidx + (GAVNEW * mult)) * sizeof(char *)); 157 | #ifdef DEBUG 158 | #ifdef DEBUG_GLOB 159 | fd_print(FD2, " : (GAVNEW * mult) == %u, siz == %zu;\n", 160 | (GAVNEW * mult), siz); 161 | #endif 162 | #endif 163 | if ((nav = realloc(gav, siz)) == NULL) { 164 | err(SH_ERR, FMT1S, ERR_NOMEM); 165 | /*NOTREACHED*/ 166 | } 167 | gav = nav; 168 | gavp = gav + gidx; 169 | gave = &gav[gidx + (GAVNEW * mult) - 1]; 170 | } 171 | return gav; 172 | } 173 | 174 | static char * 175 | gcat(const char *src1, const char *src2) 176 | { 177 | size_t siz; 178 | char *b, buf[PATHMAX], c, *dst; 179 | const char *s; 180 | 181 | *buf = EOS; 182 | b = buf; 183 | s = src1; 184 | while ((c = *s++) != EOS) { 185 | if (b >= &buf[PATHMAX - 1]) 186 | err(SH_ERR, FMT1S, strerror(ENAMETOOLONG)); 187 | if ((c &= ASCII) == EOS) { 188 | *b++ = SLASH; 189 | break; 190 | } 191 | *b++ = c; 192 | } 193 | 194 | s = src2; 195 | do { 196 | if (b >= &buf[PATHMAX]) 197 | err(SH_ERR, FMT1S, strerror(ENAMETOOLONG)); 198 | *b++ = c = *s++; 199 | } while (c != EOS); 200 | b--; 201 | 202 | siz = (b - buf) + 1; 203 | gavtot += siz; 204 | if (gavtot > GAVMAX) 205 | err(SH_ERR, FMT1S, ERR_E2BIG); 206 | #ifdef DEBUG 207 | #ifdef DEBUG_GLOB 208 | fd_print(FD2, "gcat: siz == %zu, (%p < %p) == %s;\n", 209 | siz, b, &buf[PATHMAX], (b < &buf[PATHMAX]) ? "true" : "false"); 210 | fd_print(FD2, " : strlen(buf) == %zu;\n", strlen(buf)); 211 | #endif 212 | #endif 213 | if ((dst = malloc(siz)) == NULL) { 214 | err(SH_ERR, FMT1S, ERR_NOMEM); 215 | /*NOTREACHED*/ 216 | } 217 | 218 | (void)memcpy(dst, buf, siz); 219 | return dst; 220 | } 221 | 222 | static const char ** 223 | glob1(const char **gav, char *as, int *pmc) 224 | { 225 | DIR *dirp; 226 | struct dirent *entry; 227 | ptrdiff_t gidx; 228 | const char *ds; 229 | char *ps; 230 | 231 | ds = ps = as; 232 | while (*ps != ASTERISK && *ps != QUESTION && *ps != LBRACKET) 233 | if (*ps++ == EOS) { 234 | gav = gnew(gav); 235 | *gavp++ = gcat(as, ""); 236 | *gavp = NULL; 237 | return gav; 238 | } 239 | if (strlen(as) >= PATHMAX) { 240 | err(SH_ERR, FMT1S, ERR_PATTOOLONG); 241 | /*NOTREACHED*/ 242 | } 243 | for (;;) { 244 | if (ps == ds) { 245 | ds = ""; 246 | break; 247 | } 248 | if ((*--ps & ASCII) == SLASH) { 249 | *ps = EOS; 250 | if (ds == ps) 251 | ds = "/"; 252 | *ps++ = (char)QUOTE; 253 | break; 254 | } 255 | } 256 | if ((dirp = gopendir(*ds != EOS ? ds : ".")) == NULL) { 257 | err(SH_ERR, FMT1S, ERR_NODIR); 258 | /*NOTREACHED*/ 259 | } 260 | gidx = (ptrdiff_t)(gavp - gav); 261 | while ((entry = readdir(dirp)) != NULL) { 262 | if (entry->d_name[0] == DOT && (*ps & ASCII) != DOT) 263 | continue; 264 | if (glob2(UCPTR(entry->d_name), UCPTR(ps))) { 265 | gav = gnew(gav); 266 | *gavp++ = gcat(ds, entry->d_name); 267 | (*pmc)++; 268 | } 269 | } 270 | (void)closedir(dirp); 271 | gsort(gav + gidx); 272 | *gavp = NULL; 273 | return gav; 274 | } 275 | 276 | static bool 277 | glob2(const UChar *ename, const UChar *pattern) 278 | { 279 | int cok, rok; /* `[...]' - cok (class), rok (range) */ 280 | UChar c, ec, pc; 281 | const UChar *e, *n, *p; 282 | 283 | e = ename; 284 | p = pattern; 285 | if ((ec = *e++) != EOS) 286 | if ((ec &= ASCII) == EOS) 287 | ec = (UChar)QUOTE; 288 | 289 | switch (pc = *p++) { 290 | case EOS: 291 | return ec == EOS; 292 | 293 | case ASTERISK: 294 | /* 295 | * Ignore all but the last `*' in a group of consecutive 296 | * `*' characters to avoid unnecessary glob2() recursion. 297 | */ 298 | while (*p++ == ASTERISK) 299 | ; /* nothing */ 300 | if (*--p == EOS) 301 | return true; 302 | e--; 303 | while (*e != EOS) 304 | if (glob2(e++, p)) 305 | return true; 306 | break; 307 | 308 | case QUESTION: 309 | if (ec != EOS) 310 | return glob2(e, p); 311 | break; 312 | 313 | case LBRACKET: 314 | if (*p == EOS) 315 | break; 316 | for (c = UCHAR(EOS), cok = rok = 0, n = p + 1; ; ) { 317 | pc = *p++; 318 | if (pc == RBRACKET && p > n) { 319 | if (cok > 0 || rok > 0) 320 | return glob2(e, p); 321 | break; 322 | } 323 | if (*p == EOS) 324 | break; 325 | if (pc == HYPHEN && c != EOS && *p != RBRACKET) { 326 | pc = *p++ & ASCII; 327 | if (*p == EOS) 328 | break; 329 | if (c <= ec && ec <= pc) 330 | rok++; 331 | else if (c == ec) 332 | cok--; 333 | c = UCHAR(EOS); 334 | } else { 335 | c = pc & ASCII; 336 | if (ec == c) 337 | cok++; 338 | } 339 | } 340 | break; 341 | 342 | default: 343 | if ((pc & ASCII) == ec) 344 | return glob2(e, p); 345 | } 346 | return false; 347 | } 348 | 349 | static void 350 | gsort(const char **ogavp) 351 | { 352 | const char **p1, **p2, *sap; 353 | 354 | p1 = ogavp; 355 | while (gavp - p1 > 1) { 356 | p2 = p1; 357 | while (++p2 < gavp) 358 | if (strcmp(*p1, *p2) > 0) { 359 | sap = *p1; 360 | *p1 = *p2; 361 | *p2 = sap; 362 | } 363 | p1++; 364 | } 365 | } 366 | 367 | static DIR * 368 | gopendir(const char *dname) 369 | { 370 | char *b, buf[PATHMAX]; 371 | const char *d; 372 | 373 | for (*buf = EOS, b = buf, d = dname; b < &buf[PATHMAX]; b++, d++) 374 | if ((*b = (*d & ASCII)) == EOS) 375 | break; 376 | return (b >= &buf[PATHMAX]) ? NULL : opendir(buf); 377 | } 378 | -------------------------------------------------------------------------------- /goto.1: -------------------------------------------------------------------------------- 1 | .\" 2 | .\" Copyright (c) 2004-2014 3 | .\" Jeffrey Allen Neitzel . 4 | .\" All rights reserved. 5 | .\" 6 | .\" Redistribution and use in source and binary forms, with or without 7 | .\" modification, are permitted provided that the following conditions 8 | .\" are met: 9 | .\" 1. Redistributions of source code must retain the above copyright 10 | .\" notice, this list of conditions and the following disclaimer. 11 | .\" 2. Redistributions in binary form must reproduce the above copyright 12 | .\" notice, this list of conditions and the following disclaimer in the 13 | .\" documentation and/or other materials provided with the distribution. 14 | .\" 15 | .\" THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 16 | .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | .\" DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 19 | .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 | .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24 | .\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | .\" 26 | .\" @(#)$Id: d9f5deab98e90da8cc6791edf68407d35115a631 $ 27 | .\" 28 | .\" Derived from: Sixth Edition UNIX /usr/man/man1/goto.1 29 | .\" 30 | .\" Copyright (C) Caldera International Inc. 2001-2002. All rights reserved. 31 | .\" 32 | .\" Redistribution and use in source and binary forms, with or without 33 | .\" modification, are permitted provided that the following conditions 34 | .\" are met: 35 | .\" 1. Redistributions of source code and documentation must retain the above 36 | .\" copyright notice, this list of conditions and the following disclaimer. 37 | .\" 2. Redistributions in binary form must reproduce the above copyright 38 | .\" notice, this list of conditions and the following disclaimer in the 39 | .\" documentation and/or other materials provided with the distribution. 40 | .\" 3. All advertising materials mentioning features or use of this software 41 | .\" must display the following acknowledgement: 42 | .\" This product includes software developed or owned by Caldera 43 | .\" International, Inc. 44 | .\" 4. Neither the name of Caldera International, Inc. nor the names of other 45 | .\" contributors may be used to endorse or promote products derived from 46 | .\" this software without specific prior written permission. 47 | .\" 48 | .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 49 | .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 50 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 51 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 52 | .\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 53 | .\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 54 | .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 55 | .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 57 | .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 58 | .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 59 | .\" POSSIBILITY OF SUCH DAMAGE. 60 | .\" 61 | .TH GOTO 1 "@OSH_DATE@" "@OSH_VERSION@" "General Commands" 62 | .SH NAME 63 | goto \- transfer command 64 | .SH SYNOPSIS 65 | .B goto 66 | \fIlabel\fR [\fI...\fR] 67 | .SH DESCRIPTION 68 | .B Goto 69 | is allowed only when the shell is taking 70 | commands from a seekable command file (see 71 | .IR lseek (2)). 72 | .PP 73 | The entire command file is searched for a line beginning 74 | with a \fB:\fR as the first non-blank character, 75 | followed by one or more blanks, 76 | and then the 77 | .IR label . 78 | If such a line is found, 79 | .B goto 80 | repositions the command-file offset to 81 | the line after the label and exits. 82 | This causes the shell to transfer 83 | to the labelled line. 84 | .PP 85 | \fB:\fR is a special command which causes 86 | the shell to do nothing. 87 | .SH "EXIT STATUS" 88 | The 89 | .B goto 90 | command exits with one of the following values: 91 | .TP 92 | 0 93 | The label was found. 94 | .TP 95 | 1 96 | The label was not found. 97 | .TP 98 | 2 99 | An error was detected. 100 | .SH "SEE ALSO" 101 | if(1), 102 | osh(1), 103 | sh6(1) 104 | .PP 105 | Osh home page: 106 | http://v6shell.org/ 107 | .SH COMPATIBILITY 108 | The 109 | .B goto 110 | command from Sixth Edition UNIX 111 | requires \fB:\fR to be the first character 112 | on the labelled line. 113 | Otherwise, 114 | the label cannot be found. 115 | .PP 116 | This port differs in that \fB:\fR may be preceded by blanks. 117 | This allows labelled lines to be indented so that complex 118 | command files might be easier to read and understand. 119 | .SH HISTORY 120 | A 121 | .B goto 122 | command 123 | appeared as 124 | .I /bin/goto 125 | in Third Edition UNIX. 126 | .SH LICENSE 127 | See either the LICENSE file which is distributed with 128 | .B osh 129 | or 130 | http://v6shell.org/license/ 131 | for full details. 132 | .SH COPYRIGHT 133 | .nf 134 | Copyright (c) 2004-2014 135 | Jeffrey Allen Neitzel. All rights reserved. 136 | 137 | Copyright (c) 2001-2002 138 | Caldera International Inc. All rights reserved. 139 | .fi 140 | -------------------------------------------------------------------------------- /goto.c: -------------------------------------------------------------------------------- 1 | /* 2 | * goto.c - a port of the Sixth Edition (V6) UNIX transfer command 3 | */ 4 | /*- 5 | * Copyright (c) 2004-2014 6 | * Jeffrey Allen Neitzel . 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | * @(#)$Id: 6986396c095ada47817db743c29027710b0692a7 $ 30 | */ 31 | /* 32 | * Derived from: Sixth Edition UNIX /usr/source/s1/goto.c 33 | */ 34 | /*- 35 | * Copyright (C) Caldera International Inc. 2001-2002. All rights reserved. 36 | * 37 | * Redistribution and use in source and binary forms, with or without 38 | * modification, are permitted provided that the following conditions 39 | * are met: 40 | * 1. Redistributions of source code and documentation must retain the above 41 | * copyright notice, this list of conditions and the following disclaimer. 42 | * 2. Redistributions in binary form must reproduce the above copyright 43 | * notice, this list of conditions and the following disclaimer in the 44 | * documentation and/or other materials provided with the distribution. 45 | * 3. All advertising materials mentioning features or use of this software 46 | * must display the following acknowledgement: 47 | * This product includes software developed or owned by Caldera 48 | * International, Inc. 49 | * 4. Neither the name of Caldera International, Inc. nor the names of other 50 | * contributors may be used to endorse or promote products derived from 51 | * this software without specific prior written permission. 52 | * 53 | * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 54 | * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 55 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 56 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 57 | * IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, 58 | * INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 59 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 60 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 62 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 63 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 64 | * POSSIBILITY OF SUCH DAMAGE. 65 | */ 66 | 67 | #include "defs.h" 68 | #include "err.h" 69 | 70 | #ifndef CONFIG_SUNOS 71 | static off_t offset; 72 | #endif 73 | 74 | static bool getlabel(/*@out@*/ char *, int, size_t); 75 | static int xgetc(void); 76 | 77 | /* 78 | * NAME 79 | * goto - transfer command 80 | * 81 | * SYNOPSIS 82 | * goto label [...] 83 | * 84 | * DESCRIPTION 85 | * See the goto(1) manual page for full details. 86 | */ 87 | int 88 | main(int argc, char **argv) 89 | { 90 | size_t siz; 91 | char label[LABELMAX]; 92 | 93 | setmyerrexit(&ut_errexit); 94 | setmyname(argv[0]); 95 | setmypid(getpid()); 96 | 97 | if (argc < 2 || *argv[1] == EOS || isatty(FD0) != 0) 98 | err(FC_ERR, FMT2S, getmyname(), ERR_GENERIC); 99 | if ((siz = strlen(argv[1]) + 1) > sizeof(label)) 100 | err(FC_ERR, FMT3S, getmyname(), argv[1], ERR_LABTOOLONG); 101 | if (lseek(FD0, (off_t)0, SEEK_SET) == -1) 102 | err(FC_ERR, FMT2S, getmyname(), ERR_SEEK); 103 | 104 | while (getlabel(label, *argv[1] & 0377, siz)) 105 | if (strcmp(label, argv[1]) == 0) { 106 | #ifndef CONFIG_SUNOS 107 | (void)lseek(FD0, offset, SEEK_SET); 108 | #endif 109 | return SH_TRUE; 110 | } 111 | 112 | fd_print(FD2, FMT3S, getmyname(), argv[1], ERR_LABNOTFOUND); 113 | return SH_FALSE; 114 | } 115 | 116 | /* 117 | * Search for the first occurrence of a possible label with both 118 | * the same first character (fc) and the same length (siz - 1) 119 | * as argv[1], and copy this possible label to buf. 120 | * Return true (1) if possible label found. 121 | * Return false (0) at end-of-file. 122 | */ 123 | static bool 124 | getlabel(char *buf, int fc, size_t siz) 125 | { 126 | int c; 127 | char *b; 128 | 129 | while ((c = xgetc()) != EOF) { 130 | /* `:' may be preceded by blanks. */ 131 | while (c == SPACE || c == TAB) 132 | c = xgetc(); 133 | if (c != COLON) { 134 | while (c != EOL && c != EOF) 135 | c = xgetc(); 136 | continue; 137 | } 138 | 139 | /* Prepare for possible label. */ 140 | while ((c = xgetc()) == SPACE || c == TAB) 141 | ; /* nothing */ 142 | if (c != fc) /* not label */ 143 | continue; 144 | 145 | /* 146 | * Try to copy possible label (first word only) 147 | * to buf, ignoring it if it becomes too long. 148 | */ 149 | b = buf; 150 | do { 151 | if (c == EOL || c == SPACE || c == TAB || c == EOF) { 152 | *b = EOS; 153 | break; 154 | } 155 | *b = c; 156 | c = xgetc(); 157 | } while (++b < &buf[siz]); 158 | 159 | /* Ignore any remaining characters on labelled line. */ 160 | while (c != EOL && c != EOF) 161 | c = xgetc(); 162 | if (c == EOF) 163 | break; 164 | 165 | if ((size_t)(b - buf) != siz - 1) /* not label */ 166 | continue; 167 | return true; 168 | } 169 | 170 | *buf = EOS; 171 | return false; 172 | } 173 | 174 | /* 175 | * If not at end-of-file, return the next character from the standard 176 | * input as an unsigned char converted to an int while incrementing 177 | * the global offset. Otherwise, return EOF at end-of-file. 178 | */ 179 | static int 180 | xgetc(void) 181 | { 182 | #ifndef CONFIG_SUNOS 183 | int nc; 184 | 185 | offset++; 186 | nc = getchar(); 187 | return (nc != EOF) ? nc & 0377 : EOF; 188 | #else 189 | unsigned char nc; 190 | 191 | return (read(FD0, &nc, (size_t)1) == 1) ? nc : EOF; 192 | #endif 193 | } 194 | -------------------------------------------------------------------------------- /mkconfig: -------------------------------------------------------------------------------- 1 | #!/bin/sh - 2 | # 3 | # @(#)$Id: c0bfe3ef99498e37aaab239f7f2e7c85a48056e8 $ 4 | # 5 | # Write out an appropriate "config.h" file. 6 | # This script is invoked automatically from the Makefile. 7 | # Thus, the user does not need to run it manually. 8 | # 9 | # Exit w/ a status of 0 on success. 10 | # Exit w/ a status of 1 on error. 11 | # -- 12 | # Jeffrey Allen Neitzel 13 | # 14 | 15 | CONFIG_H="config.h" 16 | rm -f $CONFIG_H 17 | trap 'status=$? ; rm -f $CONFIG_H ; exit $status' HUP INT QUIT TERM 18 | 19 | # 20 | # This function searches for the pathname of utility and defines 21 | # constant w/ the resulting value. If utility cannot be found, 22 | # constant is defined as the empty string. 23 | # 24 | # usage: definePathnameConstant constant utility 25 | # 26 | definePathnameConstant() 27 | { 28 | const="$1" ; util="$2" 29 | dirlist="/bin /sbin /usr/bin /usr/sbin /usr/libexec /usr/games" 30 | moderr=" Modify value in \"$CONFIG_H\" if this is incorrect." 31 | modout=" /* Modify value if incorrect. */" 32 | for dir in $dirlist ; do 33 | if test -f "$dir/$util" -a -x "$dir/$util" ; then 34 | pname="$dir/$util" ; break 35 | else 36 | pname="" 37 | fi 38 | done 39 | 40 | #echo "$PATH" >&2 41 | wpname="`which $util /dev/null | grep -v 'not found'`" 42 | #echo "$wpname" >&2 43 | if test X"$pname" != X -a \( \ 44 | X"$wpname" = X -o X"$wpname" = X"$pname" \ 45 | \) ; then 46 | (echo "$PROGNAME: $const == \"$pname\"";echo "$moderr") >&2 47 | def="#define $const \"$pname\"$modout" 48 | elif test X"$wpname" != X ; then 49 | (echo "$PROGNAME: $const == \"$wpname\"";echo "$moderr") >&2 50 | def="#define $const \"$wpname\"$modout" 51 | else 52 | # This should rarely be true, but it is possible. 53 | (echo "$PROGNAME: $const == \"\"";echo "$moderr") >&2 54 | def="#define $const \"\"$modout" 55 | fi 56 | 57 | echo "$def" 58 | } 59 | 60 | UNAME_S="`uname -s`" 61 | UNAME_SRM="`uname -srm`" 62 | PROGNAME="`basename $0`" 63 | if test $# -ne 0 ; then echo 'usage: $(SHELL) ./'"$PROGNAME" >&2 ; exit 1 ; fi 64 | if test X"$UNAME_S" = X -o X"$UNAME_SRM" = X ; then 65 | echo "$PROGNAME: Fatal uname(1) error" >&2 ; exit 1 66 | fi 67 | 68 | cat <$CONFIG_H 69 | /* 70 | * osh - an enhanced port of the Sixth Edition (V6) UNIX Thompson shell 71 | */ 72 | /* 73 | * _XOPEN_SOURCE and/or _BSD_SOURCE should be defined only if needed 74 | * to avoid compilation errors or warnings for the osh package on a 75 | * given system. The systems where these feature test macros are 76 | * (known to be) needed are defined in the mkconfig script. 77 | * 78 | * This includes only Linux and SunOS (Solaris/OpenSolaris) 79 | * at the present time. 80 | * 81 | * Configured for: $UNAME_SRM 82 | */ 83 | 84 | #ifndef CONFIG_H 85 | #define CONFIG_H 86 | 87 | `definePathnameConstant PATH_LOGIN login` 88 | `definePathnameConstant PATH_NEWGRP newgrp` 89 | #define OSH_UNAME_SRM "$UNAME_SRM" 90 | 91 | EOI 92 | 93 | case "$UNAME_S" in 94 | *BSD|Darwin|DragonFly) 95 | echo "/* $UNAME_S: No need for _XOPEN_SOURCE or _BSD_SOURCE */" \ 96 | >>$CONFIG_H 97 | ;; 98 | Linux) 99 | echo '#define _XOPEN_SOURCE 600L' >>$CONFIG_H 100 | echo '#define _BSD_SOURCE' >>$CONFIG_H 101 | ;; 102 | SunOS) 103 | ( echo '#define CONFIG_SUNOS' ; echo ) >>$CONFIG_H 104 | echo '#define _XOPEN_SOURCE 600L' >>$CONFIG_H 105 | ;; 106 | *) 107 | # 108 | # This may or may not cause a compilation error. 109 | # Simply try it to see if it works or not. 110 | # 111 | echo "$PROGNAME: WARNING: Check \"$CONFIG_H\" if compilation fails." >&2 112 | cat <>$CONFIG_H 113 | /* 114 | * WARNING: $UNAME_SRM: Unknown system 115 | * 116 | * Please report this result to the developer if possible. 117 | */ 118 | EOI 119 | ;; 120 | esac 121 | 122 | echo >>$CONFIG_H 123 | echo '#endif /* !CONFIG_H */' >>$CONFIG_H 124 | -------------------------------------------------------------------------------- /pexec.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2005-2014 3 | * Jeffrey Allen Neitzel . 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * @(#)$Id: 85d77cf4bea8e3dd1c6b63b5323c03f0279840cf $ 27 | */ 28 | /* 29 | * Derived from: 30 | * - /usr/src/lib/libc/gen/execvp.c: 31 | * $NetBSD: execvp.c,v 1.24 2003/08/07 16:42:47 agc Exp $ 32 | */ 33 | /*- 34 | * Copyright (c) 1991, 1993 35 | * The Regents of the University of California. All rights reserved. 36 | * 37 | * Redistribution and use in source and binary forms, with or without 38 | * modification, are permitted provided that the following conditions 39 | * are met: 40 | * 1. Redistributions of source code must retain the above copyright 41 | * notice, this list of conditions and the following disclaimer. 42 | * 2. Redistributions in binary form must reproduce the above copyright 43 | * notice, this list of conditions and the following disclaimer in the 44 | * documentation and/or other materials provided with the distribution. 45 | * 3. Neither the name of the University nor the names of its contributors 46 | * may be used to endorse or promote products derived from this software 47 | * without specific prior written permission. 48 | * 49 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 | * SUCH DAMAGE. 60 | * 61 | * @(#)exec.c 8.1 (Berkeley) 6/4/93 62 | */ 63 | 64 | #include "defs.h" 65 | #include "err.h" 66 | #include "pexec.h" 67 | 68 | extern char **environ; 69 | 70 | /* 71 | * Execute a file or path name. 72 | */ 73 | int 74 | pexec(const char *file, char *const *argv) 75 | { 76 | const char **esh_argv; 77 | size_t dlen, flen; 78 | int cnt, eacces = 0; 79 | const char *d, *esh, *f, *pnp, *upp; 80 | char pnbuf[PATHMAX]; 81 | 82 | /* 83 | * Fail if the value of file, argv, or argv[0] is invalid. 84 | */ 85 | errno = 0; 86 | if (file == NULL || argv == NULL || argv[0] == NULL) { 87 | errno = EINVAL; 88 | goto fail; 89 | } 90 | if (*file == EOS || *argv[0] == EOS) 91 | goto fail; 92 | flen = strlen(file); 93 | 94 | /* 95 | * If the name of the specified file contains one or more 96 | * `/' characters, it is used as the path name to execute. 97 | */ 98 | for (f = file; *f != EOS; f++) 99 | if (*f == SLASH) { 100 | pnp = file; 101 | upp = ""; 102 | goto exec_pathname; 103 | } 104 | *pnbuf = EOS; 105 | pnp = pnbuf; 106 | 107 | /* 108 | * Get the user's PATH. Fail if PATH is unset or is 109 | * set to the empty string, as no PATH search shall be 110 | * performed in such a case. 111 | */ 112 | upp = getenv("PATH"); 113 | if (upp == NULL || *upp == EOS) 114 | goto fail; 115 | 116 | do { 117 | /* Find the end of this PATH element. */ 118 | for (d = upp; *upp != COLON && *upp != EOS; upp++) 119 | ; /* nothing */ 120 | /* 121 | * Since this is a shell PATH, double, leading, and/or 122 | * trailing colons indicate the current directory. 123 | */ 124 | if (d == upp) { 125 | d = "."; 126 | dlen = 1; 127 | } else 128 | dlen = (size_t)(upp - d); 129 | 130 | /* 131 | * Complain if this path name for file would be too long. 132 | * Otherwise, use this PATH element to build a possible 133 | * path name for file. Then, attempt to execve(2) it. 134 | */ 135 | if (dlen + flen + 1 >= sizeof(pnbuf)) { 136 | struct iovec msg[3]; 137 | msg[0].iov_base = "pexec: "; 138 | msg[0].iov_len = (size_t)7; 139 | msg[1].iov_base = (char *)d; 140 | msg[1].iov_len = dlen; 141 | msg[2].iov_base = ": path too long\n"; 142 | msg[2].iov_len = (size_t)16; 143 | (void)writev(FD2, msg, 3); 144 | errno = ENAMETOOLONG; 145 | continue; 146 | } 147 | (void)memcpy(pnbuf, d, dlen); 148 | pnbuf[dlen] = SLASH; 149 | (void)memcpy(pnbuf + dlen + 1, file, flen); 150 | pnbuf[dlen + flen + 1] = EOS; 151 | 152 | exec_pathname: 153 | (void)execve(pnp, argv, environ); 154 | switch (errno) { 155 | case EACCES: 156 | #if defined(__OpenBSD__) 157 | case EISDIR: /* Treat it as an EACCES error. */ 158 | #endif 159 | eacces = 1; 160 | /*FALLTHROUGH*/ 161 | case ELOOP: 162 | case ENAMETOOLONG: 163 | case ENOENT: 164 | case ENOTDIR: 165 | break; 166 | case ENOEXEC: 167 | /* 168 | * Get the user's EXECSHELL. 169 | * Fail if it is unset or is set to an unusable value. 170 | */ 171 | esh = getenv("EXECSHELL"); 172 | if (esh==NULL||*esh==EOS||strlen(esh)>=sizeof(pnbuf)) 173 | goto fail; 174 | for (cnt = 0; argv[cnt] != NULL; cnt++) 175 | ; /* nothing */ 176 | esh_argv = malloc((cnt + 2) * sizeof(char *)); 177 | if (esh_argv == NULL) 178 | goto fail; 179 | esh_argv[0] = esh; 180 | esh_argv[1] = pnp; 181 | (void)memcpy(&esh_argv[2],&argv[1],cnt*sizeof(char *)); 182 | (void)execve(esh, (char *const *)esh_argv, environ); 183 | free(esh_argv); 184 | errno = (errno == E2BIG) ? E2BIG : ENOEXEC; 185 | /*FALLTHROUGH*/ 186 | default: 187 | goto fail; 188 | } 189 | } while (*upp++ == COLON); /* Otherwise, *upp was NUL. */ 190 | if (eacces != 0) 191 | errno = EACCES; 192 | 193 | fail: 194 | if (errno == 0) 195 | errno = ENOENT; 196 | return -1; 197 | } 198 | 199 | extern const char *name; 200 | extern bool no_lnum; 201 | 202 | /* 203 | * Execute a file or path name w/ error handling. 204 | * This function never returns. 205 | */ 206 | void 207 | err_pexec(const char *file, char *const *argv) 208 | { 209 | long l; 210 | const char *f, *n; 211 | 212 | (void)pexec(file, argv); 213 | #ifdef DEBUG 214 | fd_print(FD2, "err_pexec: strerror(errno) == %s;\n", strerror(errno)); 215 | #endif 216 | 217 | f = (file == NULL) ? "(null)" : file; 218 | n = getmyname(); 219 | 220 | if (EQUAL(n, "glob6")) { 221 | if (errno == ENOEXEC) 222 | err(SH_ERR, FMT1S, ERR_NOSHELL); 223 | if (errno == E2BIG) 224 | err(SH_ERR, FMT1S, ERR_E2BIG); 225 | err(SH_ERR, FMT1S, ERR_GNOTFOUND); 226 | } else if (EQUAL(n, "sh6")) { 227 | if (errno == ENOEXEC) 228 | err(125, FMT1S, ERR_NOSHELL); 229 | if (errno == E2BIG) 230 | err(126, FMT2S, f, ERR_E2BIG); 231 | if (errno != ENOENT && errno != ENOTDIR) 232 | err(126, FMT2S, f, ERR_EXEC); 233 | err(127, FMT2S, f, ERR_NOTFOUND); 234 | } else { 235 | l = no_lnum ? -1 : get_lnum(); 236 | if (name != NULL) { 237 | if (l != -1) { 238 | if (errno == ENOEXEC) 239 | err(125,FMT4LS,n,name,l,f, ERR_NOSHELL); 240 | if (errno == E2BIG) 241 | err(126,FMT4LS,n,name, l, f, ERR_E2BIG); 242 | if (errno != ENOENT && errno != ENOTDIR) 243 | err(126,FMT4LS,n, name, l, f, ERR_EXEC); 244 | err(127, FMT4LS, n, name, l, f, ERR_NOTFOUND); 245 | } else { 246 | if (errno == ENOEXEC) 247 | err(125,FMT4S, n, name, f, ERR_NOSHELL); 248 | if (errno == E2BIG) 249 | err(126, FMT4S, n, name, f, ERR_E2BIG); 250 | if (errno != ENOENT && errno != ENOTDIR) 251 | err(126, FMT4S, n, name, f, ERR_EXEC); 252 | err(127, FMT4S, n, name, f, ERR_NOTFOUND); 253 | } 254 | } else { 255 | if (l != -1) { 256 | if (errno == ENOEXEC) 257 | err(125, FMT3LFS, n, l, f, ERR_NOSHELL); 258 | if (errno == E2BIG) 259 | err(126, FMT3LFS, n, l, f, ERR_E2BIG); 260 | if (errno != ENOENT && errno != ENOTDIR) 261 | err(126, FMT3LFS, n, l, f, ERR_EXEC); 262 | err(127, FMT3LFS, n, l, f, ERR_NOTFOUND); 263 | } else { 264 | if (errno == ENOEXEC) 265 | err(125, FMT3S, n, f, ERR_NOSHELL); 266 | if (errno == E2BIG) 267 | err(126, FMT3S, n, f, ERR_E2BIG); 268 | if (errno != ENOENT && errno != ENOTDIR) 269 | err(126, FMT3S, n, f, ERR_EXEC); 270 | err(127, FMT3S, n, f, ERR_NOTFOUND); 271 | } 272 | } 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /pexec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * osh - an enhanced port of the Sixth Edition (V6) UNIX Thompson shell 3 | */ 4 | /*- 5 | * Copyright (c) 2005-2014 6 | * Jeffrey Allen Neitzel . 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | * @(#)$Id: 84ed4da87bfd18d85f0fe2e6af2d15c456d6a0cb $ 30 | */ 31 | 32 | #ifndef PEXEC_H 33 | #define PEXEC_H 34 | 35 | /* 36 | * NAME 37 | * pexec - execute a file or path name 38 | * 39 | * SYNOPSIS 40 | * #include "pexec.h" 41 | * 42 | * extern char **environ; 43 | * 44 | * int 45 | * pexec(const char *file, char *const argv[]); 46 | * 47 | * DESCRIPTION 48 | * The pexec() function replaces the current process with a new process 49 | * by calling execve(2). The file argument specifies a file or path name 50 | * to execute. The argv argument is a pointer to a NULL-terminated array 51 | * of pointers to `\0'-terminated strings, which specifies the argument 52 | * list for the new process. 53 | * 54 | * If the name of the specified file contains one or more `/' characters, 55 | * it is used as the path name to execute. 56 | * 57 | * Otherwise, a path search is performed. The environment variable PATH 58 | * specifies the search path to be used. The search builds a sequence of 59 | * possible path names for the specified file, attempting to execve(2) 60 | * each one until success or failure. The search continues on any of 61 | * the following errors if PATH is not yet exhausted: 62 | * 63 | * EACCES, EISDIR (OpenBSD), ELOOP, ENAMETOOLONG, ENOENT, ENOTDIR 64 | * 65 | * If an EACCES, or EISDIR (OpenBSD), error occurs during the search 66 | * and if no other executable file is found, pexec() sets errno to 67 | * EACCES upon failure. The search ceases immediately on any error 68 | * not mentioned above (except ENOEXEC), or when PATH is exhausted. 69 | * 70 | * If execve(2) fails and sets errno to ENOEXEC, pexec() attempts to 71 | * execute the path name with the shell specified by the environment 72 | * variable EXECSHELL. If this attempt fails, pexec() also fails. 73 | * 74 | * Notice that if PATH is unset or is set to the empty string, the 75 | * name of the specified file must contain one or more `/' characters 76 | * in order to be executed. Otherwise, pexec() shall fail. 77 | * 78 | * Notice also that if EXECSHELL is unset or is set to the empty 79 | * string, pexec() shall make no attempt to execute the specified 80 | * file with any shell. Instead, pexec() shall fail. 81 | * 82 | * RETURN VALUES 83 | * On success, pexec() does not return. Otherwise, it returns 84 | * a value of -1 and sets errno according to the error. 85 | * 86 | * ERRORS 87 | * Possible errno values set by pexec() shall correspond to those 88 | * set by execve(2), with the following special exceptions: 89 | * 90 | * EINVAL The value of file, argv, or argv[0] is NULL. 91 | * 92 | * ENOEXEC The file argument specifies an executable file 93 | * which does not begin with the proper magic number. 94 | * At the same time, the value of EXECSHELL is unset, 95 | * is set to the empty string, or is set to another 96 | * unusable value which causes execve(2) to fail. 97 | */ 98 | 99 | /*@maynotreturn@*/ 100 | int pexec(/*@null@*/ const char *, /*@null@*/ char *const *); 101 | 102 | /* 103 | * NAME 104 | * err_pexec - execute a file or path name w/ error handling 105 | * 106 | * SYNOPSIS 107 | * #include "pexec.h" 108 | * 109 | * extern const char *name; 110 | * extern bool no_lnum; 111 | * 112 | * void 113 | * err_pexec(const char *file, char *const argv[]); 114 | */ 115 | 116 | /*@noreturn@*/ 117 | void err_pexec(/*@null@*/ const char *, /*@null@*/ char *const *); 118 | 119 | #endif /* !PEXEC_H */ 120 | -------------------------------------------------------------------------------- /sasignal.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2008-2014 3 | * Jeffrey Allen Neitzel . 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * @(#)$Id: 6d72084614aa4507fbf33c3baad901ea3105c2ed $ 27 | */ 28 | /* 29 | * Derived from: 30 | * - /usr/src/lib/libc/gen/signal.c: 31 | * $OpenBSD: signal.c,v 1.7 2005/08/08 08:05:34 espie Exp $ 32 | */ 33 | /*- 34 | * Copyright (c) 1985, 1989, 1993 35 | * The Regents of the University of California. All rights reserved. 36 | * 37 | * Redistribution and use in source and binary forms, with or without 38 | * modification, are permitted provided that the following conditions 39 | * are met: 40 | * 1. Redistributions of source code must retain the above copyright 41 | * notice, this list of conditions and the following disclaimer. 42 | * 2. Redistributions in binary form must reproduce the above copyright 43 | * notice, this list of conditions and the following disclaimer in the 44 | * documentation and/or other materials provided with the distribution. 45 | * 3. Neither the name of the University nor the names of its contributors 46 | * may be used to endorse or promote products derived from this software 47 | * without specific prior written permission. 48 | * 49 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 | * SUCH DAMAGE. 60 | */ 61 | 62 | #include "defs.h" 63 | #include "sasignal.h" 64 | 65 | action_type 66 | sasignal(int sig, action_type act) 67 | { 68 | struct sigaction a, oa; 69 | 70 | (void)memset(&a, 0, sizeof(a)); 71 | (void)sigemptyset(&a.sa_mask); 72 | (void)sigaddset(&a.sa_mask, sig); 73 | 74 | a.sa_handler = act; 75 | a.sa_flags = SA_RESTART; 76 | 77 | if (sigaction(sig, &a, &oa) < 0) 78 | return SIG_ERR; 79 | 80 | return oa.sa_handler; 81 | } 82 | -------------------------------------------------------------------------------- /sasignal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * osh - an enhanced port of the Sixth Edition (V6) UNIX Thompson shell 3 | */ 4 | /*- 5 | * Copyright (c) 2008-2014 6 | * Jeffrey Allen Neitzel . 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | * @(#)$Id: 596efc130c368ea376f8e5ed1d455c8054b5c930 $ 30 | */ 31 | 32 | #ifndef SASIGNAL_H 33 | #define SASIGNAL_H 34 | 35 | /* 36 | * required header files 37 | */ 38 | #include 39 | 40 | /* 41 | * The sasignal() function is a signal() with BSD-like semantics. 42 | * On success, sasignal() returns the previous action. Otherwise, 43 | * it returns SIG_ERR and sets errno according to the error. 44 | */ 45 | 46 | typedef void (*action_type)(int); /* signal action type */ 47 | 48 | action_type sasignal(int, action_type); 49 | 50 | #endif /* !SASIGNAL_H */ 51 | -------------------------------------------------------------------------------- /sh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * osh - an enhanced port of the Sixth Edition (V6) UNIX Thompson shell 3 | */ 4 | /*- 5 | * Copyright (c) 2004-2014 6 | * Jeffrey Allen Neitzel . 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | * @(#)$Id: e1dde18eb3d9765a430099ca0e3838b896cf5429 $ 30 | */ 31 | 32 | #ifndef SH_H 33 | #define SH_H 34 | 35 | /* 36 | * signal flags 37 | */ 38 | enum sigflags { 39 | S_SIGINT = 01, 40 | S_SIGQUIT = 02, 41 | S_SIGTERM = 04 42 | }; 43 | 44 | #ifdef OSH_SHELL 45 | /* 46 | * shell special built-in (sbi) command keys 47 | */ 48 | enum sbikey { 49 | SBI_NULL, SBI_ALIAS, SBI_CD, SBI_CHDIR, SBI_ECHO, 50 | SBI_EXEC, SBI_EXIT, SBI_FD2, SBI_GOTO, SBI_IF, 51 | SBI_LOGIN, SBI_NEWGRP, SBI_SET, SBI_SETENV, SBI_SHIFT, 52 | SBI_DOT, SBI_SOURCE, SBI_TRAP, SBI_UMASK, SBI_UNALIAS, 53 | SBI_UNSET, SBI_UNSETENV, SBI_VERSION, SBI_WAIT, SBI_UNKNOWN 54 | }; 55 | 56 | #define IS_VARNAME(v) (((*(v) >= 'A' && *(v) <= 'Z') || (*(v) >= 'a' && *(v) <= 'z')) && !any(*(v), "#$*?0123456789dehmptuv") && *((v) + 1) == EOS) 57 | 58 | /* 59 | * shell variable node structure 60 | */ 61 | struct vnode { 62 | /*@null@*/ /*@only@*/ 63 | struct vnode *next; /* Pointer to next variable node. */ 64 | int name; /* This variable name (one ASCII char). */ 65 | /*@only@*/ 66 | char *value; /* Pointer to this variable value. */ 67 | }; 68 | 69 | /* 70 | * shell alias node structure 71 | */ 72 | struct anode { 73 | /*@null@*/ /*@only@*/ 74 | struct anode *next; /* Pointer to next alias node. */ 75 | /*@only@*/ 76 | char *name; /* Pointer to this alias name. */ 77 | /*@only@*/ 78 | char *string;/* Pointer to this alias string. */ 79 | }; 80 | #endif 81 | 82 | /* 83 | * shell command tree node flags 84 | */ 85 | enum tnflags { 86 | FAND = 0001, /* A `&' designates asynchronous execution. */ 87 | FCAT = 0002, /* A `>>' appends output to file. */ 88 | FFIN = 0004, /* A `<' redirects input from file. */ 89 | FPIN = 0010, /* A `|' or `^' redirects input from pipe. */ 90 | FPOUT = 0020, /* A `|' or `^' redirects output to pipe. */ 91 | FNOFORK = 0040, /* No fork(2) for last command in `( list )'. */ 92 | FINTR = 0100, /* Child process ignores SIGINT and SIGQUIT. */ 93 | FPRS = 0200 /* Print process ID of child as a string. */ 94 | }; 95 | 96 | /* 97 | * shell command tree node structure 98 | */ 99 | struct tnode { 100 | /*@null@*/ /*@only@*/ 101 | struct tnode *nleft; /* Pointer to left node. */ 102 | /*@null@*/ /*@only@*/ 103 | struct tnode *nright; /* Pointer to right node. */ 104 | /*@null@*/ /*@only@*/ 105 | struct tnode *nsub; /* Pointer to TSUBSHELL node. */ 106 | /*@null@*/ /*@only@*/ 107 | char *nfin; /* Pointer to input file (<). */ 108 | /*@null@*/ /*@only@*/ 109 | char *nfout; /* Pointer to output file (>, >>). */ 110 | /*@null@*/ /*@only@*/ 111 | char **nav; /* Argument vector for TCOMMAND. */ 112 | #ifdef OSH_SHELL 113 | enum sbikey nkey; /* Shell sbi command key. */ 114 | #endif 115 | enum tnflags nflags; /* Shell command tree node flags. */ 116 | enum { /* Shell command tree node type. */ 117 | TLIST = 1, /* pipelines separated by `;', `&', or `\n' */ 118 | TPIPE = 2, /* commands separated by `|' or `^' */ 119 | TCOMMAND = 3, /* command [arg ...] [< in] [> [>] out] */ 120 | TSUBSHELL = 4 /* ( list ) [< in] [> [>] out] */ 121 | } ntype; 122 | }; 123 | 124 | #ifdef OSH_SHELL 125 | /* osh.c */ 126 | extern uid_t sheuid; /* effective shell user ID */ 127 | 128 | enum sbikey cmd_lookup(const char *); 129 | 130 | /* util.c */ 131 | /*@maynotreturn@*/ 132 | int uexec(enum sbikey, int, char **); 133 | #endif 134 | 135 | #endif /* !SH_H */ 136 | -------------------------------------------------------------------------------- /strtoint.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2008-2014 3 | * Jeffrey Allen Neitzel . 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * @(#)$Id: a3c933f7fb9b46f087114b42e977b8824aa1b19c $ 27 | */ 28 | /* 29 | * Derived from: 30 | * - /usr/src/lib/libc/stdlib/strtol.3 31 | * $NetBSD: strtol.3,v 1.22 2003/09/08 17:54:33 wiz Exp $ 32 | */ 33 | /*- 34 | * Copyright (c) 1990, 1991, 1993 35 | * The Regents of the University of California. All rights reserved. 36 | * 37 | * This code is derived from software contributed to Berkeley by 38 | * Chris Torek and the American National Standards Committee X3, 39 | * on Information Processing Systems. 40 | * 41 | * Redistribution and use in source and binary forms, with or without 42 | * modification, are permitted provided that the following conditions 43 | * are met: 44 | * 1. Redistributions of source code must retain the above copyright 45 | * notice, this list of conditions and the following disclaimer. 46 | * 2. Redistributions in binary form must reproduce the above copyright 47 | * notice, this list of conditions and the following disclaimer in the 48 | * documentation and/or other materials provided with the distribution. 49 | * 3. Neither the name of the University nor the names of its contributors 50 | * may be used to endorse or promote products derived from this software 51 | * without specific prior written permission. 52 | * 53 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 54 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 | * SUCH DAMAGE. 64 | * 65 | * @(#)strtol.3 8.1 (Berkeley) 6/4/93 66 | */ 67 | 68 | #include "defs.h" 69 | #include "err.h" 70 | #include "strtoint.h" 71 | 72 | /* 73 | * Convert a string value into an int integer value. 74 | */ 75 | bool 76 | strtoint(const char *string, int *integer) 77 | { 78 | long lint; 79 | char *lintbad; 80 | const char *name; 81 | 82 | name = getmyname(); 83 | 84 | /* 85 | * Fail if the specified string or integer is (or points to) NULL. 86 | */ 87 | errno = 0; 88 | if (string == NULL || integer == NULL) { 89 | errno = EINVAL; 90 | fd_print(FD2, FMT3S, name, "strtoint", strerror(errno)); 91 | if (integer != NULL) 92 | *integer = 0; 93 | return false; 94 | } 95 | 96 | lint = strtol(string, &lintbad, 10); 97 | if (*string == EOS || *lintbad != EOS) { 98 | errno = EINVAL; 99 | if (EQUAL(name, "if")) 100 | fd_print(FD2, FMT3S, name, string, ERR_NOTINTEGER); 101 | *integer = 0; 102 | return false; 103 | } 104 | if ((errno == ERANGE && (lint == LONG_MAX || lint == LONG_MIN)) || 105 | (lint > INT_MAX || lint < INT_MIN)) { 106 | errno = ERANGE; 107 | if (EQUAL(name, "if")) 108 | fd_print(FD2, FMT3S, name, string, ERR_RANGE); 109 | *integer = 0; 110 | return false; 111 | } 112 | *integer = (int)lint; 113 | return true; 114 | } 115 | -------------------------------------------------------------------------------- /strtoint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * osh - an enhanced port of the Sixth Edition (V6) UNIX Thompson shell 3 | */ 4 | /*- 5 | * Copyright (c) 2008-2014 6 | * Jeffrey Allen Neitzel . 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | * @(#)$Id: 40c30a8efeae0fa002492ef7294b0d97b92eb9e2 $ 30 | */ 31 | 32 | #ifndef STRTOINT_H 33 | #define STRTOINT_H 34 | 35 | /* 36 | * NAME 37 | * strtoint - convert a string value into an int integer value 38 | * 39 | * SYNOPSIS 40 | * #include "strtoint.h" 41 | * 42 | * bool 43 | * strtoint(const char *string, int *integer); 44 | * 45 | * DESCRIPTION 46 | * The strtoint() function converts the specified string into a 47 | * decimal integer value of type int. It assigns the converted 48 | * value to the storage pointed to by the specified integer. 49 | * 50 | * RETURN VALUES 51 | * On success, strtoint() returns true with the converted int 52 | * integer value assigned to the storage pointed to by integer. 53 | * On error, it returns false with 0 assigned to the storage 54 | * pointed to by integer and sets errno according to the error. 55 | * 56 | * ERRORS 57 | * EINVAL The specified string is NULL, empty, 58 | * or cannot be converted by strtol(3). 59 | * 60 | * EINVAL The specified integer is NULL. 61 | * 62 | * ERANGE The specified string is out of range. 63 | */ 64 | 65 | bool strtoint(/*@null@*/ const char *, /*@null@*/ /*@out@*/ int *); 66 | 67 | #endif /* !STRTOINT_H */ 68 | -------------------------------------------------------------------------------- /tests/LICENSE: -------------------------------------------------------------------------------- 1 | =================================================================== 2 | 3 | The files in this directory are hereby granted to the public domain 4 | by the author, Jeffrey Allen Neitzel . 5 | 6 | === 7 | 8 | Jeffrey Allen Neitzel 2013/11/09 9 | 10 | @(#)$Id: 55aa7f4cd8dbc0b8fa65bc5b75a3b5a2d7386253 $ 11 | -------------------------------------------------------------------------------- /tests/README: -------------------------------------------------------------------------------- 1 | Welcome to Osh (V6Shell) Regression Tests! 2 | 3 | ------- 4 | 5 | NAME 6 | run.osh - run regression test suite with osh and sh6 7 | 8 | SYNOPSIS 9 | ../osh run.osh [-newlog] osh sh6 10 | 11 | DESCRIPTION 12 | ... 13 | 14 | EXIT STATUS 15 | The run.osh script exits with a zero status (true) when 16 | all tests pass. It exits with a non-zero status (false) 17 | when any tests fail. 18 | 19 | ------- 20 | 21 | If you have any comments or questions about this software, I encourage 22 | you to contact me via email. Thanks & Enjoy! 23 | 24 | Jeffrey Allen Neitzel 25 | 26 | http://v6shell.org/regression_tests 2013/01/13 27 | 28 | @(#)$Id: c193be8302fa7438dd2f353d63f3558202ddecb9 $ 29 | -------------------------------------------------------------------------------- /tests/bin/now: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh6 2 | : 3 | : sh6 - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; 4 | : 5 | : " The author of this file, J.A. Neitzel , " 6 | : " hereby grants it to the public domain. " 7 | : 8 | 9 | : 10 | : " Print the date and time in a nice ISO-like format. " 11 | : 12 | : " usage: now " 13 | : 14 | 15 | date '+%A, %Y-%m-%d, %T %Z' 16 | -------------------------------------------------------------------------------- /tests/input: -------------------------------------------------------------------------------- 1 | Hello World! =) 2 | -------------------------------------------------------------------------------- /tests/run.osh: -------------------------------------------------------------------------------- 1 | : osh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/regression_tests " 7 | : 8 | 9 | : 10 | : " Exit w/ zero status (true) when all tests pass. " 11 | : " Exit w/ non-zero status (false) when any tests fail. " 12 | : 13 | : " usage: ../osh run.osh [-newlog] osh sh6 " 14 | : 15 | 16 | : >>$0'' <'' ; : >>$1'' <'' ; : >>$2'' <'' ; : >>$3'' <'' 17 | 18 | if X$u = Xroot if { fd2 -e echo Cannot run tests as superuser } \ 19 | if { exit } if A = B 20 | if X$0 != Xrun.osh -a X$0 != X./run.osh if { fd2 -e echo Wrong directory } \ 21 | if { exit } if A = B 22 | if $# = # if { fd2 -e echo Invalid shell - osh\(1\) required } \ 23 | if { exit } if A = B 24 | 25 | trap '' 1 2 3 13 15 ; : trap 26 | setenv PATH ..:./bin:$p ; : printenv PATH 27 | umask 22 ; : umask 28 | rm -f TestFailCount TestPassCount syntax_error 29 | ( : ) >TestFailCount ; ( : ) >TestPassCount 30 | 31 | if $# = 3 -a X$1 = X-newlog -a X$2 = Xosh -a X$3 = Xsh6 goto NewLog 32 | 33 | : Again - " Check for correct usage and/or test other binary. " 34 | 35 | if ! \( \( $# = 1 -o $# = 2 \) -a \( X$1 = Xosh -o X$1 = Xsh6 \) \) \ 36 | if { fd2 -e echo usage: ../osh run.osh \[-newlog\] osh sh6 } \ 37 | if { exit } if A = B 38 | : fallthrough 39 | 40 | : NewLog - " Generate new test logs if needed. " 41 | 42 | if X$1 != X-newlog goto BinCheck 43 | rm -f test0[1-8]_[os][sh][h6].log 44 | fd2 $2 test01 >test01_$2.log ; fd2 $3 test01 >test01_$3.log 45 | fd2 $2 test02 >test02_$2.log ; fd2 $3 test02 >test02_$3.log 46 | fd2 $2 test03 >test03_$2.log ; fd2 $3 test03 >test03_$3.log 47 | fd2 -f/dev/null $2 test04 >test04_$2.log 48 | fd2 -f/dev/null $3 test04 >test04_$3.log 49 | fd2 $2 test05 $2 >test05_$2.log ; fd2 $3 test05 $3 >test05_$3.log 50 | rm -f syntax_error 51 | fd2 $2 test08 >test08_$2.log ; fd2 $3 test08 >test08_$3.log 52 | ( : ) >test06_$2.log ; ( : ) >test07_$2.log 53 | fd2 $2 test06 >test06_$2.log 54 | fd2 $2 test07 >test07_$2.log 55 | shift 56 | : fallthrough 57 | 58 | : BinCheck - " Ensure that needed binaries are present and executable. " 59 | 60 | if ! -x ../$1 if { fd2 -e echo $1: Missing or not executable } \ 61 | if { exit } if A = B 62 | if X$1 = Xosh goto Jump 63 | if ! -x ../glob6 if { fd2 -e echo glob6: Missing or not executable } \ 64 | if { exit } if A = B 65 | if ! -x ../if if { fd2 -e echo if: Missing or not executable } \ 66 | if { exit } if A = B 67 | if ! -x ../goto if { fd2 -e echo goto: Missing or not executable } \ 68 | if { exit } if A = B 69 | if ! -x ../fd2 if { fd2 -e echo fd2: Missing or not executable } \ 70 | if { exit } if A = B 71 | : which sh6 glob6 if goto fd2 72 | goto Run 73 | : Jump 74 | : which osh 75 | : fallthrough 76 | 77 | : Run - " Run appropriate tests w/ $1 binary. " 78 | 79 | if $# = 2 fd2 -e -- now 80 | fd2 -e -- echo -n Testing $1 binary\ 81 | fd2 $1 test01 | diff -u test01_$1.log - 82 | if $? != 0 if { fd2 -e echo $1: Test 1 Failed } echo >>TestFailCount 83 | echo >>TestPassCount 84 | fd2 -e -- echo -n .\ 85 | fd2 $1 test02 | diff -u test02_$1.log - 86 | if $? != 0 if { fd2 -e echo $1: Test 2 Failed } echo >>TestFailCount 87 | echo >>TestPassCount 88 | fd2 -e -- echo -n .\ 89 | fd2 $1 test03 | diff -u test03_$1.log - 90 | if $? != 0 if { fd2 -e echo $1: Test 3 Failed } echo >>TestFailCount 91 | echo >>TestPassCount 92 | fd2 -e -- echo -n .\ 93 | fd2 -f/dev/null $1 test04 | diff -u test04_$1.log - 94 | if $? != 0 if { fd2 -e echo $1: Test 4 Failed } echo >>TestFailCount 95 | echo >>TestPassCount 96 | fd2 -e -- echo -n .\ 97 | fd2 $1 test05 $1 | diff -u test05_$1.log - 98 | if $? != 0 if { fd2 -e echo $1: Test 5 Failed } echo >>TestFailCount 99 | echo >>TestPassCount 100 | fd2 -e -- echo -n .\ 101 | if X$1 = Xsh6 goto Next 102 | : " Tests 6 and 7 are for osh only. " 103 | rm -f syntax_error 104 | fd2 $1 test06 | diff -u test06_$1.log - 105 | if $? != 0 if { fd2 -e echo $1: Test 6 Failed } \ 106 | echo >>TestFailCount 107 | echo >>TestPassCount 108 | fd2 -e -- echo -n .\ 109 | fd2 $1 test07 | diff -u test07_$1.log - 110 | if $? != 0 if { fd2 -e echo $1: Test 7 Failed } \ 111 | echo >>TestFailCount 112 | echo >>TestPassCount 113 | fd2 -e -- echo -n .\ 114 | : fallthrough 115 | : Next 116 | fd2 $1 test08 | diff -u test08_$1.log - 117 | if $? != 0 if { fd2 -e echo $1: Test 8 Failed } echo >>TestFailCount 118 | echo >>TestPassCount 119 | fd2 -e echo . Done . 120 | shift 121 | if $# = 0 goto Done 122 | goto Again 123 | 124 | : Done - " Print final results and exit false/true as needed. " 125 | 126 | fd2 -e -- now 127 | if ! -s TestFailCount goto TestsPassed 128 | ( wc -l /dev/null : nothing 90 | 72: ( echo Hello! ) : nothing >/dev/null 91 | 92 | ==== Unexpected `<', `>', `>>', or Missing file name ==== 93 | 73: < 94 | 74: > 95 | 75: >> 96 | 76: <> 97 | 77: >< 98 | 78: <>> 99 | 79: >>< 100 | 80: cat < >/dev/null 101 | 81: cat > 103 | 83: cat >/dev/null < 104 | 84: /dev/null 110 | 88: >/dev/null 111 | 89: >/dev/null >/dev/null 113 | 91: >>/dev/null /dev/null ( | ) 118 | 94: ( | ) /dev/null 120 | 96: /dev/null ( | ) 121 | 97: >/dev/null /dev/null 123 | 99: >/dev/null ( | ) /dev/null 125 | 101: ( | ) >/dev/null /dev/null ( < ) 130 | 104: ( < ) /dev/null 132 | 106: /dev/null ( < ) 133 | 107: >/dev/null /dev/null 135 | 109: >/dev/null ( < ) /dev/null 137 | 111: ( < ) >/dev/null , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | 7 | @SH_TO_TEST@ - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \ 8 | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \ 9 | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \ 10 | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 \ 11 | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \ 12 | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 13 | 14 | : Loop 15 | sed -n 's/^ *'$1': /% /p' , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/regression_tests " 7 | : 8 | 9 | : 10 | : test01 - Too many characters 11 | : 12 | 13 | echo Begin ... 14 | echo .......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................1024 15 | echo .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................2042 16 | echo ..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................2043 17 | echo ......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................2047 18 | echo End . 19 | -------------------------------------------------------------------------------- /tests/test01_osh.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | .......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................1024 3 | .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................2042 4 | osh: test01: 16: Too many characters 5 | -------------------------------------------------------------------------------- /tests/test01_sh6.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | .......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................1024 3 | .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................2042 4 | Too many characters 5 | -------------------------------------------------------------------------------- /tests/test02: -------------------------------------------------------------------------------- 1 | : osh/sh6 - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/regression_tests " 7 | : 8 | 9 | : 10 | : test02 - Too many args 11 | : 12 | 13 | echo Begin ... 14 | echo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1018 15 | echo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1019 16 | echo End . 17 | -------------------------------------------------------------------------------- /tests/test02_osh.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1018 3 | osh: test02: 15: Too many args 4 | -------------------------------------------------------------------------------- /tests/test02_sh6.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1018 3 | Too many args 4 | -------------------------------------------------------------------------------- /tests/test03: -------------------------------------------------------------------------------- 1 | : osh/sh6 - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/regression_tests " 7 | : 8 | 9 | : 10 | : test03 - Command line overflow 11 | : 12 | 13 | echo Begin ... 14 | echo 1 ... 15 | /dev/null 40 | echo 1 . 41 | echo 2 ... 42 | /dev/null 68 | echo 2 . 69 | echo 3 ... 70 | /dev/null 97 | echo 3 . 98 | echo End . 99 | -------------------------------------------------------------------------------- /tests/test03_osh.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | 1 ... 3 | 1 . 4 | 2 ... 5 | osh: test03: 67: Command line overflow 6 | -------------------------------------------------------------------------------- /tests/test03_sh6.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | 1 ... 3 | 1 . 4 | 2 ... 5 | Command line overflow 6 | -------------------------------------------------------------------------------- /tests/test04: -------------------------------------------------------------------------------- 1 | : osh/sh6 - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/regression_tests " 7 | : 8 | 9 | : 10 | : test04 - syntactically correct 11 | : 12 | 13 | echo Begin ... 14 | 15 | : The following is perfectly legal in osh and sh6 ... 16 | 17 | ;;;;;; 18 | ; ; ; ; ; ; 19 | &&&&&& 20 | & & & & & & 21 | 22 | : Quotes ... 23 | 24 | echo "\" 25 | echo '\' 26 | echo \\ 27 | echo "Hello World! =)" 28 | echo 'Hello World! =)' 29 | echo Hello\ World!\ =\) 30 | 31 | : Redirections ... 32 | 33 | cat /dev/null 34 | /dev/null 35 | /dev/null cat 36 | cat < input > /dev/null 37 | < input cat > /dev/null 38 | < input > /dev/null cat 39 | 40 | cat >/dev/null 41 | >/dev/null 42 | >/dev/null cat 43 | cat < input >> /dev/null 44 | < input cat >> /dev/null 45 | < input >> /dev/null cat 46 | 47 | cat >/dev/null /dev/null cat /dev/null /dev/null < input 51 | > /dev/null cat < input 52 | > /dev/null < input cat 53 | 54 | cat >>/dev/null >/dev/null cat >/dev/null > /dev/null < input 58 | >> /dev/null cat < input 59 | >> /dev/null < input cat 60 | 61 | ( cat ) /dev/null 62 | /dev/null 63 | /dev/null ( cat ) 64 | ( cat ) < input > /dev/null 65 | < input ( cat ) > /dev/null 66 | < input > /dev/null ( cat ) 67 | 68 | ( cat ) >/dev/null 69 | >/dev/null 70 | >/dev/null ( cat ) 71 | ( cat ) < input >> /dev/null 72 | < input ( cat ) >> /dev/null 73 | < input >> /dev/null ( cat ) 74 | 75 | (cat) /dev/null 76 | /dev/null 77 | /dev/null (cat) 78 | (cat) < input > /dev/null 79 | < input (cat) > /dev/null 80 | < input > /dev/null (cat) 81 | 82 | (cat) >/dev/null 83 | >/dev/null 84 | >/dev/null (cat) 85 | (cat) < input >> /dev/null 86 | < input (cat) >> /dev/null 87 | < input >> /dev/null (cat) 88 | 89 | ( cat ) >/dev/null /dev/null ( cat ) /dev/null /dev/null < input 93 | > /dev/null ( cat ) < input 94 | > /dev/null < input ( cat ) 95 | 96 | ( cat ) >>/dev/null >/dev/null ( cat ) >/dev/null > /dev/null < input 100 | >> /dev/null ( cat ) < input 101 | >> /dev/null < input ( cat ) 102 | 103 | (cat) >/dev/null /dev/null (cat) /dev/null /dev/null < input 107 | > /dev/null (cat) < input 108 | > /dev/null < input (cat) 109 | 110 | (cat) >>/dev/null >/dev/null (cat) >/dev/null > /dev/null < input 114 | >> /dev/null (cat) < input 115 | >> /dev/null < input (cat) 116 | 117 | : Pipes ... 118 | 119 | echo Hello 01! | cat | grep '^H' 120 | echo Hello 02! ^ cat ^ grep '^H' 121 | echo Hello 03! | : nothing | grep '^H' 122 | echo Hello 04! ^ : nothing ^ grep '^H' 123 | echo Hello 05! | cat | : nothing | cat | grep '^H' 124 | echo Hello 06! ^ cat ^ : nothing ^ cat ^ grep '^H' 125 | echo Hello 07!|cat|grep '^H' 126 | echo Hello 08!^cat^grep '^H' 127 | echo Hello 09!|: nothing|grep '^H' 128 | echo Hello 10!^: nothing^grep '^H' 129 | echo Hello 11!|cat|: nothing|cat|grep '^H' 130 | echo Hello 12!^cat^: nothing^cat^grep '^H' 131 | 132 | : Subshells ... 133 | 134 | ( echo Hello 13! ) | ( cat ) | ( grep '^H' ) 135 | ( ( echo Hello 14! ) | ( cat ) | ( grep '^H' ) ) 136 | ( echo Hello 15! ) ^ ( cat ) ^ ( grep '^H' ) 137 | ( ( echo Hello 16! ) ^ ( cat ) ^ ( grep '^H' ) ) 138 | echo Hello 17! | ( ( cat ) | grep '^H' ) 139 | ( echo Hello 18! | ( ( cat ) | grep '^H' ) ) 140 | echo Hello 19! ^ ( ( cat ) ^ grep '^H' ) 141 | ( echo Hello 20! ^ ( ( cat ) ^ grep '^H' ) ) 142 | ( echo Hello 21! | ( cat ) ) | grep '^H' 143 | ( ( echo Hello 22! | ( cat ) ) | grep '^H' ) 144 | ( echo Hello 23! ^ ( cat ) ) ^ grep '^H' 145 | ( ( echo Hello 24! ^ ( cat ) ) ^ grep '^H' ) 146 | ( echo Hello 25! ) | ( cat >/dev/null ) | ( grep '^H' ) 147 | ( ( echo Hello 26! ) | ( cat >/dev/null ) | ( grep '^H' ) ) 148 | ( echo Hello 27! ) ^ ( cat >/dev/null ) ^ ( grep '^H' ) 149 | ( ( echo Hello 28! ) ^ ( cat >/dev/null ) ^ ( grep '^H' ) ) 150 | ( echo Hello 29! ) | ( : nothing ) | ( grep '^H' ) 151 | ( ( echo Hello 30! ) | ( : nothing ) | ( grep '^H' ) ) 152 | ( echo Hello 31! ) ^ ( : nothing ) ^ ( grep '^H' ) 153 | ( ( echo Hello 32! ) ^ ( : nothing ) ^ ( grep '^H' ) ) 154 | ( echo one ) ; ( echo two ) ; ( echo three ) 155 | ( ( echo one ) ; ( echo two ) ; ( echo three ) ) 156 | ( echo \( one \) ) ; ( echo \( two \) ) ; ( echo \( three \) ) 157 | ( ( echo \( one \) ) ; ( echo \( two \) ) ; ( echo \( three \) ) ) 158 | 159 | (echo Hello 33!)|(cat)|(grep '^H') 160 | ((echo Hello 34!)|(cat)|(grep '^H')) 161 | (echo Hello 35!)^(cat)^(grep '^H') 162 | ((echo Hello 36!)^(cat)^(grep '^H')) 163 | echo Hello 37!|((cat)|grep '^H') 164 | (echo Hello 38!|((cat)|grep '^H')) 165 | echo Hello 39!^((cat)^grep '^H') 166 | (echo Hello 40!^((cat)^grep '^H')) 167 | (echo Hello 41!|(cat))|grep '^H' 168 | ((echo Hello 42!|(cat))|grep '^H') 169 | (echo Hello 43!^(cat))^grep '^H' 170 | ((echo Hello 44!^(cat))^grep '^H') 171 | (echo Hello 45!)|(cat >/dev/null)|(grep '^H') 172 | ((echo Hello 46!)|(cat >/dev/null)|(grep '^H')) 173 | (echo Hello 47!)^(cat >/dev/null)^(grep '^H') 174 | ((echo Hello 48!)^(cat >/dev/null)^(grep '^H')) 175 | (echo Hello 49!)|(: nothing)|(grep '^H') 176 | ((echo Hello 50!)|(: nothing)|(grep '^H')) 177 | (echo Hello 51!)^(: nothing)^(grep '^H') 178 | ((echo Hello 52!)^(: nothing)^(grep '^H')) 179 | (echo one);(echo two);(echo three) 180 | ((echo one);(echo two);(echo three)) 181 | (echo \(one\));(echo \(two\));(echo \(three\)) 182 | ((echo \(one\));(echo \(two\));(echo \(three\))) 183 | 184 | ( ( echo Hello 53! ) | \ 185 | ( cat | ( cat | cat | cat ) | cat ) | \ 186 | ( grep '^H' ) ) 187 | ( ( echo Hello 54! ) ^ \ 188 | ( cat ^ ( cat ^ cat ^ cat ) ^ cat ) ^ \ 189 | ( grep '^H' ) ) 190 | ( ( echo Hello 55! ) | \ 191 | ( cat | ( cat | : nothing | cat ) | cat ) | \ 192 | ( grep '^H' ) ) 193 | ( ( echo Hello 56! ) ^ \ 194 | ( cat ^ ( cat ^ : nothing ^ cat ) ^ cat ) ^ \ 195 | ( grep '^H' ) ) 196 | 197 | ((echo Hello 57!)|(cat|(cat|cat|cat)|cat)|(grep '^H')) 198 | ((echo Hello 58!)^(cat^(cat^cat^cat)^cat)^(grep '^H')) 199 | ((echo Hello 59!)|(cat|(cat|: nothing|cat)|cat)|(grep '^H')) 200 | ((echo Hello 60!)^(cat^(cat^: nothing^cat)^cat)^(grep '^H')) 201 | 202 | : Asynchronous ... 203 | 204 | ( sleep 3 ; echo 'sleep 3 : done' ) & \ 205 | ( sleep 4 ; echo 'sleep 4 : done' ) & \ 206 | ( sleep 5 ; echo 'sleep 5 : done' ) & \ 207 | wait 208 | 209 | echo End . 210 | -------------------------------------------------------------------------------- /tests/test04_osh.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | \ 3 | \ 4 | \ 5 | Hello World! =) 6 | Hello World! =) 7 | Hello World! =) 8 | Hello 01! 9 | Hello 02! 10 | Hello 07! 11 | Hello 08! 12 | Hello 13! 13 | Hello 14! 14 | Hello 15! 15 | Hello 16! 16 | Hello 17! 17 | Hello 18! 18 | Hello 19! 19 | Hello 20! 20 | Hello 21! 21 | Hello 22! 22 | Hello 23! 23 | Hello 24! 24 | one 25 | two 26 | three 27 | one 28 | two 29 | three 30 | ( one ) 31 | ( two ) 32 | ( three ) 33 | ( one ) 34 | ( two ) 35 | ( three ) 36 | Hello 33! 37 | Hello 34! 38 | Hello 35! 39 | Hello 36! 40 | Hello 37! 41 | Hello 38! 42 | Hello 39! 43 | Hello 40! 44 | Hello 41! 45 | Hello 42! 46 | Hello 43! 47 | Hello 44! 48 | one 49 | two 50 | three 51 | one 52 | two 53 | three 54 | (one) 55 | (two) 56 | (three) 57 | (one) 58 | (two) 59 | (three) 60 | Hello 53! 61 | Hello 54! 62 | Hello 57! 63 | Hello 58! 64 | sleep 3 : done 65 | sleep 4 : done 66 | sleep 5 : done 67 | End . 68 | -------------------------------------------------------------------------------- /tests/test04_sh6.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | \ 3 | \ 4 | \ 5 | Hello World! =) 6 | Hello World! =) 7 | Hello World! =) 8 | Hello 01! 9 | Hello 02! 10 | Hello 07! 11 | Hello 08! 12 | Hello 13! 13 | Hello 14! 14 | Hello 15! 15 | Hello 16! 16 | Hello 17! 17 | Hello 18! 18 | Hello 19! 19 | Hello 20! 20 | Hello 21! 21 | Hello 22! 22 | Hello 23! 23 | Hello 24! 24 | one 25 | two 26 | three 27 | one 28 | two 29 | three 30 | ( one ) 31 | ( two ) 32 | ( three ) 33 | ( one ) 34 | ( two ) 35 | ( three ) 36 | Hello 33! 37 | Hello 34! 38 | Hello 35! 39 | Hello 36! 40 | Hello 37! 41 | Hello 38! 42 | Hello 39! 43 | Hello 40! 44 | Hello 41! 45 | Hello 42! 46 | Hello 43! 47 | Hello 44! 48 | one 49 | two 50 | three 51 | one 52 | two 53 | three 54 | (one) 55 | (two) 56 | (three) 57 | (one) 58 | (two) 59 | (three) 60 | Hello 53! 61 | Hello 54! 62 | Hello 57! 63 | Hello 58! 64 | sleep 3 : done 65 | sleep 4 : done 66 | sleep 5 : done 67 | End . 68 | -------------------------------------------------------------------------------- /tests/test05: -------------------------------------------------------------------------------- 1 | : osh/sh6 - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/regression_tests " 7 | : 8 | 9 | : 10 | : test05 - syntax error 11 | : 12 | 13 | if ! \( X$1 = Xosh -o X$1 = Xsh6 \) -o X$2 != X \ 14 | if { fd2 -e echo 'usage: {osh | sh6} test05 {osh | sh6}' } \ 15 | if { exit } if A = B 16 | 17 | sed 's,@SH_TO_TEST@,'$1',g' syntax_error 18 | 19 | echo Begin ... 20 | $1 syntax_error 21 | echo End . 22 | -------------------------------------------------------------------------------- /tests/test05_osh.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | % " 3 | osh: -t: syntax error 4 | % : nothing; " 5 | osh: -t: syntax error 6 | % "; : nothing 7 | osh: -t: syntax error 8 | % ( " ) 9 | osh: -t: syntax error 10 | % : nothing; ( " ) 11 | osh: -t: syntax error 12 | % ( " ); : nothing 13 | osh: -t: syntax error 14 | % ( : nothing; " ) 15 | osh: -t: syntax error 16 | % ( "; : nothing ) 17 | osh: -t: syntax error 18 | % ' 19 | osh: -t: syntax error 20 | % : nothing; ' 21 | osh: -t: syntax error 22 | % '; : nothing 23 | osh: -t: syntax error 24 | % ( ' ) 25 | osh: -t: syntax error 26 | % : nothing; ( ' ) 27 | osh: -t: syntax error 28 | % ( ' ); : nothing 29 | osh: -t: syntax error 30 | % ( : nothing; ' ) 31 | osh: -t: syntax error 32 | % ( '; : nothing ) 33 | osh: -t: syntax error 34 | % | 35 | osh: -t: syntax error 36 | % ^ 37 | osh: -t: syntax error 38 | % | | 39 | osh: -t: syntax error 40 | % ^ ^ 41 | osh: -t: syntax error 42 | % | cat 43 | osh: -t: syntax error 44 | % ^ cat 45 | osh: -t: syntax error 46 | % echo Hello! | 47 | osh: -t: syntax error 48 | % echo Hello! ^ 49 | osh: -t: syntax error 50 | % echo Hello! | cat | 51 | osh: -t: syntax error 52 | % echo Hello! ^ cat ^ 53 | osh: -t: syntax error 54 | % echo Hello! | | grep H 55 | osh: -t: syntax error 56 | % echo Hello! ^ ^ grep H 57 | osh: -t: syntax error 58 | % || 59 | osh: -t: syntax error 60 | % ^^ 61 | osh: -t: syntax error 62 | % |cat 63 | osh: -t: syntax error 64 | % ^cat 65 | osh: -t: syntax error 66 | % echo Hello!| 67 | osh: -t: syntax error 68 | % echo Hello!^ 69 | osh: -t: syntax error 70 | % echo Hello!|cat| 71 | osh: -t: syntax error 72 | % echo Hello!^cat^ 73 | osh: -t: syntax error 74 | % echo Hello!||grep H 75 | osh: -t: syntax error 76 | % echo Hello!^^grep H 77 | osh: -t: syntax error 78 | % ( 79 | osh: -t: syntax error 80 | % ( echo Hello! 81 | osh: -t: syntax error 82 | % ( ( echo Hello! ) 83 | osh: -t: syntax error 84 | % ( ( echo Hello! ); echo Hello again! 85 | osh: -t: syntax error 86 | % echo Hello! | ( ( cat ) | grep H 87 | osh: -t: syntax error 88 | % ( echo Hello! | ( ( cat ) | grep H ) 89 | osh: -t: syntax error 90 | % echo Hello! ^ ( ( cat ) ^ grep H 91 | osh: -t: syntax error 92 | % ( echo Hello! ^ ( ( cat ) ^ grep H ) 93 | osh: -t: syntax error 94 | % ) 95 | osh: -t: syntax error 96 | % echo Hello! ) 97 | osh: -t: syntax error 98 | % ( echo Hello! ) ) 99 | osh: -t: syntax error 100 | % ( echo Hello! ); echo Hello again! ) 101 | osh: -t: syntax error 102 | % echo Hello! | ( cat ) ) | grep H 103 | osh: -t: syntax error 104 | % ( echo Hello! | ( cat ) ) | grep H ) 105 | osh: -t: syntax error 106 | % echo Hello! ^ ( cat ) ) ^ grep H 107 | osh: -t: syntax error 108 | % ( echo Hello! ^ ( cat ) ) ^ grep H ) 109 | osh: -t: syntax error 110 | % ( ) 111 | osh: -t: syntax error 112 | % ( ( ) ) 113 | osh: -t: syntax error 114 | % ( ( ( ) ) ) 115 | osh: -t: syntax error 116 | % ( echo Hello! ) | ( ) | ( grep H ) 117 | osh: -t: syntax error 118 | % ( ( echo Hello! ) | ( ) | ( grep H ) ) 119 | osh: -t: syntax error 120 | % () 121 | osh: -t: syntax error 122 | % (()) 123 | osh: -t: syntax error 124 | % ((())) 125 | osh: -t: syntax error 126 | % (echo Hello!)|()|(grep H) 127 | osh: -t: syntax error 128 | % ((echo Hello!)|()|(grep H)) 129 | osh: -t: syntax error 130 | % :( echo Hello! ) 131 | osh: -t: syntax error 132 | % echo ( Hello! ) 133 | osh: -t: syntax error 134 | % : nothing /dev/null : nothing 143 | osh: -t: syntax error 144 | % ( echo Hello! ) : nothing >/dev/null 145 | osh: -t: syntax error 146 | % < 147 | osh: -t: syntax error 148 | % > 149 | osh: -t: syntax error 150 | % >> 151 | osh: -t: syntax error 152 | % <> 153 | osh: -t: syntax error 154 | % >< 155 | osh: -t: syntax error 156 | % <>> 157 | osh: -t: syntax error 158 | % >>< 159 | osh: -t: syntax error 160 | % cat < >/dev/null 161 | osh: -t: syntax error 162 | % cat > 165 | osh: -t: syntax error 166 | % cat >/dev/null < 167 | osh: -t: syntax error 168 | % /dev/null 175 | osh: -t: syntax error 176 | % >/dev/null 177 | osh: -t: syntax error 178 | % >/dev/null >/dev/null 181 | osh: -t: syntax error 182 | % >>/dev/null /dev/null ( | ) 187 | osh: -t: syntax error 188 | % ( | ) /dev/null 191 | osh: -t: syntax error 192 | % /dev/null ( | ) 193 | osh: -t: syntax error 194 | % >/dev/null /dev/null 197 | osh: -t: syntax error 198 | % >/dev/null ( | ) /dev/null 201 | osh: -t: syntax error 202 | % ( | ) >/dev/null /dev/null ( < ) 207 | osh: -t: syntax error 208 | % ( < ) /dev/null 211 | osh: -t: syntax error 212 | % /dev/null ( < ) 213 | osh: -t: syntax error 214 | % >/dev/null /dev/null 217 | osh: -t: syntax error 218 | % >/dev/null ( < ) /dev/null 221 | osh: -t: syntax error 222 | % ( < ) >/dev/null /dev/null : nothing 143 | syntax error 144 | % ( echo Hello! ) : nothing >/dev/null 145 | syntax error 146 | % < 147 | syntax error 148 | % > 149 | syntax error 150 | % >> 151 | syntax error 152 | % <> 153 | syntax error 154 | % >< 155 | syntax error 156 | % <>> 157 | syntax error 158 | % >>< 159 | syntax error 160 | % cat < >/dev/null 161 | syntax error 162 | % cat > 165 | syntax error 166 | % cat >/dev/null < 167 | syntax error 168 | % /dev/null 175 | syntax error 176 | % >/dev/null 177 | syntax error 178 | % >/dev/null >/dev/null 181 | syntax error 182 | % >>/dev/null /dev/null ( | ) 187 | syntax error 188 | % ( | ) /dev/null 191 | syntax error 192 | % /dev/null ( | ) 193 | syntax error 194 | % >/dev/null /dev/null 197 | syntax error 198 | % >/dev/null ( | ) /dev/null 201 | syntax error 202 | % ( | ) >/dev/null /dev/null ( < ) 207 | syntax error 208 | % ( < ) /dev/null 211 | syntax error 212 | % /dev/null ( < ) 213 | syntax error 214 | % >/dev/null /dev/null 217 | syntax error 218 | % >/dev/null ( < ) /dev/null 221 | syntax error 222 | % ( < ) >/dev/null , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/regression_tests " 7 | : 8 | 9 | : 10 | : test06 - Aliases 11 | : 12 | 13 | if $# = # if { fd2 -e echo Invalid shell - osh\(1\) required } \ 14 | if { exit } if A = B 15 | 16 | echo Begin ... 17 | alias 18 | if $? = 1 echo 0 Aliases Set 19 | alias tests "echo test??^tr ' ' '\n';:" 20 | alias logs "echo *.log^tr ' ' '\n';:" 21 | alias TestCounts "echo Test*Count^tr ' ' '\n';:" 22 | alias HelloWorld "echo 'Hello World!'^cat^cat^cat^cat^cat^cat^cat^cat^cat^grep '^H';:" 23 | alias All "echo *^tr ' ' '\n';:" 24 | ( alias ) >/dev/null 25 | if $? = 1 if { fd2 -e echo Unexpected alias result } if { exit } if A = B 26 | ( alias ) ^ wc -l ^ tr -d ' \t\n' ; echo ' Aliases Set' 27 | ( alias ) ^ awk '{ print NR "\t" $0 }' 28 | echo HelloWorld ...;HelloWorld^awk '{ print NR "\t" $0 }';echo HelloWorld . 29 | echo All ...; All ;echo All . 30 | echo tests ...; tests ^awk '{ print NR "\t" $0 }';echo tests . 31 | echo logs ...; logs ^awk '{ print NR "\t" $0 }';echo logs . 32 | echo TestCounts ...;TestCounts^awk '{ print NR "\t" $0 }';echo TestCounts . 33 | unalias tests 34 | unalias logs 35 | unalias TestCounts 36 | unalias HelloWorld 37 | unalias All 38 | alias 39 | if $? = 1 echo 0 Aliases Set 40 | echo End . 41 | -------------------------------------------------------------------------------- /tests/test06_osh.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | 0 Aliases Set 3 | 5 Aliases Set 4 | 1 All (echo *^tr ' ' '\n';:) 5 | 2 HelloWorld (echo 'Hello World!'^cat^cat^cat^cat^cat^cat^cat^cat^cat^grep '^H';:) 6 | 3 TestCounts (echo Test*Count^tr ' ' '\n';:) 7 | 4 logs (echo *.log^tr ' ' '\n';:) 8 | 5 tests (echo test??^tr ' ' '\n';:) 9 | HelloWorld ... 10 | 1 Hello World! 11 | HelloWorld . 12 | All ... 13 | LICENSE 14 | README 15 | TestFailCount 16 | TestPassCount 17 | bin 18 | input 19 | run.osh 20 | syntax.list 21 | syntax_error.in 22 | test01 23 | test01_osh.log 24 | test01_sh6.log 25 | test02 26 | test02_osh.log 27 | test02_sh6.log 28 | test03 29 | test03_osh.log 30 | test03_sh6.log 31 | test04 32 | test04_osh.log 33 | test04_sh6.log 34 | test05 35 | test05_osh.log 36 | test05_sh6.log 37 | test06 38 | test06_osh.log 39 | test07 40 | test07_osh.log 41 | test08 42 | test08_osh.log 43 | test08_sh6.log 44 | All . 45 | tests ... 46 | 1 test01 47 | 2 test02 48 | 3 test03 49 | 4 test04 50 | 5 test05 51 | 6 test06 52 | 7 test07 53 | 8 test08 54 | tests . 55 | logs ... 56 | 1 test01_osh.log 57 | 2 test01_sh6.log 58 | 3 test02_osh.log 59 | 4 test02_sh6.log 60 | 5 test03_osh.log 61 | 6 test03_sh6.log 62 | 7 test04_osh.log 63 | 8 test04_sh6.log 64 | 9 test05_osh.log 65 | 10 test05_sh6.log 66 | 11 test06_osh.log 67 | 12 test07_osh.log 68 | 13 test08_osh.log 69 | 14 test08_sh6.log 70 | logs . 71 | TestCounts ... 72 | 1 TestFailCount 73 | 2 TestPassCount 74 | TestCounts . 75 | 0 Aliases Set 76 | End . 77 | -------------------------------------------------------------------------------- /tests/test07: -------------------------------------------------------------------------------- 1 | : osh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/regression_tests " 7 | : 8 | 9 | : 10 | : test07 - Variable substitution 11 | : 12 | 13 | if $# = # if { fd2 -e echo Invalid shell - osh\(1\) required } \ 14 | if { exit } if A = B 15 | 16 | echo Begin ... 17 | set 18 | if $? = 1 echo 0 Variables Set 19 | set E "echo test??^tr ' ' '\n'" 20 | set D "echo *.log^tr ' ' '\n'" 21 | set C "echo Test*Count^tr ' ' '\n'" 22 | set B "echo 'Hello World!'^cat^cat^cat^cat^cat^cat^cat^cat^cat^grep '^H'" 23 | set A "echo *^tr ' ' '\n'" 24 | set a a... 25 | set b b... 26 | set c c... 27 | set X X... 28 | set Y Y... 29 | set Z Z... 30 | ( set ) >/dev/null 31 | if $? = 1 if { fd2 -e echo Unexpected set result } if { exit } if A = B 32 | ( set ) ^ wc -l ^ tr -d ' \t\n' ; echo ' Variables Set' 33 | ( set ) ^ awk '{ print NR "\t" $0 }' 34 | echo \$B ...;$B^awk '{ print NR "\t" $0 }';echo \$B . 35 | echo \$A ...;$A ;echo \$A . 36 | echo \$E ...;$E^awk '{ print NR "\t" $0 }';echo \$E . 37 | echo \$D ...;$D^awk '{ print NR "\t" $0 }';echo \$D . 38 | echo \$C ...;$C^awk '{ print NR "\t" $0 }';echo \$C . 39 | echo \$a \$b \$c ...;echo $a $b $c;echo \$a \$b \$c . 40 | echo \$X \$Y \$Z ...;echo $X $Y $Z;echo \$X \$Y \$Z . 41 | unset E 42 | unset D 43 | unset C 44 | unset B 45 | unset A 46 | unset a 47 | unset b 48 | unset c 49 | unset X 50 | unset Y 51 | unset Z 52 | set 53 | if $? = 1 echo 0 Variables Set 54 | echo End . 55 | -------------------------------------------------------------------------------- /tests/test07_osh.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | 0 Variables Set 3 | 11 Variables Set 4 | 1 A echo *^tr ' ' '\n' 5 | 2 B echo 'Hello World!'^cat^cat^cat^cat^cat^cat^cat^cat^cat^grep '^H' 6 | 3 C echo Test*Count^tr ' ' '\n' 7 | 4 D echo *.log^tr ' ' '\n' 8 | 5 E echo test??^tr ' ' '\n' 9 | 6 X X... 10 | 7 Y Y... 11 | 8 Z Z... 12 | 9 a a... 13 | 10 b b... 14 | 11 c c... 15 | $B ... 16 | 1 Hello World! 17 | $B . 18 | $A ... 19 | LICENSE 20 | README 21 | TestFailCount 22 | TestPassCount 23 | bin 24 | input 25 | run.osh 26 | syntax.list 27 | syntax_error.in 28 | test01 29 | test01_osh.log 30 | test01_sh6.log 31 | test02 32 | test02_osh.log 33 | test02_sh6.log 34 | test03 35 | test03_osh.log 36 | test03_sh6.log 37 | test04 38 | test04_osh.log 39 | test04_sh6.log 40 | test05 41 | test05_osh.log 42 | test05_sh6.log 43 | test06 44 | test06_osh.log 45 | test07 46 | test07_osh.log 47 | test08 48 | test08_osh.log 49 | test08_sh6.log 50 | $A . 51 | $E ... 52 | 1 test01 53 | 2 test02 54 | 3 test03 55 | 4 test04 56 | 5 test05 57 | 6 test06 58 | 7 test07 59 | 8 test08 60 | $E . 61 | $D ... 62 | 1 test01_osh.log 63 | 2 test01_sh6.log 64 | 3 test02_osh.log 65 | 4 test02_sh6.log 66 | 5 test03_osh.log 67 | 6 test03_sh6.log 68 | 7 test04_osh.log 69 | 8 test04_sh6.log 70 | 9 test05_osh.log 71 | 10 test05_sh6.log 72 | 11 test06_osh.log 73 | 12 test07_osh.log 74 | 13 test08_osh.log 75 | 14 test08_sh6.log 76 | $D . 77 | $C ... 78 | 1 TestFailCount 79 | 2 TestPassCount 80 | $C . 81 | $a $b $c ... 82 | a... b... c... 83 | $a $b $c . 84 | $X $Y $Z ... 85 | X... Y... Z... 86 | $X $Y $Z . 87 | 0 Variables Set 88 | End . 89 | -------------------------------------------------------------------------------- /tests/test08: -------------------------------------------------------------------------------- 1 | : osh/sh6 - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; 2 | : 3 | : " The author of this file, J.A. Neitzel , " 4 | : " hereby grants it to the public domain. " 5 | : 6 | : " From: http://v6shell.org/regression_tests " 7 | : 8 | 9 | : 10 | : test08 - glob : No directory / No match / Pattern too long 11 | : 12 | 13 | echo Begin ... 14 | echo foo/*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx* 15 | echo foo/*'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'* 16 | echo *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx* 17 | echo *'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'* 18 | echo *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx* 19 | echo *'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'* 20 | echo End . 21 | -------------------------------------------------------------------------------- /tests/test08_osh.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | osh: test08: 14: No directory 3 | osh: test08: 15: No directory 4 | osh: test08: 16: No match 5 | osh: test08: 17: No match 6 | osh: test08: 18: Pattern too long 7 | osh: test08: 19: Pattern too long 8 | End . 9 | -------------------------------------------------------------------------------- /tests/test08_sh6.log: -------------------------------------------------------------------------------- 1 | Begin ... 2 | No directory 3 | No directory 4 | No match 5 | No match 6 | Pattern too long 7 | Pattern too long 8 | End . 9 | -------------------------------------------------------------------------------- /v.c: -------------------------------------------------------------------------------- 1 | /* 2 | * v.c - osh package version and copyright notices 3 | */ 4 | /*- 5 | * Copyright (c) 2008-2014 6 | * Jeffrey Allen Neitzel . 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | * 29 | * @(#)$Id: ebf927f05cb9607edb1e16d6b0cfd811f4914b42 $ 30 | */ 31 | 32 | #include "config.h" 33 | 34 | #ifndef lint 35 | #ifndef OSH_ATTR 36 | # if __GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ >= 4 37 | # define OSH_ATTR __attribute__((__used__)) 38 | # elif defined(__GNUC__) 39 | # define OSH_ATTR __attribute__((__unused__)) 40 | # else 41 | # define OSH_ATTR /* nothing */ 42 | # endif 43 | #endif /* !OSH_ATTR */ 44 | 45 | /*@unused@*/ 46 | static const char *const vcid[] OSH_ATTR = { 47 | "\100(#)\044Id: " OSH_VERSION " (" OSH_UNAME_SRM ") \044", 48 | "\100(#)\044Id: Copyright (c) 2003-2014 Jeffrey Allen Neitzel. \044", 49 | "\100(#)\044Id: Copyright (c) 2001-2002 Caldera International Inc. \044", 50 | "\100(#)\044Id: Copyright (c) 1985, 1989, 1991, 1993 The Regents of the University of California. \044" 51 | }; 52 | #endif /* !lint */ 53 | --------------------------------------------------------------------------------