Eieruhr/Timer

#!/usr/bin/env bash
read -p "Timer-Dauer in Sekunden: " wait_time
#wait_time=3
start_time=$(date +%s)

while [ $(( $(date +%s) - start_time )) -lt $wait_time ]; do
    remaining=$(( wait_time - ( $(date +%s) - start_time ) ))
    printf "\rZeit bis Ablauf: %d Sekunde(n)" "$remaining"
done

ffplay failure02.mp3 -nodisp -autoexit -loglevel quiet >/dev/null 2>&1
echo -e "\rDie Zeit ist abgelaufen!"

Text und Input in eine Zeile

following the shell script that I am executing

#!/bin/sh

echo "Enter [y/n] : "
read opt

Its output is

Enter [y/n] : 
Y

I want that the variable should be read on the same line like below

Enter [y/n] : Y

Lösung

Solution: read -p "Enter [y/n] : " opt

From help read:

  -p prompt output the string PROMPT without a trailing newline before
        attempting to read