I'm on FreeBSD's csh.I want to form a row with domains of one user and then use this row to filter exim maillog to get only mail from/to this user's domains.I wrote a script to form a row from a list of DirectAdmin-domains:#!/bin/shuser=some-user    list=$(cat /usr/local/directadmin/data/users/$user/domains.list)    domaincount=$(echo $list|wc -w)    echo $list| tr ' ' '|'Executing this script returns rows with domains like this: 'domain.com' or this: 'domain1.com|domain2.net'Now I want to use this as an argument to grep, but cat /var/log/exim/mainlog |egrep `/path/to/rowscript`returns nothing, while replacing manually /path/to/rowscript with its result returns what I want to see.Tried to use grep -E `/path/to/rowscript`, egrep '`/path/to/rowscript`' egrep `/bin/sh /path/to/rowscript`egrep $(/path/to/rowscript)    getting Illegal variable name.etc., but still no luck.BTW, date in backticks works well:cat /var/log/exim/mainlog | grep `date +%Y-%m-%d`What am I doing wrong?
How to use a value returned by a script in grep filter?
shell script;scripting;grep
Your script should not output single quotes. When you writeegrep 'foo|bar'the single quotes are part of the shell syntax. They protect the characters inside them against expansion. If single quotes appear in the output of your script, they'll be taken as ordinary characters. Simply omit them.There's a far easier way to write your script: replace newlines by pipe symbols, and remove the last one.list=$(</usr/local/directadmin/data/users/$user/domains.list tr '\n' '|')echo ${list%|}You don't need to do that if you're looking for a fixed set of strings. Instead, use the -F option to grep to tell it to look for fixed strings, and the -f option to tell it to read a list of patterns from a file.grep -Ff /usr/local/directadmin/data/users/bob/domains.listNote that if you have domain.com in that file, the search will also return hits for longer strings such as otherdomain.com. So you may want to use your script to build a pattern that has anchors at the beginning and at the end, so avoid spurious matching. I don't know what kind of punctuation the exim log has; for example, if the names are surrounded by whitespace, you'd want something like#!/bin/shlist=$(</usr/local/directadmin/data/users/$1/domains.list tr '\n' '|')echo  (${list%|}) and call it as</var/log/exim/mainlog grep -E `/path/to/rowscript bob`Or make the script call grep:#!/bin/shshiftlist=$(</usr/local/directadmin/data/users/$1/domains.list tr '\n' '|')grep -E  (${list%|})  -- $@called as</var/log/exim/mainlog /path/to/rowscript bob