What is the Linux equivalent to DOS pause?
read
does this:
user@host:~$ read -n1 -r -p "Press any key to continue..." key
[...]
user@host:~$
The -n1
specifies that it only waits for a single character. The -r
puts it into raw mode, which is necessary because otherwise, if you press something like backslash, it doesn't register until you hit the next key. The -p
specifies the prompt, which must be quoted if it contains spaces. The key
argument is only necessary if you want to know which key they pressed, in which case you can access it through $key
.
If you are using Bash, you can also specify a timeout with -t
, which causes read to return a failure when a key isn't pressed. So for example:
read -t5 -n1 -r -p 'Press any key in the next five seconds...' key
if [ "$?" -eq "0" ]; then
echo 'A key was pressed.'
else
echo 'No key was pressed.'
fi
Looking to get a timeout/wait command in linux equivalent to ms-dos
Use this:
sleep 3
so, just use sleep and the given time in seconds.
pause function not working in script that worked in previous server CentOS 9
The error message is from your source
command. Where did variables.sh
come from? You probably need to use the full path name.
Your first line has an error, there should not be a space between the #
and the !
, it should be #!/bin/bash
(optional space after the !
).
The backticks are unnecessary around the function, and the syntax is either:
function pause { ... }
or
pause() { ... }
not both, although that should not generate an error.
Pause programmatically video player mpv
To control mpv
remotely (eg from another terminal session) you can also start it with the option
--input-ipc-server=/tmp/mpvsocket
and control it by issuing commands like this:
echo '{ "command": ["set_property", "pause", true] }' | socat - /tmp/mpvsocket
See man mpv
for (many) more details.
edit: see also mpv --list-properties
edit2: The most simple way I've found to "toggle" pause/play is
{"command": ["cycle", "pause"]}
I'm looking to convert my MS-DOS .bat file into the equivalent linux .sh file
function choice1 {
echo "Do stuff here to create an account"
}
function choice2 {
echo "Get the point?"
}
function choice3 {
exit
}
#### Main
echo "Welcome to OP-SYS Account creation. Please choose which mode you would like to continue in."
echo
echo "[1] Basic Account Creation
[2] Advanced Account Creation
[3] Exit"
echo
read CHOICE #### This loads your choice into a variable
eval choice"$CHOICE" ### This is evaluation awesomeness
Related Topics
How to Find Directory of Some Command
How to Extract Only the Raw Contents of an Elf Section
Why Does Sed Fail with International Characters and How to Fix
Linux Shell Script to Add Leading Zeros to File Names
Receiving Key Press and Key Release Events in Linux Terminal Applications
How Do Unix Domain Sockets Differentiate Between Multiple Clients
How to Install PHP 7 on Ec2 T2.Micro Instance Running Amazon Linux Distro
Crontab Run Every 15 Minutes Except at 3Am
The Concept of 'Hold Space' and 'Pattern Space' in Sed
Replacing Control Character in Sed
Piping Text to an External Program Appends a Trailing Newline
Bash: Infinite Sleep (Infinite Blocking)
Do I Need -D_Reentrant with -Pthreads
Need Text to Speech and Speech Recognition Tools for Linux
Why Doesn't the Cd Command Work in My Shell Program
Command Line: Search and Replace in All Filenames Matched by Grep