diff --git a/README b/README index 69c2081..aa17b82 100644 --- a/README +++ b/README @@ -14,7 +14,7 @@ How to install: Please see the document called "INSTALL" in the source distribution. Tested on: - OpenBSD 6.3, NetBSD 7.0.2, Ubuntu 16.10, Solaris 11.3 + OpenBSD 6.3, NetBSD 7.1.2, Ubuntu 17.10, Solaris 11.4, CentOS 7 ------------------------------------------------------------------------ diff --git a/TODO b/TODO index 64725db..2c9470b 100644 --- a/TODO +++ b/TODO @@ -1 +1,3 @@ -Nothing at the moment. +For "shell": + +* Nothing at the moment. diff --git a/configure b/configure index b8437a7..0bb69f8 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69.195-487d6 for shell-toolbox 20180408. +# Generated by GNU Autoconf 2.69.195-487d6 for shell-toolbox 20180415. # # Report bugs to . # @@ -565,8 +565,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='shell-toolbox' PACKAGE_TARNAME='shell-toolbox' -PACKAGE_VERSION='20180408' -PACKAGE_STRING='shell-toolbox 20180408' +PACKAGE_VERSION='20180415' +PACKAGE_STRING='shell-toolbox 20180415' PACKAGE_BUGREPORT='https://github.com/kusalananda/shell-toolbox/issues' PACKAGE_URL='' @@ -1203,7 +1203,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures shell-toolbox 20180408 to adapt to many kinds of systems. +\`configure' configures shell-toolbox 20180415 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1270,7 +1270,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of shell-toolbox 20180408:";; + short | recursive ) echo "Configuration of shell-toolbox 20180415:";; esac cat <<\_ACEOF @@ -1347,7 +1347,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -shell-toolbox configure 20180408 +shell-toolbox configure 20180415 generated by GNU Autoconf 2.69.195-487d6 Copyright (C) 2017 Free Software Foundation, Inc. @@ -1384,7 +1384,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by shell-toolbox $as_me 20180408, which was +It was created by shell-toolbox $as_me 20180415, which was generated by GNU Autoconf 2.69.195-487d6. Invocation command line was $ $0$ac_configure_args_raw @@ -2272,7 +2272,7 @@ fi # Define the identity of the package. PACKAGE='shell-toolbox' - VERSION='20180408' + VERSION='20180415' printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h @@ -3017,7 +3017,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by shell-toolbox $as_me 20180408, which was +This file was extended by shell-toolbox $as_me 20180415, which was generated by GNU Autoconf 2.69.195-487d6. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -3072,7 +3072,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ -shell-toolbox config.status 20180408 +shell-toolbox config.status 20180415 configured by $0, generated by GNU Autoconf 2.69.195-487d6, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 08251a0..c057f8e 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([shell-toolbox],[20180408],[https://github.com/kusalananda/shell-toolbox/issues]) +AC_INIT([shell-toolbox],[20180415],[https://github.com/kusalananda/shell-toolbox/issues]) AC_CONFIG_AUX_DIR([build]) diff --git a/doc/shell.man b/doc/shell.man index 2e146d5..35ca952 100644 --- a/doc/shell.man +++ b/doc/shell.man @@ -1,4 +1,4 @@ -.TH "SHELL" "1" "April 8, 2018" "Unix" "General Commands Manual" +.TH "SHELL" "1" "April 15, 2018" "Unix" "General Commands Manual" .nh .if n .ad l .SH "NAME" @@ -7,12 +7,14 @@ .SH "SYNOPSIS" .HP 6n \fBshell\fR +[\fB\-f\fR] [\fB\-d\fR\ \fIdirectory\fR\ |\ \fB\-k\fR] [\fIshell\fR\ [\fI...\fR]] .br .PD 0 .HP 6n \fBshell\fR +[\fB\-f\fR] [\fB\-s\fR\ \fIdirectory\fR] [\fB\-k\fR] [\fIshell\fR\ [\fI...\fR]] @@ -58,6 +60,10 @@ option, and conflicts with the \fB\-s\fR option. .TP 8n +\fB\-f\fR +Force the execution of the given command, even if it is not a valid +login shell on the current system. +.TP 8n \fB\-k\fR Keep the temporary directory around after terminating the shell session. .TP 8n @@ -77,6 +83,11 @@ uses the following environment variables: Directory in which to create the working directory when the \fB\-d\fR option is not used. +This variable is used by +\fBmktemp\fR +which will revert to use +\fI/tmp\fR +if the variable is not set. .TP 8n \fRSHELL\fR Used to determine what shell to start if a specific @@ -184,14 +195,19 @@ $ exit Removing /tmp/shell-ksh.4DzEG6qr .RE .fi +.SH "SEE ALSO" +mktemp(1) .SH "AUTHORS" Andreas Kusalananda K\[:a]h\[:a]ri <\fIandreas.kahari@nbis.se\fR> .SH "CAVEATS" For Solaris, the list of valid login shells is taken from the shells(4) -manual on a Solaris 11.3 system. +manual on a vanilla Solaris 11.4 system. This is because Solaris lacks \(lq\fBgetent shells\fR\(rq and may also lack the \fI/etc/shells\fR file. +The +\fI/etc/shells\fR +file will still be used if it exists. diff --git a/doc/shell.md b/doc/shell.md index a92001d..000d9d4 100644 --- a/doc/shell.md +++ b/doc/shell.md @@ -7,9 +7,11 @@ SHELL(1) - General Commands Manual # SYNOPSIS **shell** +\[**-f**] \[**-d** *directory* | **-k**] \[*shell* \[*...*]] **shell** +\[**-f**] \[**-s** *directory*] \[**-k**] \[*shell* \[*...*]] @@ -57,6 +59,11 @@ The options are as follows: > **-s** > option. +**-f** + +> Force the execution of the given command, even if it is not a valid +> login shell on the current system. + **-k** > Keep the temporary directory around after terminating the shell session. @@ -81,6 +88,11 @@ uses the following environment variables: > Directory in which to create the working directory when the > **-d** > option is not used. +> This variable is used by +> **mktemp** +> which will revert to use +> */tmp* +> if the variable is not set. `SHELL` @@ -183,6 +195,10 @@ file copied from $ exit Removing /tmp/shell-ksh.4DzEG6qr +# SEE ALSO + +mktemp(1) + # AUTHORS Andreas Kusalananda Kähäri <[andreas.kahari@nbis.se](mailto:andreas.kahari@nbis.se)> @@ -191,11 +207,14 @@ Andreas Kusalananda Kähäri <[andreas.kahari@nbis.se](mailto:andreas For Solaris, the list of valid login shells is taken from the shells(4) -manual on a Solaris 11.3 system. +manual on a vanilla Solaris 11.4 system. This is because Solaris lacks "**getent shells**" and may also lack the */etc/shells* file. +The +*/etc/shells* +file will still be used if it exists. -Unix - April 8, 2018 +Unix - April 15, 2018 diff --git a/doc/shell.mdoc b/doc/shell.mdoc index 0b3fc7c..e3ba627 100644 --- a/doc/shell.mdoc +++ b/doc/shell.mdoc @@ -6,9 +6,11 @@ .Nd Creates a temporary interactive shell session in a disposable working directory .Sh SYNOPSIS .Nm shell +.Op Fl f .Op Fl d Ar directory | Fl k .Op Ar shell Op Ar ... .Nm +.Op Fl f .Op Fl s Ar directory .Op Fl k .Op Ar shell Op Ar ... @@ -52,6 +54,9 @@ This option implies the option, and conflicts with the .Fl s option. +.It Fl f +Force the execution of the given command, even if it is not a valid +login shell on the current system. .It Fl k Keep the temporary directory around after terminating the shell session. .It Fl s Ar directory @@ -71,6 +76,11 @@ uses the following environment variables: Directory in which to create the working directory when the .Fl d option is not used. +This variable is used by +.Cm mktemp +which will revert to use +.Pa /tmp +if the variable is not set. .It Ev SHELL Used to determine what shell to start if a specific .Ar shell @@ -164,14 +174,19 @@ drwxrwxrwt 4 root wheel 512 Apr 8 18:49 .. $ exit Removing /tmp/shell-ksh.4DzEG6qr .Ed +.Sh SEE ALSO +.Xr mktemp 1 .Sh AUTHORS .An Andreas Kusalananda K\[:a]h\[:a]ri Aq Mt andreas.kahari@nbis.se .Sh CAVEATS For Solaris, the list of valid login shells is taken from the .Xr shells 4 -manual on a Solaris 11.3 system. +manual on a vanilla Solaris 11.4 system. This is because Solaris lacks .Dq Cm getent shells and may also lack the .Pa /etc/shells file. +The +.Pa /etc/shells +file will still be used if it exists. diff --git a/doc/shell.txt b/doc/shell.txt index 04ddeb3..4e854ea 100644 --- a/doc/shell.txt +++ b/doc/shell.txt @@ -5,8 +5,8 @@ NAME working directory SYNOPSIS - shell [-d directory | -k] [shell [...]] - shell [-s directory] [-k] [shell [...]] + shell [-f] [-d directory | -k] [shell [...]] + shell [-f] [-s directory] [-k] [shell [...]] DESCRIPTION The shell utility creates an interactive shell session with a clean @@ -34,6 +34,9 @@ DESCRIPTION session terminates. This option implies the -k option, and conflicts with the -s option. + -f Force the execution of the given command, even if it is not a + valid login shell on the current system. + -k Keep the temporary directory around after terminating the shell session. @@ -47,7 +50,8 @@ ENVIRONMENT shell uses the following environment variables: TMPDIR Directory in which to create the working directory when the -d - option is not used. + option is not used. This variable is used by mktemp which will + revert to use /tmp if the variable is not set. SHELL Used to determine what shell to start if a specific shell is not specified on the command line. @@ -116,12 +120,16 @@ EXAMPLES $ exit Removing /tmp/shell-ksh.4DzEG6qr +SEE ALSO + mktemp(1) + AUTHORS Andreas Kusalananda Kahari CAVEATS For Solaris, the list of valid login shells is taken from the shells(4) - manual on a Solaris 11.3 system. This is because Solaris lacks "getent - shells" and may also lack the /etc/shells file. + manual on a vanilla Solaris 11.4 system. This is because Solaris lacks + "getent shells" and may also lack the /etc/shells file. The /etc/shells + file will still be used if it exists. -Unix April 8, 2018 Unix +Unix April 15, 2018 Unix diff --git a/src/shell.in b/src/shell.in index eb3f8f1..7a3aef5 100644 --- a/src/shell.in +++ b/src/shell.in @@ -19,7 +19,7 @@ _error () _get_solaris_shells () { - # Returns a list of valid Solaris 11.3 shells. The list is taken + # Returns a list of valid Solaris 11.4 shells. The list is taken # from the shells(4) manual and is shortened to only contain one # single instance of each shell. @@ -33,13 +33,9 @@ _get_solaris_shells () /bin/jsh /bin/ksh /bin/ksh93 -/bin/pfbash /bin/pfcsh /bin/pfksh -/bin/pfksh93 /bin/pfsh -/bin/pftcsh -/bin/pfzsh /bin/sh /bin/tcsh /bin/zsh @@ -48,14 +44,15 @@ END_LIST get_shells () { - # Returns a list of installed shells. The shells are validated - # (it's made sure that they are executable files) before returned. + # Returns a list of absolute paths to installed shells. The shells + # are validated (it's made sure that they are executable files) + # before returned. # Rationale: OpenBSD and NetBSD can use "getent shells" to get a # list of shells, but this doesn't work on Ubuntu. Solaris is a # problem since "getent shells" doesn't work and /etc/shells may not # exist. The list of valid Solaris shells is instead taken from - # the shells(4) manual on a vanilla Solaris 11.3 system. + # the shells(4) manual on a vanilla Solaris 11.4 system. # Parameters: none # stdin: unused @@ -84,11 +81,14 @@ get_shells () done } -while getopts 'd:ks:' opt; do +force=0 # when 1, bypasses the call to get_shells +keep=0 # when 1, does not remove working directory when exiting +while getopts 'd:fks:' opt; do case "$opt" in d) tmpwd=$OPTARG - keep=1 ;; - k) keep=1 ;; + keep=1 ;; + f) force=1 ;; + k) keep=1 ;; s) skel=$OPTARG ;; *) _error 'error while parsing the command line\n' exit 1 @@ -102,10 +102,10 @@ if [ -n "$tmpwd" ] && [ -n "$skel" ]; then fi if [ -n "$1" ]; then - shell="${1##*/}" + shell="$1" shift else - shell="${SHELL##*/}" + shell="$SHELL" fi if [ -z "$shell" ]; then @@ -113,17 +113,32 @@ if [ -z "$shell" ]; then exit 1 fi -realshell="$( get_shells | grep "/$shell\$" )" +if [ "$force" -eq 0 ]; then + # Get the absolute path to a real shell. If multiple shells are + # returned from get_shells, we will use the first one. + realshell="$( get_shells | sed -n '\#/'"${shell##*/}"'$#{p;q;}' )" -if [ -z "$realshell" ] || [ ! -x "$realshell" ]; then - _error 'No such shell: %s\n' "$shell" - echo 'Valid shells:' >&2 - get_shells | awk '{ printf("\t%s\n", $0) }' >&2 - exit 1 + if [ -z "$realshell" ]; then + _error 'No such shell: %s\n' "$shell" + echo 'Valid shells:' >&2 + get_shells | awk '{ printf("\t%s\n", $0) }' >&2 + exit 1 + fi +elif [ ! -x "$shell" ]; then + _error 'No such executable: %s\n' "$shell" + exit 1 +else + realshell="$shell" fi if [ -z "$tmpwd" ]; then - tmpwd="$( mktemp -d -t "shell-$shell.XXXXXXXX" )" + template="shell-${shell##*/}" + case "$( uname )" in + NetBSD) ;; # mktemp(1) on NetBSD 7.1.2 adds '.XXXXXXXX' to + # template when using -t + *) template="$template.XXXXXXXX" + esac + tmpwd="$( mktemp -d -t "$template" )" elif [ ! -d "$tmpwd" ]; then if [ -e "$tmpwd" ]; then _error '"%s" exists, but is not a directory\n' "$tmpwd"