Try this:
#Filename: user_retrieval : Author: L.Pearce
function grepfunction
{
cat $filename | $gtool $parameter
}
#:::How does a user type data to be stored in a variable?:::
#-------------------------------------------------------------
echo
echo
echo ":::Retrieval of Information using 'Grep':::"
echo
echo "enter the tool you are using here:"
read gtool
echo "$gtool was the tool you typed"
echo
echo
echo
echo
#:::Similarly, a user can specify a parameter to be stored in a variable:::
#-------------------------------------------------------------------------
echo
echo
echo "enter the parameter you wish to search by:"
read parameter
echo "$parameter was the parameter you typed"
echo
echo
echo
echo
#:::And, a user can specify a filename to be stored in a variable:::
#-------------------------------------------------------------------------
echo
echo
echo "Enter file name to be searched"
read filename
if [ -r "$filename" -a -f "$filename" ]
then
clear
#:::How can the data stored in that variable be used to search a file?:::
#------------------------------------------------------------------------
#By calling the function "grep function"
grepfunction
else
echo "Could not search!"
[jpowers@adsl-065-005-212-144 test]$ more grepit.sh
#Filename: user_retrieval : Author: L.Pearce
function grepfunction
{
cat $filename | $gtool $parameter
}
#:::How does a user type data to be stored in a variable?:::
#-------------------------------------------------------------
echo
echo
echo ":::Retrieval of Information using 'Grep':::"
echo
echo "enter the tool you are using here:"
read gtool
echo "$gtool was the tool you typed"
echo
echo
echo
echo
#:::Similarly, a user can specify a parameter to be stored in a variable:::
#-------------------------------------------------------------------------
echo
echo
echo "enter the parameter you wish to search by:"
read parameter
echo "$parameter was the parameter you typed"
echo
echo
echo
echo
#:::And, a user can specify a filename to be stored in a variable:::
#-------------------------------------------------------------------------
echo
echo
echo "Enter file name to be searched"
read filename
if [ -r "$filename" -a -f "$filename" ]
then
clear
#:::How can the data stored in that variable be used to search a file?:::
#------------------------------------------------------------------------
#By calling the function "grep function"
grepfunction
else
echo "Could not search!"
fi
echo
echo
echo "The entries above match your search"
echo
echo
echo "It is as easy as:-"
echo "1. (Type tool) grep"
echo "2. (Type parameter) a name"
echo "3. (Type the name of the file) Myfile"
echo
echo "All you have to do is type the command at the $ prompt!"
Results...
[jpowers@thebeast test]$ ./grepit.sh
:::Retrieval of Information using 'Grep':::
enter the tool you are using here:
grep
grep was the tool you typed
enter the parameter you wish to search by:
jpowers
jpowers was the parameter you typed
Enter file name to be searched
dat.dat
jpowers
jpowers
jpowers
The entries above match your search