Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare file and string 1

Status
Not open for further replies.

Yarka

Technical User
Jan 14, 2007
192
ES
I have a file 'abc'like:

root#cat abc

no selected

root#

I need to compare the content of this test with the string 'no selected'. I do the following:

if [cat abc == "no selected"]; then
echo 1
else
echo 0
fi

but it doesn't work. How can I compare the file and that string?


Thank you very much!
 
Hi

Code:
[gray]# corrected[/gray]
[b]if[/b] [teal][[/teal] [green][i]"$( cat abc )"[/i][/green] [teal]==[/teal] [green][i]"no selected"[/i][/green] [teal]];[/teal] [b]then[/b]

[gray]# preferrable[/gray]
[b]if[/b] [teal][[/teal] [green][i]"$(< abc )"[/i][/green] [teal]==[/teal] [green][i]"no selected"[/i][/green] [teal]];[/teal] [b]then[/b]

[gray]# even more preferrable[/gray]
[b]if[/b] [teal][[[/teal] [green][i]"$(< abc )"[/i][/green] [teal]==[/teal] [green][i]"no selected"[/i][/green] [teal]]];[/teal] [b]then[/b]

Feherke.
 
Why not simply this ?
Code:
fgrep -q 'no selected' abc && echo 1 || echo 0

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top