How do you take what a user types in and convert it into a variable to be used


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do you take what a user types in and convert it into a variable to be used
# 1  
Old 06-11-2008
Question How do you take what a user types in and convert it into a variable to be used

I am a newbie to programming on the unix Command Line*, and was wondering how you take what a user types in and convert it into a variable to be used in the script?


*I always used it for file editing, but nothing more. Then I began to use BBedit.

Smilie
# 2  
Old 06-12-2008
Code:
#!/bin/ksh
echo "Give me your best shot: "
read bestshot
echo "The user's best shot was ${bestshot}."

Fancy UNIX shell programming trick:

Code:
printf "Hit me: "
stty raw
hit=`dd if=/dev/tty  bs=1 count=1 2>/dev/null`
stty cooked
echo "User hit a $hit character!"

Smilie

-mschwage
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert a string to variable in Bash shell

Hi All; I have 2 variable let's say $A and $B. These are actually some remotely executed command outputs. I captured these values in my local variables. Here is my problem. When I try to do some arithmetic operation with these variables, I receive an error message. Neither expr nor typeset -i... (3 Replies)
Discussion started by: Meacham12
3 Replies

2. UNIX for Advanced & Expert Users

Convert variable blocked file

Dear All, I am receiving Fixed blocked file from AS/400 system to my unix box. Could you please advise us how to convert this fix blocked file to variable blocked file. Do we have any command in Unixt or program. I am new to this Unix system Thanks & Regards, Colam (1 Reply)
Discussion started by: coolmaninit
1 Replies

3. Shell Programming and Scripting

How to convert string(variable) into date( epoch) in ksh on HPUX machine?

Hi all, I have used a bash script which ultimately converts a string into date using date --date option: DATE=$DATE" "$TIME" "`date +%Y` //concatenating 2 strings TMRW_DATE=`date --date="$DATE" +"%s"` //applying date command on string and getting the unixtime Please use code tags... (7 Replies)
Discussion started by: Rashu123
7 Replies

4. Shell Programming and Scripting

Read Variable From Fille And Convert it to Integer

I read 3 variables from from Inputfile.txt the third one "startnumber" is a number when i compare it with 9 ($startnumber -le 9) it give's me a "unary operator expected", i know that -le is for number comparison. What i need is to convert $startnumber to integer (i have try to do it with expr but... (8 Replies)
Discussion started by: marios
8 Replies

5. Shell Programming and Scripting

how to convert user input to uppercase

Hi, how to convert user input (lowercase) to uppercase in the dos batch file ? echo. SET /p user1=Enter username: SET user2=%user1%V echo. echo %user1% echo. echo %user2% echo. With Regards (7 Replies)
Discussion started by: milink
7 Replies

6. Shell Programming and Scripting

convert hex to binary and send to variable

Folks, can anyone help with a script to convert hex to binary digits, and break the 32 bit binary into packs of 4 and send them to 8 different variables.Any help is sincerely appreciated. Thanks venu Its in korn shell...... (24 Replies)
Discussion started by: venu
24 Replies

7. Shell Programming and Scripting

Convert value stored in a variable to epoch time?

Hello I have a the creation date of a file stored in a variable in the following format: Wed May 06 10:14:58 2009Is there a way I can echo the variable and display it in epoch time? I've done a lot of searching on this topic, but haven't managed to get a solution. I'm on Solaris 10. ... (2 Replies)
Discussion started by: Glyn_Mo
2 Replies

8. Shell Programming and Scripting

convert date variable to doy variable

Hello: I have a script that requires the use of DOY (as a variable) instead of YY/MM/DD. I already obtained these parameters from downloaded files and stored them as variables (i.e. $day, $month, $year). Is there any simple script that I could incorporate in mine to do this job? Regards, ... (8 Replies)
Discussion started by: aabrego
8 Replies

9. Shell Programming and Scripting

convert variable content to array

Hi All, I have a variable in a shell script which holds let say n paarmeteres with space separate them : $var = par1 par2 par3 par4 parn; so if I print this variable this is what I'll see: par1 par2 par3 par4 parn I need to insert each parameter to an array , so I can go over on each... (3 Replies)
Discussion started by: Alalush
3 Replies

10. Shell Programming and Scripting

Replace variable with a user defined variable

I have a file that has a list of entries in a column x z z z x y z The column can have any length and any number of any strings. I need to replace each unique string with a user defined number. I can filter the unique entries out using awk '{if (NF==5) print $2}' file | uniq | nl >... (1 Reply)
Discussion started by: ce124
1 Replies
Login or Register to Ask a Question