grep, sed in a shell script

Hi,

I have a problem with a simple script I am trying to write. I want a user to type grep, sed commands that are then stored in variables. Those variables are stored in a function, and the function is then called to execute the commands. The idea is that the user does it step by step.

script:-

#!/bin/bash
#Filename: variabletest : Author: L.Pearce

function tptfunction
{
 $tool $criteria $filename
}

echo
echo
echo "Type command in full:"
echo "1. Type the tool you are using."
      read tool
echo "You typed $tool"

echo "2. Type criteria you wish to search."
      read criteria
echo "You typed $criteria"

echo "3. Type the name of the file you are searching:"
         read filename
echo "$filename is what you typed."

             tptfunction

echo
echo

I type sed '/Pearce/p' NewFile

the error:-

sed: -e expression #1, char 1: Unknown command: `''

When I type this command, and other similar ones where quotes are used:-

sed -n '/Pearce/p' NewFile

ls | grep '^g'

I get similar errors, like command not found.
I have the saem problem when trying to pipe unix commands to grep or sed

who|grep ^l

I have used:-

grep -n Name NewFile

and this seems to work fine.

I am guessing the spacing is not an issue, moreover the quotes or syntax.

Can anyone help?

Trufla

i just tested your script on a Solaris 8 box and it works fine with sed until you give " '/Pearce/p' " as an argument to the criteria prompt ... use "/Pearce/p" only without the single quotes ... also make sure you are using single quotes and not backticks --- backticks are with the tilde key while single quotes are with the double quotes key on both sun and pc keyboards i use ...

I still have problems:
I typed:-

#no single quotes/backquotes or back ticks 
-n /Pearce/
#I also tried it without suppression command

I got an error:-

sed: -e expression #1, char 8: Missing command

I did a search for this type of error, but could not find any info I understand.

I do not know if this makes a difference but I am using a windows PC, and using SSh to connect to a remote unix box.

Would this make a difference?

Trufla

sed needs to know what to do with "/Pearce/" ... try "/Pearce/p" ...

and no, it doesn't matter how you're getting to the unix box as you're not executing the script on your pc ... that only matters when you're starting a Xwindows application and you need to have a Xserver (i.e., exceed, cygwin, etc.) on your PC for it to work ...

FANTASTIC!

Cheers!