Matthew G
Matthew G

Reputation: 95

Saving grep output in csh

Hi I just started to do some csh scripting and I have been having issues with storing grep results to a variable. I'm trying to save a line from a file that contains a username as a substring.

echo `grep -w $name /etc/passwd`
set line=`grep -w $name /etc/passwd`
echo $line

The first line is just a debug line so I know my grep is getting the correct line. Its the second line that is giving me issues. When I echo it it prints "echo: no match". Anyone have any help to offer?

Upvotes: 0

Views: 2733

Answers (1)

Craig Estey
Craig Estey

Reputation: 33631

Your passwd file contains an *. Add double quotes to your script:

set line="`grep -w $name /etc/passwd`"
echo "$line"

Without the quotes, the * gets interpreted as a wildcard file match character that [probably] won't match any real file.

Upvotes: 1

Related Questions