Sponsored Content
Full Discussion: How to ask...???
Top Forums UNIX for Advanced & Expert Users How to ask...??? Post 7496 by LivinFree on Thursday 27th of September 2001 02:40:29 AM
Old 09-27-2001
Well, to ask a questions, and record the answer in memory, use the "read" builtin command. Here's an example (I wrote it in sh instead of ksh, since I don't know which you're using, if either- this should be portable between the two, with the exception of the echo statement):

Code:
#!/bin/sh
# Simple example to read in a line, then echo it out

# If you're using Linux, you'll need to use "echo -e"
# instead of "echo".

echo "Enter a string: \c"

# The \c tells echo not to add a new line

read input

# That's where it takes your input and stores it into the 
# variable "input" - you can name this whatever you want

echo "\nThe \$input variable was: $input"

# The "\n" forces echo to insert a new line at that spot

Of course this script isn't of much use to anyone, but it gives an example of using read.
Hope that helps.
 
ECHO(1) 						    BSD General Commands Manual 						   ECHO(1)

NAME
echo -- write arguments to the standard output SYNOPSIS
echo [-n] [string ...] DESCRIPTION
The echo utility writes any specified operands, separated by single blank (' ') characters and followed by a newline (' ') character, to the standard output. The following option is available: -n Do not print the trailing newline character. This may also be achieved by appending 'c' to the end of the string, as is done by iBCS2 compatible systems. Note that this option as well as the effect of 'c' are implementation-defined in IEEE Std 1003.1-2001 (``POSIX.1'') as amended by Cor. 1-2002. Applications aiming for maximum portability are strongly encouraged to use printf(1) to sup- press the newline character. Some shells may provide a builtin echo command which is similar or identical to this utility. Most notably, the builtin echo in sh(1) does not accept the -n option. Consult the builtin(1) manual page. EXIT STATUS
The echo utility exits 0 on success, and >0 if an error occurs. SEE ALSO
builtin(1), csh(1), printf(1), sh(1) STANDARDS
The echo utility conforms to IEEE Std 1003.1-2001 (``POSIX.1'') as amended by Cor. 1-2002. BSD
April 12, 2003 BSD
All times are GMT -4. The time now is 11:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy