LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   how can I take input with a shell script? (https://www.linuxquestions.org/questions/linux-general-1/how-can-i-take-input-with-a-shell-script-312124/)

GUIPenguin 04-11-2005 04:24 PM

how can I take input with a shell script?
 
I need help with taking input with a shell script


something like this

-----> take input ---> save as a var

echo $var

thanks

Zeno McDohl 04-11-2005 04:26 PM

I think it's something like this, $1 being the first arg.
Code:

if ( "$1" != "" ) set port="$1"
Where port is what you want to name the variable.
Then:
Code:

echo $port

GUIPenguin 04-11-2005 04:34 PM

I know how to save it like that.....what I am actualy looking for is to 'take input' from the user and save it in a 'var'. But Thanks

perfect_circle 04-11-2005 04:43 PM

Something like this? (in bold is my input)
Code:

skalkoto@darkstar:~/src$ ./ask_name
What's your name? John
hello John
skalkoto@darkstar:~/src$cat ask_name
#!/bin/bash

echo -n "What's your name? "
read var1
echo "hello $var1"
skalkoto@darkstar:~/src$

The command you are looking for is read.

For more info, look here:
http://www.tldp.org/LDP/abs/html/internal.html

GUIPenguin 04-11-2005 04:46 PM

yes........thanks ALOT


All times are GMT -5. The time now is 08:15 AM.