Script (Unix)
   HOME

TheInfoList



OR:

The script command is a
Unix utility Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and o ...
that records a
terminal Terminal may refer to: Computing Hardware * Terminal (electronics), a device for joining electrical circuits together * Terminal (telecommunication), a device communicating over a line * Computer terminal, a set of primary input and output dev ...
session. It dates back to the 1979 3.0 BSD.


Usage

A script session is captured in file name by default; to specify a different filename follow the command with a space and the filename as such: . The recorded format of consists of plain-text timing information (for the whole session) and verbatim command output, including whatever
ANSI escape code ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals and terminal emulators. Certain sequences of bytes, most starting with an ASCII escape char ...
the program has printed for formatting. It uses a pseudoterminal for this purpose, so programs act exactly as if they were on a terminal. The
util-linux is a standard package distributed by the Linux Kernel Organization for use as part of the Linux operating system. A fork, (with meaning "next generation"), was created when development stalled, but has been renamed back to , and is the offi ...
command offers a replay function to its script, which supports using an extra timing file for character-level information. Some online services, such as the now-defunct shelr.tv, can also show the format as a low-bandwidth alternative to video screencasts.


Problems with ''script''

One of the problems with the script command is that it only allows logging of a child process; and often there is a need to log the command in the current process without spawning a new process, such as when automation of a script is needed that can log its own output. The
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, an ...
operating systems make this possible by use of
pipe Pipe(s), PIPE(S) or piping may refer to: Objects * Pipe (fluid conveyance), a hollow cylinder following certain dimension rules ** Piping, the use of pipes in industry * Smoking pipe ** Tobacco pipe * Half-pipe and quarter pipe, semi-circular ...
s and redirects. Consider the following model examples: ;Bourne shell All shells related to Bourne shell (namely: sh, bash, and ksh) allow the stdout and stderr to be attached to a
named pipe In computing, a named pipe (also known as a FIFO for its behavior) is an extension to the traditional pipe concept on Unix and Unix-like systems, and is one of the methods of inter-process communication (IPC). The concept is also found in OS/2 and ...
and redirected to the tee command. Example LOGNAME="script" rm -f $LOGNAME.p $LOGNAME.log mknod $LOGNAME.p p tee <$LOGNAME.p $LOGNAME.log & exec >$LOGNAME.p 2>&1 The above script records to all output of the command. However, some interactive programs (such as
python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
) do not echo their standard input when run under the resulting shell, although they do when run under the script command, again due to the detection of a terminal.


Alternatives to Script Command

The ttyrec program from 2000 provides the same kind of functionality and offers several bindings. The timing is similar to util-linux. A more modern take on the concept is "asciicast" JSON, used by asciinema.


See also

*
Command line interpreter A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
*
Shebang (Unix) In computing, a shebang is the character sequence consisting of the characters number sign and exclamation mark () at the beginning of a script. It is also called sharp-exclamation, sha-bang, hashbang, pound-bang, or hash-pling. When a text fil ...
* Bourne shell * Bourne-Again shell *
C shell The C shell (csh or the improved version, tcsh) is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of th ...
*
Python (programming language) Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. Python is dynamically-typed and garbage-collected. It supports multiple programming p ...
*
Filename extension A filename extension, file name extension or file extension is a suffix to the name of a computer file (e.g., .txt, .docx, .md). The extension indicates a characteristic of the file contents or its intended use. A filename extension is typically ...
, ''Command Name Issues'' section *
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offic ...
*
Scripting language A scripting language or script language is a programming language that is used to manipulate, customize, and automate the facilities of an existing system. Scripting languages are usually interpreted at runtime rather than compiled. A scripting ...
*
Unix shell A Unix shell is a command-line interpreter or shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command language and a scripting language, and is used by the operating syste ...


References

Unix software {{unix-stub