LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to make a script wait for input (https://www.linuxquestions.org/questions/linux-general-1/how-to-make-a-script-wait-for-input-271031/)

farmerjoe 12-28-2004 01:17 AM

How to make a script wait for input?
 
How do i make a script wait for user input to declare a variable?

like say i wanted it to do this:

What would you like the variable to be?
>test
Your variable is test.


I want to pause and wait for the user to input something that will declare a variable to be that input.

Any help is greatly appreciated. I am a n00b to all of this of course.

Thanks!
famerjoe

druuna 12-28-2004 04:54 AM

Hi,

Here are 2 ways of doing it:

Code:

#/bin/ksh

# Question and answer in one statement. The ?"<text>" is the part for the text you want/need to display

read aok?"Can we continue (y|n) : "

echo $aok

# Here text and answer are 2 commands. echo for the text, and read for the input.

echo "Can we continue (y|n) : \c"
read aok

echo $aok

Hope this helps.

PS: Can also be done with bash.

XavierP 12-28-2004 05:18 AM

Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php

Go here: http://www.linuxquestions.org/questi...hreadid=271028


All times are GMT -5. The time now is 02:16 AM.