View Single Post
Old Apr 5th, 2005, 11:19 AM   #2
trufla
Newbie
 
Join Date: Apr 2005
Posts: 6
Rep Power: 0 trufla is on a distinguished road
aah, when saving a string with spaces you have to save it in quotes:-

x="Have a nice day"
y=$y

But a command has spaces and isn't a string? Cannot save it in double quotes.

How can a user enter a commmand to be saved to a variable so that it will be run when a function is called.

My original little script worked, but there were only single words in stored in the variables:- the user would type 'grep Jones Myfile', and each word is stored in a separate variable and recalled in order of the command

#Filename: user_retrieval : Author: L.Pearce

function grepfunction
{

$gtool $parameter $filename

}

#:::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!"

Any ideas?
trufla is offline   Reply With Quote