tags:

views:

81

answers:

3
+1  A: 

'unary operator expected' is the error when you use a binary operator with only a single operand.

This means that either t2 or t1 is empty. To cause an empty variable to not disappear, use default notation ${VARIABLE:-DEFAULT} to give them a default value:

if [ ${t2:-0} -ge ${t1:-0} ]; then
R Samuel Klatchko
A: 

I think you want

t1=$(sort -k 2,2 f.txt|head -1|cut -d" " -f2)

instead of

t1=$(sort -k 2,2 f.txt|head -1|cut -d" " -f3)

Your f.txt has only two fields, so cut command results in nothing, and then you pass that to [ ].

About why it works without the H 0 line, I suspect that your F line is

F 1 13

instead of

F1 13

(This is all just a guess.)

Alok
+1  A: 

you are using bash, so use bash's internals. No need to call external cut etc. also quote your variables when you use [ ]

set -- $(sort -k 2,2 f.txt|head -1)
t1=$3
while read f1 f2 f3
do
t2="$f2"
if [ "$t2" -ge "$t1" ] ; then
  p=$f1
  echo -n $p " "
fi
done <f.txt
ghostdog74
What? If you already have quoted the variable before the test-statement there is no need to quote it again, i even thought that was bad etiquette.
Anders
@Anders: `v1=""; [ "$v1" = '' ] [ $v1 = '' ]
Dennis Williamson