[Solved] Adding start-and-stop halts to an automatic script

Asked by Julianloui

2014-09-21

How can I add start-and-stop commands to an otherwise automatic script in order to gain control over the running of the script. The show-and-tell script I am developing uses only shotwell and espeak repeatively. I would like to insert proper commands in between so that the script will continue to the next 'frame' only if I hit ENTER or some other key. This will be better than using the command line to stop the script and its numerous annoying orphan processes when a need arises to stop the script immediately.

An afterthought: I 've just realized that my wish if realized may ruin the appearance of my script's display and flow.

However, any help and advice will be greatly appreciated.

Julianloui

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:
Revision history for this message
Best Manfred Hampl (m-hampl) said :
#1

The read command in a bash script might do what you want, e.g.

#!/bin/bash

#first part of script
echo "results of first step"

read -p "hit Enter to continue or ctrl-C to abort:" response

#second part of script
#...

Or you can select different actions depending on the value entered

#!/bin/bash

#first part of script
echo "results of first step"

read -p "Enter 1 to continue or anything else to abort:" response

if [ $response -eq 1 ]
then
  # next step
else
  exit
fi

More information is available on the web, just search for "bash script read" or something like that.

Revision history for this message
Julianloui (julianloui) said :
#2

Thanks Manfred Hampl, that solved my question.