Since the variant or version of the script
utility you use does not set the SCRIPT
environment variable within the shell it starts, you can do so yourself. In variants of the utility that sets this variable, it is set to the name of the output file. The following is a short bash
shell function that would mimic that behaviour:
script () {
local outfile="${1:-typescript}"
SCRIPT=$outfile command script "$outfile"
}
This function takes an optional single argument which is the pathname of the output typescript file. If no argument is supplied (or it's empty), the name typescript
is used as the output file. The name of the output file is also available as "$SCRIPT"
in the shell that the utility starts.
You would use this function like
script myfile
or as
script
Alternatively, to allow an arbitrary command at the end of the command line (requires that the first argument is the typescript output file and, just like with the above variation, does not allow for giving options to the real script
command):
script () {
local outfile="${1:-typescript}"
shift
SCRIPT=$outfile command script "$outfile" "$@"
}
You could use this as above, but you could also add a command to run:
script outfile mail -s testmail user@remote.host
util-linux
'sscript
sets this environment variable. If you're in control of the execution, then you might want to try something likeSCRIPT=foo script ...
to set the variable yourself. BSDscript
(on macOS, anyway) does set this variable.script
set the variable.script
. Good to know, thanks for pointing that to me. I guess I will have to stick to using a manual of detecting if I am using ascript
version without that feature.