0

i have only one character to read from a file in UNIX. When i assign the file to a variable and compare with integer it gives integer error.

count.txt contains numeric character. Below is the code

#!/usr/local/bin/bash
_count=/apps/count.txt
_value=20
if [ _value -ge _count ] then
echo "Value is greater"
fi
exit 0
2
  • 1
    The file contains only one character Commented Sep 17, 2013 at 2:59
  • 1
    you're not reading a file. It should be something like _count=$(cat /apps/count.txt) Commented Sep 17, 2013 at 3:00

2 Answers 2

1
_count=$( cat /apps/count.txt )
_value=20
if [ $_value -ge $_count ]; then
    echo "Value is greater"
fi
exit 0

You can access the value in count.txt with "cat" and assign it to the variable. You also forgot to add a ";" after the if statement.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Script is running without semicolon
1

You don't even have to use cat! Also you can use (( )) for arithmetical operations:

count=$( < count.txt)
value=20

if (( value >= count )); then
    echo "Value is greater"
fi
exit 0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.