Auto enter for prompt messages


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Auto enter for prompt messages
# 1  
Old 09-03-2016
Auto enter for prompt messages

Hello everybody,

I am coding a script, that allow the user to enter some information using prompt messages, i.e:

Code:
sEpisode=1
read -e -i "$sEpisode" -p "Start download from episode: " downloadFrom
sEpisode="${downloadFrom:-$sEpisode}"

This code allows the user to set the download from which episode, the default value is 1, is there anyway to auto select (auto enter) that default value if the user did not enter anything for 5 seconds delay?

Thanks in advance
# 2  
Old 09-03-2016
The read utility in the standards does not have a timeout option. And, you didn't bother telling us what operating system or shell (and version of that shell) you're using.

You might want to look at the man page on your system for your shell to see if your shell's read built-in has a -t seconds option or some other timeout option (and note the constraints for your shell under which that option will or will not have any effect on that script's execution).
# 3  
Old 09-03-2016
Quote:
Originally Posted by Don Cragun
And, you didn't bother telling us what operating system or shell (and version of that shell) you're using.
Sorry for the inconvenient:

Code:
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.5 LTS
Release:        12.04
Codename:       precise


# which bash
/bin/bash

I looked in the help page for read:

Code:
read: usage: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]

Then I ended up by:

Code:
#! /bin/bash

sEpisode=1
read -e -t 5 -i "$sEpisode" -p "Start download from episode: " downloadFrom
sEpisode="${downloadFrom:-$sEpisode}"

#clear

#echo 'S episode is ' $sEpisode

printf "\n"

eEpisode=7
read -e -t 5 -i "$eEpisode" -p "End download to pisode: " downloadTO
eEpisode="${downloadTo:-$eEpisode}"

clear

echo 'So resuming '
echo 'Start from '$sEpisode
echo 'End to '$eEpisode

Please correct me if I am wrong, or if there is a better way to do it Smilie
# 4  
Old 09-03-2016
The bash read built-in on my system doesn't have a -i init_string option, but after adjusting for that, I found that no matter what value I entered in response to the second prompt, eEpisode was always set to 7. Shells (including bash) distinguish between uppercase and lowercase letters in variable names, so when you read into a variable named downloadTO and then use downloadTo, bash sees downloadTo as an undefined variable. One might assume that you would want to change:
Code:
eEpisode=7
read -e -t 5 -i "$eEpisode" -p "End download to pisode: " downloadTO
eEpisode="${downloadTo:-$eEpisode}"

to:
Code:
eEpisode=7
read -e -t 5 -i "$eEpisode" -p "End download to episode: " downloadTo
eEpisode="${downloadTo:-$eEpisode}"

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 09-05-2016
Sorry for that, I did not pay attention to these errors, I was focussing on timeout stuff Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Auto ENTER key on TERM

I'm working in a UNIX box that's owned by a vendor. They have it set up by State, meaning when I need to program script related to certain States, I type in, for example, "CA", it goes to a whole other terminal: ddqsw:pts/2:login miller CA TERM = ( vt100 ) When I do this I have to hit... (7 Replies)
Discussion started by: shorty
7 Replies

2. Shell Programming and Scripting

Loop logic, enter into respective IF as per enter input file name

have three big data file, however I just need to see the mentioned below one line form the all the file which has SERVER_CONNECTION Value File 1 export SERVER_CONNECTION=//dvlna002:10001/SmartServer File2 export SERVER_CONNECTION=///SmartServer File3 export... (1 Reply)
Discussion started by: Nsharma3006
1 Replies

3. Shell Programming and Scripting

Script to prompt user to enter data

Hi All I have a script that moves files from one dir to another dir based on date, but I would like to change it in a way that whoever is going to run to enter the dates in which files will be removed. This is my script: #!/bin/sh touch -mt 201302250000 /tmp/ref3 touch -mt 201302282359... (14 Replies)
Discussion started by: fretagi
14 Replies

4. Shell Programming and Scripting

how to prompt the user to enter an array in tcsh

Hello, I am writing a script that requires the user to enter a string of numbers: ex: 134 345 865 903 This command only allows for one variable to be entered: set "var" = $< and than once I got the array I want to change it to a list with each input on a different line: ... (1 Reply)
Discussion started by: smarones
1 Replies

5. UNIX for Dummies Questions & Answers

Auto-exit from telnet prompt

Hi, Hope all your are doing well. Need a suggestion from you. I am writing an automated shell script that will effectively check the telnet connectivity with different backends from present deployment server. Ideally, this script reads each backend hostname from a configuration file and fires... (4 Replies)
Discussion started by: bhaskar_m
4 Replies

6. Solaris

Console - root command prompt displayed twice after hitting enter

Dear All, I hope you can help me. I have a pair of E2900's I've inherited. Both running Solaris 9. Both have LOM> consoles. The problem I'm experiencing only occurs when connected to the /dev/console tty. Whenever I hit 'Enter' for a new line, I receive two new lines: - myhost# ... (11 Replies)
Discussion started by: aleith
11 Replies

7. Shell Programming and Scripting

How to enter commands to the command prompt in a program

Hey, So I'm trying to write a program in unix to automate a process for my astrophysics research. Basically I want the program to prompt the user for some information and store the entered string of text as a variable. I know how to do this. This is where I need help: Now lets say I have a... (4 Replies)
Discussion started by: freemoniez
4 Replies

8. Shell Programming and Scripting

enter password at prompt during a script?

I'm using rsync with the "-e ssh" option so of course it asks for a password using a prompt. Is there a way to tell a script to expect a prompt, wait for it, and give a password when it arrives? There is a way to give rsync a password as part of its options using a file, but it only works with... (2 Replies)
Discussion started by: davidstvz
2 Replies

9. AIX

AIX auto delete old mail messages

We have had an issue where the mail file filled up. Is there a setting in sendmail.cf to automatically remove old emails? Say after 14 days. If not is there any way automatically to delete older mail files?? (1 Reply)
Discussion started by: daveisme
1 Replies

10. Shell Programming and Scripting

How to enter if-then condition on command prompt/line ?

Hi I have some trouble entering if-then condition in a single line on a command prompt in csh. Could someone show how does one do that ? eg: source .cshrc; cd $dir; pwd; test -d $backup_dir; if then mkdir -p ${backup_dir}; echo inside loop; fi; echo outside loop; mv -f... (3 Replies)
Discussion started by: mpc8250
3 Replies
Login or Register to Ask a Question