How can I grep variable?
I want to And search grep shell
but It's hard to grep variable --------------------------------------------------------------- #!/bin/bash if [ $# -eq 0 ] then echo "Ussage: phone searchfor [...searchfor]" echo "(You didn't tell me what you want to search for )" else pass=0 find="" for idx in $* do if [ -n "$idx" ] then if [ $pass -eq 0 ] then find=$(egrep "$idx" mydata) pass=1 else find=$("$find" | grep "$idx") echo $find fi fi done if [ -z "$find" ] then echo "There is no such thing" else echo $find | awk -f display.awk fi fi ----------------------------------------------------- there is one error : command not found in find=$("$find" | grep "$idx") how can I grep variable and store it into variable? |
Unless $find is a command I am not how you think the pipe will work? Maybe try calling a command on the variable, say echo, then there is some standard input for grep and the pipe to work with.
Also, what would be the point? Is it likely that $find will have multiple lines in it? If not, why use grep? |
Not sure what you want but maybe you could just run env and then grep.
Code:
env | grep <whatever> Code:
env | awk -F"=" '{print $1}' | grep <whatever> |
All times are GMT -5. The time now is 07:05 AM. |