![]() |
Piping in a script
Hello all!
I was writing a simple script to search text files for data using grep and I decided to have a go at writing a script that piped unix commands to grep too. I am having problems though. I think the problem is in the storing of user input in a variable. For example:- If I wanted to store who|grep ^l in a variable called $pipe is the spacing of the command an issue when stored in variables or am I completely off the point? This is my code:- :
I get this error:- :
./piping: line 8: who|grep: command not foundCheers, Trufla |
aah, when saving a string with spaces you have to save it in quotes:-
:
x="Have a nice day"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 :
Any ideas? |
I'm alittle confused because when I echo what is stored in $pipe it is
who|grep ^l when I called the function that holds $pipe I get:- :
./piping: line 6: who|grep: command not found? |
execution:
#!/bin/sh pipe=`who | grep myuser` echo $pipe saving command to execute later: pipe="who | grep myuser" |
I still get problems.
When I do this:- :
#!/bin/bashI get this:- :
who|grep myuser is what you typedThis means the user entered info is stored in the variable $pipe? when I do this:- :
#Filename: piping : Author: L.PearceI get this:- :
./piping: line 6: who|grep: command not foundIt is like the first half of the data with no spaces is stored but the last crucial part isn't? However I know that it all is stored because of the first test. What happens to the 'myuser' bit? What am I doing wrong? |
Try this:
:
#Filename: user_retrieval : Author: L.PearceResults... [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 |
| All times are GMT -5. The time now is 4:22 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC