read command in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read command in shell script
# 8  
Old 02-19-2009
hi,


its getting sleep for only 18 seconds not 180 seconds. please help

$cat get.sh
## USAGE: get_key VAR [SECS]
## SECS defaults to 5
get_key()
{
if [ -t 0 ]
then
_STTY=`stty -g`
stty -icanon min 0 time ${2:-$(( 10 * ${2:-5}))} -echo
fi
_KEY=`dd bs=1 count=1 2>/dev/null`
[ -n "$_STTY" ] && stty "$_STTY"
[ -n "$1" ] && eval "$1=\$_KEY"
return 0
}

get_key VAR 180
echo $VAR


$date;sh get.sh ;date
Thu Feb 19 10:23:32 IST 2009


Thu Feb 19 10:23:50 IST 2009
$
# 9  
Old 02-19-2009

Sorry; that should be:

Code:
stty -icanon min 0 time $(( 10 * ${2:-5})) -echo

# 10  
Old 02-22-2009
Quote:
Originally Posted by cfajohnson
Sorry; that should be:

Code:
stty -icanon min 0 time $(( 10 * ${2:-5})) -echo



now it is comming with in second.

$date;sh get.sh ;date
Sun Feb 22 22:54:26 IST 2009

Sun Feb 22 22:54:27 IST 2009
$
# 11  
Old 02-24-2009

I just discovered that the maximum value for the argument to time is 255.

To use something larger, put it in a loop with a smaller value.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell read command is not waiting for user input

Hi, i am working on one automation , for that i have writing one shell program that take user input in "while read line" block. but read command is taking value that is readed by While block. while read line; do command 1; command 2 echo -n "Do you want to continute > " read rsp... (2 Replies)
Discussion started by: ranvijaidba
2 Replies

2. Shell Programming and Scripting

Read input in shell script

I want to write a script that read the input to variable. I want the input screen to have 2 lines, where the values already input will appear above the input line for example if I want to input the words below: like love live life The screen will display like this: 1. Before any input... (8 Replies)
Discussion started by: aydj
8 Replies

3. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

4. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

5. Shell Programming and Scripting

How to read a file through shell script?

hi all, i have to read a file using shell script for example my csv file is like this Tid Inputfille Inputfilepath 1 ABC_20141218.idr /export/home/him60t1/input 2 ABC_20141219.idr /export/home/him60t1/input1 what i have to do is if on my command line i... (1 Reply)
Discussion started by: ramsavi
1 Replies

6. Shell Programming and Scripting

Read webpage from shell script

Hey experts, I am trying to read a webpage and want to search for a text patter (case insensitive). Please help me acquire this. If the text is found i will receive a mail which can be hardcoded in the script. I am not a big fan of using PERL script. Please help. Machine: AIX... (15 Replies)
Discussion started by: bankimmehta
15 Replies

7. Shell Programming and Scripting

How can I send the input of a read line command through a shell script

Hi All, I wish to automate the unix command 'su' through a shell script. I would like to pass the content of a file as password to 'su' command. My script is as below, #! /bin/sh su userA while read line do rpm -ivh $line done < pwd.txt where pwd.txt contains the password of... (6 Replies)
Discussion started by: little_wonder
6 Replies

8. Programming

How to read output of a shell command

Hello All, I have a an application written in C and runing on Red Hat Linux. In my code I have written a command that is fired on the linux shell by using system() function call. Now I need to read the output of this command in my c program and assign it to a variable. Can anyone... (1 Reply)
Discussion started by: shamik
1 Replies

9. Shell Programming and Scripting

Perl script variable to read shell command

Solaris 10 Korn shell ksh, Hi there, I have figured out to get yesterday's date which is using the below command: TZ=GMT+24; date +%d-%b-%Y to get the format of 30-Sep-2008 and TZ=GMT+24; date +%Y%m%d to get the format of 20080930. I need this two format. In my perl script below I need... (4 Replies)
Discussion started by: bulkbiz
4 Replies

10. Shell Programming and Scripting

the shell not pause when execute read command

Hi, i facing a problem when run the script below.. while do if then printf "Please enter a name : " read response # the problem occur here if then ea_ident=${omc_ident} else # # Check that name does not contain invalid... (14 Replies)
Discussion started by: neruppu
14 Replies
Login or Register to Ask a Question