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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If condition syntax help 1

Status
Not open for further replies.

simpson

MIS
Oct 23, 2001
58
CA
All,

I have a simple if statement that I am trying to get to work and my quotes adn brackets are not working. I know someone will think I am struggling with a simple thing but sometimes you have ask for help
--------cut------------
if `file $file_name | grep ascii`
then
echo "ASCII"
else
echo "Not ASCII"
fi
-------cut-------------

I can never get this to work, it always comes back false or syntax error depending on how I write the if.

Thanks in advace.
 
You may try this:
Code:
if [ "`file $file_name | grep ascii`" ]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This doesn't use an "[tt]if[/tt]", but it does the same thing...
Code:
file $filename | grep -q ASCII && echo "ASCII" || echo "Not ASCII"
Tested in BASH and KSH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top