Page 1 of 1

new try: pause function for bash script (Solved)

Posted: Wed Jan 06, 2016 6:27 pm
by davenull
as the old topic has been closed without resolving the issue:
one more try.
I need sort of pause function for a bash script.
Links which have been provided don't work and a working command has not been shown.

I tried:
read -n1 -r -p key
read -rsp $'Press any key to continue...\n' -n 1 key
read -p "$*"

but the script always runs through - no clue why.

this is the script...

Code: Select all

 cp -av  /home/pi/programs/ /home/pi/raspi_sav/
 cp -av  /home/pi/scripts/ /home/pi/raspi_sav/ 
 cp -av  /home/pi/openvg/ /home/pi/raspi_sav/ 
 cp -av  /home/pi/PIGPIO/ /home/pi/raspi_sav/ 

if [ -e /media/pi/USB120DRV/Akten ]; then
  cp -av /home/pi/raspi_sav/ /media/pi/USB120DRV/Akten/
else
  echo "The folder /media/pi/USB120DRV/Akten does not exist"
fi
read -p -r -n1 key

file copy is ok, but always runs through.

(remark: anyone who does not want to answer is not forced to do so, so please simply ignore it then! )

Re: new try: pause function for bash script

Posted: Wed Jan 06, 2016 6:55 pm
by jojopi
All your attempts use bash-specific options to read, which will fail if the script is running in /bin/sh. Since "press any key" already does not work where the any key is Ctrl, CapsLock, etc, I suggest you go with nice, portable:

Code: Select all

echo press Enter
read reply
The other reason read might fail is if the script does not have a standard input stream, because of the way it is started.

Re: new try: pause function for bash script

Posted: Wed Jan 06, 2016 6:58 pm
by rurwin
The version you have at the moment definitely isn't right -- the parameter after -p must be the string to use as a prompt -- but it does pause and wait for a key.

How are you calling this script? Is its input stream redirected?

Try this one:

Code: Select all

read -rsp $'Press any key to continue...\n' -n 1 key < /dev/tty

Re: new try: pause function for bash script

Posted: Wed Jan 06, 2016 7:00 pm
by davenull
@jojopi:

YES !

THAT was finally a really helpful answer!
Thank you very much!

:geek:


@rurwin:
yes, I always pointed out that I start this script from the file manager by double-click!
ps,
your comand does not work (illegal option -s -n ... whatever)

Re: new try: pause function for bash script

Posted: Wed Jan 06, 2016 7:02 pm
by rurwin
Try the version I posted above (I edited the post).

/dev/tty is the terminal even if input is redirected. Not sure if it will help from a double-click...

Re: new try: pause function for bash script

Posted: Wed Jan 06, 2016 7:06 pm
by davenull
your comand does not work (illegal option -s -n ... whatever)

I'll stay with
echo press Enter
read reply

that's handy and simple!
thank you nevertheless!

Re: new try: pause function for bash script

Posted: Wed Jan 06, 2016 7:14 pm
by QuietZone
It is quite likely that what the OP is really looking for is:

Code: Select all

xmessage
Or, maybe:

Code: Select all

whiptail
whiptail (or its predecessor, dialog) is nice - except for the fact that it covers the screen, so it kinda defeats the purpose, which is to be able to see the final output of the script before the window is closed.

Re: new try: pause function for bash script

Posted: Wed Jan 06, 2016 7:16 pm
by davenull
actually the DOS Batch command
pause
was what I tried to mimic but didn't work

but I'm fine with

echo press Enter
read reply

thank you nevertheless.

Re: new try: pause function for bash script

Posted: Wed Jan 06, 2016 7:17 pm
by davenull
at admins:
issue is resolved, topic can be locked.

Re: new try: pause function for bash script

Posted: Wed Jan 06, 2016 7:34 pm
by QuietZone
Davenull,
when you are replying to a specific person in a thread (as I am doing here), it is a good idea to include some indication, in the text of your post, as to whom it is that you are responding to.

Thank you.

Re: new try: pause function for bash script

Posted: Wed Jan 06, 2016 7:37 pm
by davenull
maybe yes, maybe not.
OT messages are appreciated via PM to keep the thread clean.


anyway, the issue is resolved.

@admins:
thread can be closed.

Re: new try: pause function for bash script (Solved)

Posted: Wed Jan 06, 2016 8:24 pm
by liz
Davenull, that's not how it works. Could you stop raising reports please? You're creating unnecessary work.

Re: new try: pause function for bash script (Solved)

Posted: Fri Jan 15, 2016 10:06 am
by davenull
I must have misunderstood something -
I thought the report button to report spam and trolls (CMIIW) is intended to report spam and trolls.
Sorry if I missed something.

Re: new try: pause function for bash script (Solved)

Posted: Fri Jan 15, 2016 10:08 am
by jamesh
Spam is off topic posting, this topic has stayed on topic.

Re: new try: pause function for bash script (Solved)

Posted: Fri Jan 15, 2016 10:36 am
by davenull
ok, sorry if I missed something.
Davenull,
when you are replying to a specific person in a thread (as I am doing here), it is a good idea to include some indication, in the text of your post, as to whom it is that you are responding to.

Thank you.