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!

expression syntax error : The && construct 1

Status
Not open for further replies.

RVSachin

Technical User
Nov 12, 2001
77
IN
Hi,

Someone please help me to correct the 'expression syntax error' in the following Korn-shell script:

Code:
if [ [ `grep -i "Info: .*.txt" results.log` ] && [ `grep -i "Total: " results.log` ] ]
then
	x=`awk '/Info: .*.tam/{print $2}' results.log`
	y=`awk '/Total: /{print $2}' results.log`

	echo "X =" $x  > grep.txt
	echo "Y =" $y  > grep.txt

	if [ $x == $y ]
	then
		echo "matches" > grep.txt
	else
		echo "fail" > grep.txt
	fi

else
	echo "NOT found in file \*.txt" > grep.txt
fi


This script checks for presence of 2 lines "Info: " and "Total: " in a file results.log, and if it does,
it extracts a numerical value found in those 2 lines and compares if the values are equal.
Else, it reports that there's no such line in the file.


Thanks,

RV
 
Code:
if [ [ `grep ...` ] && [ `grep ...` ] ]

The [tt]if[/tt] command takes a command pipeline as an argument, and performs a set of actions based on the exit status of that command.

The command you have supplied to it is not valid.

The [tt][[/tt] command is actually another name for the [tt]test[/tt] command, with the difference that an argument of [tt]][/tt] must be given last (to make it look pretty).

Valid formats for [tt][[/tt] are given in the [tt]test[/tt] man page or in the man page for your shell.


If I understand your intent correctly, I would suggest that you don't even use the test command to check for your condition.

Try this:
Code:
if grep -qi "Info: .*.txt" results.log &&
   grep -qi "Total: " results.log;
then
    ...
fi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top