LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-07-2011, 12:15 PM   #1
Nathan.eth0
LQ Newbie
 
Registered: Apr 2011
Posts: 21

Rep: Reputation: 2
Exclamation [SOLVED] How do I pause a batch script?


Hello World!
As you already know there's a command in the "BATCH" language named pause which causes the program to get any random character and then continues the scripts (which is mostly used to keep a script running and preventing it to do its work and close the command prompt). Something like the "getch".
Is there anything similar to this at bash?
IMPORTANT NOTE: I don't want my script to stay opened, I want it to get a character (without hitting enter) and continue executing the rest of the script so please don't reply "Tick the keep the terminal opened option" or "Use read".
Thanks

Last edited by Nathan.eth0; 04-07-2011 at 12:32 PM.
 
Old 04-07-2011, 12:16 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Do you mean "READ"?

Quote:
#!/bin/bash
echo Please, enter your name
read NAME
echo "Hi $NAME!"
 
Old 04-07-2011, 12:19 PM   #3
Nathan.eth0
LQ Newbie
 
Registered: Apr 2011
Posts: 21

Original Poster
Rep: Reputation: 2
No, I said getting a character and not hitting enter, like "press any key to continue..."
And if you read what I wrote::
Quote:
IMPORTANT NOTE: I don't want my script to stay opened, I want it to get a character (without hitting enter) and continue executing the rest of the script so please don't reply "Tick the keep the terminal opened option" or "Use read".
 
Old 04-07-2011, 12:23 PM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Do you mean "READ"?

Code:
read -n 1 character
echo $character
 
Old 04-07-2011, 12:32 PM   #5
Nathan.eth0
LQ Newbie
 
Registered: Apr 2011
Posts: 21

Original Poster
Rep: Reputation: 2
LOL
You're good ;D
 
Old 04-07-2011, 04:47 PM   #6
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 386

Rep: Reputation: 43
Here's a sample that will give you the iconic spinner and then quit after entering in any key

Code:
#!/bin/bash
#
# user prompt
prompt="press any key to continue?" 
spinner="\|/-" 	 # spinner
chars=1		 # number of characters to display
delay=.10      	 # time in seconds between characters
clearline="\e[K" # clear to end of line (ANSI terminal)
CR="\r"          # carriage return

# loop until user presses a key
until read -sn1 -t$delay -p "$prompt" var
do
  printf "  %.${chars}s$CR" "$spinner"
  temp=${spinner#?}               ## remove first character from $spinner
  spinner=$temp${spinner%"$temp"} ## and add it to the end
done
printf "$CR$clearline"
echo "$var"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Play/Pause Script for MPD drj000 Programming 3 02-15-2013 02:44 AM
Pause a process from a bash script danko101 Programming 6 10-29-2009 10:45 AM
Is there a way to do a pause in a perl script? abefroman Programming 2 01-29-2009 01:44 PM
pause search script paul_mat Linux - Software 3 05-25-2006 11:56 PM
.s batch file commands - pause??? webamoeba Linux - Newbie 2 01-27-2004 11:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration