How do I paste output from the script
command (typescript; "man script") so that it's more readable?
Script started on 2017-10-27 06:20:56-0700
]0;thufir@dur: ~/IdeaProjects[01;32mthufir@dur[00m:[01;34m~/IdeaProjects[00m$
]0;thufir@dur: ~/IdeaProjects[01;32mthufir@dur[00m:[01;34m~/IdeaProjects[00m$ tree
[01;34m.[00m
├── kotlin
└── [01;34mkotlinHelloWorld[00m
├── kotlinHelloWorld.iml
├── [01;34mout[00m
│ └── [01;34mproduction[00m
│ └── [01;34mkotlinHelloWorld[00m
└── [01;34msrc[00m
└── Main.kt
5 directories, 3 files
]0;thufir@dur: ~/IdeaProjects[01;32mthufir@dur[00m:[01;34m~/IdeaProjects[00m$
]0;thufir@dur: ~/IdeaProjects[01;32mthufir@dur[00m:[01;34m~/IdeaProjects[00m$ cat kotlinHelloWorld/src/Main.kt
class Main {
fun main(args: Array<String>) {
println("Hello, world!")
}
}]0;thufir@dur: ~/IdeaProjects[01;32mthufir@dur[00m:[01;34m~/IdeaProjects[00m$
]0;thufir@dur: ~/IdeaProjects[01;32mthufir@dur[00m:[01;34m~/IdeaProjects[00m$ exit
exit
Script done on 2017-10-27 06:21:19-0700
The gibberish (?) is reflective of, in this case, gnome-terminal
color. Yes, by using a different shell, different console, etc it's possible to not generate that "gibberish". The question is how to nicely either get the script
command to not record them, or get the pastebin
utility (or similar, such as gist-paste
) to handle them "nicely".
firstly, thank you for the responses. Secondly, I hope that this doesn't muddy the waters:
thufir@dur:~$
thufir@dur:~$ script trying_to_eliminate_control_chars.txt
Script started, file is trying_to_eliminate_control_chars.txt
thufir@dur:~$
thufir@dur:~$ echo "hi"
hi
thufir@dur:~$
thufir@dur:~$ echo "hi"
hi
thufir@dur:~$
thufir@dur:~$ echo "hmm"
hmm
thufir@dur:~$
thufir@dur:~$ exit
exit
Script done, file is trying_to_eliminate_control_chars.txt
thufir@dur:~$
thufir@dur:~$ cat trying_to_eliminate_control_chars.txt > foo.txt
thufir@dur:~$
thufir@dur:~$ cat foo.txt
Script started on 2017-10-31 17:51:29-0700
thufir@dur:~$
thufir@dur:~$ echo "hi"
hi
thufir@dur:~$
thufir@dur:~$ echo "hi"
hi
thufir@dur:~$
thufir@dur:~$ echo "hmm"
hmm
thufir@dur:~$
thufir@dur:~$ exit
exit
Script done on 2017-10-31 17:51:47-0700
thufir@dur:~$
thufir@dur:~$ cat trying_to_eliminate_control_chars.txt
Script started on 2017-10-31 17:51:29-0700
thufir@dur:~$
thufir@dur:~$ echo "hi"
hi
thufir@dur:~$
thufir@dur:~$ echo "hi"
hi
thufir@dur:~$
thufir@dur:~$ echo "hmm"
hmm
thufir@dur:~$
thufir@dur:~$ exit
exit
Script done on 2017-10-31 17:51:47-0700
thufir@dur:~$
thufir@dur:~$ pastebin foo.txt
pastebin: command not found
thufir@dur:~$
thufir@dur:~$ pastebinit foo.txt
http://paste.ubuntu.com/25862228/
thufir@dur:~$
While you may naively expect the above paste not to have control characters, it does. This is because the terminal itself (or so I infer) is handling/hiding them.
Very low-level text files, etc, at play. Plus very detailed knowledge of how terminal emulation works. A bit beyond me, frankly.
Best Answer
I've tested all solution, provided within the references below, to process and clean the output file of the command
script
from special characters.On my Ubuntu 16.04, only the following solution provides a satisfactory result:
Or you can pipe the output directly to the upload client program:
The above command works with
pastebinit
, so install it:References:
Create a 'script to pastebin' custom command - spaste
I would suggest to create a custom command, based on the above solution. Let's name it spaste.
1. Create executable script file, called
spaste
, that is located in/usr/local/bin
to be accessible as shell command:nano
: paste Shift Ins; save CtrlO Enter; exit CtrlX.2. Explanation:
When you execute the new command
spaste
it will call the commandscript
and will assign to it the user's input parameters. So the call syntax is the same as the commandscript
- seescript --help
or typespaste --help
for more details:When you type
exit
to exit from the session of thescript
command,spaste
will process the output file ofscript
to the commandpastebinit
.In result
pastebinit
will return a link to the uploaded content of thescript
's output file.The new command
spaste
has few different modes how to handle the link returned bypastebinit
. These modes could be switched by export of the variable$SPASTE_MODE
with different values before the execution of the commandspaste
:The available modes are:
SPASTE_MODE=chromium
- will open the returned link in Chromium.SPASTE_MODE=firefox
- will open the returned link in FireFox.SPASTE_MODE=lynx
- will open the returned link Lynx (terminal browser).SPASTE_MODE=upload
- just will output the returned link.SPASTE_MODE=
- will not return a link; just will process the content of the output file.You could export your favourite mode from the
~/.bashrc
file, for example add to its bottom the following line:3. Demonstration of usage: