First of all, please use ***
[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do
not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
1) In the bash version of
read, you can use the
-e option to give you readline editing. This will allow you to use tab completion and other advanced editing techniques.
2) In the second line,
$(..) is highly recommended over `..`. And don't bother to use a text file; just store the result in another variable.
Although you probably have to decide what to do if the
find command turns up more than one filename. Or no name.
You also need to enclose all variables in double quotes, to protect any spaces in their contents from shell word-splitting.
It's vital in scripting to understand how the shell handles arguments and whitespace:
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes
3) In the last line, you do not put
$ in front of a variable when setting it, only when expanding it.
Ignoring the multiple match problem for the moment:
Code:
read -e -p "Input a name of file: " fname
fname=$( find / -type f -name "$fname" -print ) #there's probably no reason not to re-use the same variable
#you should do some other error checking here to determine if the file's legit before using it.
vi "$fname"