Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Need help with repeating variables in a shell script Post 302760775 by ricco19 on Thursday 24th of January 2013 03:04:29 PM
Old 01-24-2013
Quote:
This uses the terminal's built-in properties for read timeouts:

Code:
#!/bin/sh

old_tty_settings=$(stty -g)
# This restores the terminal settings even if you quit with ctrl-C
trap "stty $old_tty_settings" EXIT

stty -echo -icanon min 1 time 1

STRING=$(dd if=/dev/tty count=1 2>/dev/null)

echo "Read $STRING"

The terminal waits for multiple keystrokes yet times out quickly, and no loop is required. I can't type fast enough to get more than one letter in, but if I paste something to the terminal it gets the whole thing.

You still have to use dd, not the read builtin, because read messes with the terminal device too, undoing all the fancy settings you've been trying to arrange.
This is a good solution and it works well. Thanks.

Yeah we knew we could make a working c program, but just using a script makes it a simpler process.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script Variables

HI guys I need to store the output of a sql query in a variable, can you tell me how to do that eg) select count(*) from s_escl_req $count = count(*) from s_escl_req how would i store the count(*) from the sql statement in a variable called $count. thanks (3 Replies)
Discussion started by: ragha81
3 Replies

2. Shell Programming and Scripting

Repeating variables in the code

Hi all, I had written 3 KSH scripts for different functionalities. In all these 3 files there are some 30 variables in common. So I want to reduce the code by placing these variables in a common properties file named (dataload.prop/dataload.parms/dataload.txt) or txt file and access it... (1 Reply)
Discussion started by: mahalakshmi
1 Replies

3. Shell Programming and Scripting

Accessing variables of one shell script in another shell script

I have a variable $exe in a shell script file a.sh which I need to access in another shell script file b.sh. How can I do that? :rolleyes: Thanks!! (2 Replies)
Discussion started by: looza
2 Replies

4. Shell Programming and Scripting

Accessing variables of one shell script in another shell script

Hi All, I have a shell script called sample1.sh where I have 2 variables. Now I have another shell script called sample2.sh. I want the variables in sample1.sh to be available to sample2.sh. For example. In sample1.sh I am finding the sum of 2 numbers namely a and b. Now I want to access... (2 Replies)
Discussion started by: rsendhilmani
2 Replies

5. Shell Programming and Scripting

Variables in shell script

mysqldump --compact --add-drop-table -h192.168.150.80 -uroot -p somePass $combined | sed '/$combined/$table/g' | mysql $databaseThe sed part is not working from the above statement. The variables combined and table are already defined and instead of showing the actual variable, it is executing the... (4 Replies)
Discussion started by: shantanuo
4 Replies

6. Shell Programming and Scripting

Shell script to extract data in repeating tags from xml

Hi, I am new to shell scripting. I need to extract data between repeating tags from an xml file and store the data in an array to process it further. <ns1:root xmlns:ns1="http://example.com/config"> <ns1:interface>in1</ns1:interface> <ns1:operation attribute1="true" attribute2="abd"... (2 Replies)
Discussion started by: sailendra
2 Replies

7. UNIX for Dummies Questions & Answers

Adding variables to repeating strings

Hello, I want to add a letter to the end of a string if it repeats in a column. so if I have a file like this: DOG001 DOG0023 DOG004 DOG001 DOG0023 DOG001 the output should look like this: DOG001-a DOG0023-a DOG004 DOG001-b (15 Replies)
Discussion started by: verse123
15 Replies

8. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

9. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

10. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies
INIT(8) 						      System Manager's Manual							   INIT(8)

NAME
init - grandparent of all processes DESCRIPTION
The first program started by Minix is init. The actions performed by init can be summarized by this pseudo shell program: # Open 0, 1, 2. exec </dev/null >/dev/log 2>&1 # Run the system initialization script. sh /etc/rc $bootopts >/etc/utmp echo reboot >>/usr/adm/wtmp while :; do # Wait for a process to exit, but don't always block. wait # Record logout. (Not in this dumb way, of course.) if "pid is in my tables" $pid then echo "logout $pid" >/etc/utmp echo "logout $pid" >>/usr/adm/wtmp fi # Start a new session. while read line type getty init do if idle $line then $init ... <$tty >$tty $getty <$tty >$tty 2>&1 & pid=$! "add pid to tables" $pid echo "login $line $pid" >/etc/utmp echo "login $line $pid" >>/usr/adm/wtmp fi done < /dev/ttytab done The first action of init is to run /etc/rc to initialize the system as described in boot(8). Init then enters its main loop where it waits for processes to exit, and starts processes on each enabled terminal line. The file /etc/ttytab contains a list of terminal devices, their terminal types, the program to execute on them to allow one to login (usually getty(8)), and the program to execute first to initialize the line (usually stty(1)). These fields may be left out to indicate that a line is disabled or that initialization is not necessary. The commands are searched using the path /sbin:/bin:/usr/sbin:/usr/bin. Init accepts several signals that must be sent to process id 1. (It is the first process, so natually its process id is 1.) The signals are: SIGHUP When receiving a hangup signal, init will forget about errors and rescan ttytab for processes to execute. Init normally rescans ttytab each time it feels the need to respawn a process, so the hangup signal is only needed if a line has been shut down, or after a terminate signal. Note that after turning a line off you will have to kill the process running on that line manually, init doesn't do that for you. SIGTERM Normally sent by programs that halt or reboot Minix. Causes init to stop spawning new processes. SIGABRT Sent by the keyboard driver when the CTRL-ALT-DEL key combination is typed. Causes init to run the shutdown command. A second abort signal makes init halt the system directly with a system call. The keyboard driver halts the system, without a sync, after the third CTRL-ALT-DEL. Minix vs. Minix-vmd There are a few differences between standard Minix and Minix-vmd on how init is run. The /etc/rc file is executed under standard Minix with input connected to /dev/console, but under Minix-vmd this is still /dev/null. This means that under Minix-vmd processes must be reconnected to /dev/console with the intr program if they need user interaction. Minix-vmd passes the value of the bootopts boot variable to /etc/rc. Standard Minix does not. FILES
/etc/ttytab List of terminals devices. /etc/utmp List of currently logged in users. /usr/adm/wtmp Login/logout history. SEE ALSO
ttytab(5), utmp(5), getty(8), stty(1), boot(8). AUTHOR
Kees J. Bot (kjb@cs.vu.nl) INIT(8)
All times are GMT -4. The time now is 07:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy