davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

new try: pause function for bash script (Solved)

Wed Jan 06, 2016 6:27 pm

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! )
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: new try: pause function for bash script

Wed Jan 06, 2016 6:55 pm

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.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: new try: pause function for bash script

Wed Jan 06, 2016 6:58 pm

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

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: new try: pause function for bash script

Wed Jan 06, 2016 7:00 pm

@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)
Last edited by davenull on Wed Jan 06, 2016 7:06 pm, edited 1 time in total.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: new try: pause function for bash script

Wed Jan 06, 2016 7:02 pm

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...

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: new try: pause function for bash script

Wed Jan 06, 2016 7:06 pm

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!
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

QuietZone
Posts: 89
Joined: Sat Dec 05, 2015 7:13 pm

Re: new try: pause function for bash script

Wed Jan 06, 2016 7:14 pm

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.
"If you haven't got anything nice to say about anybody come sit next to me." — Alice Roosevelt Longworth

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: new try: pause function for bash script

Wed Jan 06, 2016 7:16 pm

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.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: new try: pause function for bash script

Wed Jan 06, 2016 7:17 pm

at admins:
issue is resolved, topic can be locked.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

QuietZone
Posts: 89
Joined: Sat Dec 05, 2015 7:13 pm

Re: new try: pause function for bash script

Wed Jan 06, 2016 7:34 pm

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.
"If you haven't got anything nice to say about anybody come sit next to me." — Alice Roosevelt Longworth

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: new try: pause function for bash script

Wed Jan 06, 2016 7:37 pm

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.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
liz
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 5202
Joined: Thu Jul 28, 2011 7:22 pm
Contact: Website

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

Wed Jan 06, 2016 8:24 pm

Davenull, that's not how it works. Could you stop raising reports please? You're creating unnecessary work.
Director of Communications, Raspberry Pi

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

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

Fri Jan 15, 2016 10:06 am

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.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24129
Joined: Sat Jul 30, 2011 7:41 pm

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

Fri Jan 15, 2016 10:08 am

Spam is off topic posting, this topic has stayed on topic.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

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

Fri Jan 15, 2016 10:36 am

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.
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

Return to “Beginners”