On Wed, Dec 13, 2017 at 05:45:25PM +0100, Paul de Weerd wrote:
> 
> Index: script.1
> ===================================================================
> RCS file: /cvs/src/usr.bin/script/script.1,v
> retrieving revision 1.14
> diff -u -p -r1.14 script.1
> --- script.1  15 Jan 2012 20:06:40 -0000      1.14
> +++ script.1  13 Dec 2017 12:27:32 -0000
> @@ -39,6 +39,7 @@
>  .Sh SYNOPSIS
>  .Nm script
>  .Op Fl a
> +.Op Fl c Ar command
>  .Op Ar file
>  .Sh DESCRIPTION
>  .Nm
> @@ -65,6 +66,13 @@ Append the output to
>  or
>  .Pa typescript ,
>  retaining the prior contents.
> +.It Fl c Ar command
> +Run
> +.Ar command
> +instead of an interactive shell.
> +To run a

i'd remove "a", but it's preference only - your choice.

> +.Ar command
> +with its own arguments, enclose it in quotes.

and s/its own//

>  .El
>  .Pp
>  The script ends when the forked shell exits (a control-D
> Index: script.c
> ===================================================================

you want to update usage() too.

jmc

> RCS file: /cvs/src/usr.bin/script/script.c,v
> retrieving revision 1.33
> diff -u -p -r1.33 script.c
> --- script.c  12 Apr 2017 14:49:05 -0000      1.33
> +++ script.c  13 Dec 2017 12:15:20 -0000
> @@ -89,7 +89,7 @@ int         istty;
>  
>  __dead void done(int);
>  void dooutput(void);
> -void doshell(void);
> +void doshell(char *);
>  void fail(void);
>  void finish(int);
>  void scriptflush(int);
> @@ -102,15 +102,20 @@ main(int argc, char *argv[])
>       struct sigaction sa;
>       struct winsize win;
>       char ibuf[BUFSIZ];
> +     char *cmd;
>       ssize_t cc, off;
>       int aflg, ch;
>  
> +     cmd = NULL;
>       aflg = 0;
> -     while ((ch = getopt(argc, argv, "a")) != -1)
> +     while ((ch = getopt(argc, argv, "ac:")) != -1)
>               switch(ch) {
>               case 'a':
>                       aflg = 1;
>                       break;
> +             case 'c':
> +                     cmd = optarg;
> +                     break;
>               default:
>                       fprintf(stderr, "usage: %s [-a] [file]\n", __progname);
>                       exit(1);
> @@ -163,7 +168,7 @@ main(int argc, char *argv[])
>               if (child)
>                       dooutput();
>               else
> -                     doshell();
> +                     doshell(cmd);
>       }
>  
>       bzero(&sa, sizeof sa);
> @@ -302,9 +307,10 @@ scriptflush(int signo)
>  }
>  
>  void
> -doshell(void)
> +doshell(char *cmd)
>  {
>       char *shell;
> +     char *argp[] = {"sh", "-c", NULL, NULL};
>  
>       shell = getenv("SHELL");
>       if (shell == NULL)
> @@ -313,8 +319,15 @@ doshell(void)
>       (void)close(master);
>       (void)fclose(fscript);
>       login_tty(slave);
> -     execl(shell, shell, "-i", (char *)NULL);
> -     warn("%s", shell);
> +
> +     if (cmd != NULL) {
> +             argp[2] = cmd;
> +             execv(_PATH_BSHELL, argp);
> +             warn("unable to execute %s", _PATH_BSHELL);
> +     } else {
> +             execl(shell, shell, "-i", (char *)NULL);
> +             warn("%s", shell);
> +     }
>       fail();
>  }
>  
> 
> -- 
> >++++++++[<++++++++++>-]<+++++++.>+++[<------>-]<.>+++[<+
> +++++++++++>-]<.>++[<------------>-]<+.--------------.[-]
>                  http://www.weirdnet.nl/                 
> 

Reply via email to