2

I'm currently doing my coursework for OCR A452 which is a research assessment which wants you to use forums to research the answers to your question. Anyway, my question is that I have created the text of the script but when I want to type it I open the terminal type "script (example) "script Humzah" and then type my code. Then I press control D and it exists but how do I open it back up and run it? That's what I don't understand? Thank you :)

1
  • script is shell session recording tool. It doesn't create shell scripts./
    – muru
    Nov 27, 2015 at 3:14

3 Answers 3

2

To just see what was written, you can use less. We use the raw-control-chars option to convert back any colour codes and other junk that our PS1 contained when we recorded the session.

less -r typescript

script can actually record key-by-key playback though but you have to record timings. You need to alter your recording command slightly:

script -t 2> timingfile

This will output two files:

  • typescript is what is written, and
  • timingfile shows when each key was pressed.

With both files, you can replay the sequence:

scriptreplay -t timingfile typescript
1

I think that script command is a tool to save the session. I think you want to do something different.

I use vim hello.sh to create following bash script:

#!/bin/bash

echo 'Hello World!

and than you can run it by bash hello.sh, or you can set file permission to executable and run ./hello.sh

1

Use nano to make a .sh file, for example:

nano helloworld.sh

Type in something, like:

# Print HelloWorld to the terminal
echo HelloWorld
# Hashtag to comment out code

But at this point, you can't run it, to do that, type in:

chmod +x helloworld.sh

Now you should be able to run it with:

./helloworld.sh

You can also do this the hard way with C, type in

nano main.c

And type in:

#include <stdio.h>
system('echo HelloWorld')

You will need to install a C compiler, so:

sudo apt-get install gcc-4.8

Compile it: gcc main.c -o Hi Run it:

./Hi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .