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.
 
BASENAME(3)								 1							       BASENAME(3)

basename - Returns trailing name component of path

SYNOPSIS
string basename (string $path, [string $suffix]) DESCRIPTION
Given a string containing the path to a file or directory, this function will return the trailing name component. PARAMETERS
o $path - A path. On Windows, both slash ( /) and backslash ( ) are used as directory separator character. In other environments, it is the forward slash ( /). o $suffix - If the name component ends in $suffix this will also be cut off. RETURN VALUES
Returns the base name of the given $path. EXAMPLES
Example #1 basename(3) example <?php echo "1) ".basename("/etc/sudoers.d", ".d").PHP_EOL; echo "2) ".basename("/etc/sudoers.d").PHP_EOL; echo "3) ".basename("/etc/passwd").PHP_EOL; echo "4) ".basename("/etc/").PHP_EOL; echo "5) ".basename(".").PHP_EOL; echo "6) ".basename("/"); ?> The above example will output: 1) sudoers 2) sudoers.d 3) passwd 4) etc 5) . 6) NOTES
Note basename(3) operates naively on the input string, and is not aware of the actual filesystem, or path components such as " ..". Note basename(3) is locale aware, so for it to see the correct basename with multibyte character paths, the matching locale must be set using the setlocale(3) function. SEE ALSO
dirname(3), pathinfo(3). PHP Documentation Group BASENAME(3)
All times are GMT -4. The time now is 03:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy