Read input in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read input in shell script
# 8  
Old 06-17-2015
Well you been told where to look, and showed how it could work.
Since you love scripts, why dont you try yourself a bit?

I wonder that you state that clear would not work for you...
# 9  
Old 06-17-2015
Assuming TERM is set in your environment to correctly indicate your terminal or terminal emulator type, the following should work:
Code:
#!/usr/bin/ksh
addword() {
	tput clear
	if [ "$input" != "" ]
	then	if [ "$output" != "" ]
		then	output="$output $input"
		else	output="$input"
		fi
	fi
	printf '%s\nInput words (ctl-d when done): ' "$output"
	read -r input
}
input=
output=
while addword
do	:
done
echo

Although written and tested using ksh, this should work with any POSIX-conforming shell (e.g., ash, bash, dash, ksh, zsh, etc.).
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script does not read input file

Hi everyone, I have problems with this script. This script should check for a folder for each server in the list of the list.txt file. The script only checks the first host, and then exits, why? #!/bin/bash file='/etc/list.txt' while read line; do echo $line if ssh root@$line "stat /var >... (2 Replies)
Discussion started by: nashrik
2 Replies

2. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

3. 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

4. Shell Programming and Scripting

Read input from file and pass it to sub shell

i have a scenario where in i have to monitor jobs which run in different servers, The job details(job name, host server, etc) are present in a dat file. I have written a script a script which reads the details from the dat file and calls a local method where the job monitoring logic is present.... (2 Replies)
Discussion started by: abubucker0
2 Replies

5. Shell Programming and Scripting

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate... (5 Replies)
Discussion started by: casmo
5 Replies

6. Shell Programming and Scripting

Read input and output redirection filename within a script

Hello everyone, My requirement is that within a script I need to construct the command line exactly that it was invoked with. For example : sh a.sh arg1 arg2 arg3 < input.txt > output.txt Now within a.sh, I construct a file which has these contents " sh a.sh arg1 arg2 arg3 < input.txt >... (8 Replies)
Discussion started by: hedonist12
8 Replies

7. Shell Programming and Scripting

need shell or Perl script to read multiple input

I need shell 0r Perl script to read multiple input and do something and come out example: echo “ enter the host names separated by space “ read servers foreach @servers { do do something done} Here host names like host1 host2 host3 . . . . . . . so on Please help me... (8 Replies)
Discussion started by: sreedhargouda
8 Replies

8. Shell Programming and Scripting

Need a script that will read from 2 input file

Hi Everyone. I am new in this scripting world. I need to know about script that I can use on linux/sun operating systems. I have 2 input file. File 1: Its has an header information and then data in 2 different columns. File 2 : It has data in 9 different columns/ I need an script that... (3 Replies)
Discussion started by: syahmed
3 Replies

9. 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

10. Shell Programming and Scripting

read a file as input and pass each line to another script

Hi, I am trying to write a ftp script which will read a file for filenames and ftp those files to another server. Here's my ftp script, but it's scanning the current directory for file names. My question is how can I pass multiple files (these files will have the name of data files that need to... (0 Replies)
Discussion started by: sajjad02
0 Replies
Login or Register to Ask a Question