Login or Register to Ask a Question and Join Our Community


Reading input to create a variable in a script?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Reading input to create a variable in a script?
# 1  
Old 12-13-2001
Reading input to create a variable in a script?

I would like to prompt for input and then use it as a variable in a script.

Something like this.

#!/bin/ksh
echo "What is your name?: \c"
read response

echo "Your name is $reply" >file.txt
done
exit 0


What am I missing?

Thanks,
# 2  
Old 12-13-2001
MySQL

does this work for you?

#!/bin/ksh
echo "What is your name?: \c"
read response

echo "Your name is $response" >file.txt
exit 0


works for me
# 3  
Old 12-13-2001
Works now

I didn't need done evidently.
# 4  
Old 12-14-2001
Well, and also, did you notice this?:

Quote:
read response

echo "Your name is $reply" >file.txt
You defined "response", but echo'd "reply".
# 5  
Old 12-14-2001
Reading input to create a variable in a script?

---------------------
If you will use REPLY. (Give read no variable)
echo "What is your name ?" ; read
echo $REPLY #use big letters
---------------------
If you will use a variable
echo "What is your name ?" ; read TheNameIs
echo $TheNameIs
---------------------
# 6  
Old 12-14-2001
?

Yes, I noticed that response and reply were typed incorrectly. That wasn't the actual code but an example I used when typing the message to this forum. Good catch.


Thanks for the tips. My script is running great.
# 7  
Old 12-14-2001
_rd

_rd,

So the difference between using any given string name and using $REPLY is that REPLY doesn't set a variable?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading CLI input for script

I've always written scripts where the user executes the script and I prompt them for what they want to do. But I'm trying to write a script where root executes the script 'lock' or its hard-link 'unlock' and the script will passwd -l or passwd -u an account depending on the choice. What would... (3 Replies)
Discussion started by: ADay2Long
3 Replies

2. Shell Programming and Scripting

Need to develop a script to create a report reading multiple server logs

I am currently trying to develop a script to connect to mulltiple servers, reading specifc data from log files on the servers and append the data from each file into a single tab delimited row. So, at the end I am planning to have a report with all the extracted data with each row per server. I am... (5 Replies)
Discussion started by: scriptingnewbie
5 Replies

3. Shell Programming and Scripting

Perl Script Not Reading Input Files Correctly

This is one of the strangest things that's happening to me. I'm writing a new Perl script that is trying to read a file. The file is originally in .mof format, but I also saved the contents into a .txt file. As a simple test, I wrote this: #!/user/bin/perl -w use strict; ... (3 Replies)
Discussion started by: kooshi
3 Replies

4. Shell Programming and Scripting

[SH] Problem reading input in script

Alright, so the goal of my script is to read text from standard input and store it into a file using the ex-editor: so far i've got this, but it doesn't work. #!/bin/s read text ex $1 >> HERE text HERE I don't get any errors either, so i don't know what i'm doing wrong. (7 Replies)
Discussion started by: Bertieboy7
7 Replies

5. Shell Programming and Scripting

awk script - reading input lines

Can I do something like, if($0==/^int.*$/) { print "Declaration" } for an input like: int a=5; If the syntax is right, it is not working for me, but I am not sure about the syntax. Please help. Thanks, Prasanna (1 Reply)
Discussion started by: prasanna1157
1 Replies

6. Shell Programming and Scripting

Reading from a File and Using as an Input variable

I need to know how the the string constant from Input File should be read and provide as input data for the script . INPUT FILE CONST VARIABLE myname=/root/dir/syslog/myname1 myname=/root/dir/syslog/myname2 myname=/root/dir/syslog/myname3 urname=/root/dir/syslog/urname1... (6 Replies)
Discussion started by: baraghun
6 Replies

7. Shell Programming and Scripting

Reading content of a variable to create a new one?

Hello. I've written up a script, that populates a variable with a list of tapes returned from my library. For example: 701940L3,701941L3,701942L3,701943L3,701944L3,701945L3,701946L3,701947L3,701948L3 So now, the variable "TAPELIST" contains those numbers, delimited by commas. I'd like to... (6 Replies)
Discussion started by: Stephan
6 Replies

8. Shell Programming and Scripting

Create Multiple files by reading a input file and changing the contents

Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me . Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer. I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies

9. Shell Programming and Scripting

Script for reading an input file

#!/bin/sh rpt="/export/home/legato/rpt_offsite"/test_eject.tape cat <$rpt while read line do echo $line perform routine done I am trying to read the contents of this file line by line and perform a routine for each line read. The file contents are numbers.. What is wrong with my... (1 Reply)
Discussion started by: gzs553
1 Replies

10. UNIX for Dummies Questions & Answers

Reading Input in a Script

#!/usr/bin/sh echo "Enter reason:" echo "> \c" read $reason $reason >> access.log This doesnt work for me. Can someone tell me how I would read the input from what the person types, and then append that to the log file? Regards (2 Replies)
Discussion started by: alwayslearningunix
2 Replies
Login or Register to Ask a Question

Featured Tech Videos