1

In a shell script I wrote following lines gave error during execution of script

if [ p -eq 35 -o p -eq 70 ]; then
echo "Sleeping ....zzz ........zzzz......."
sleep 5

get following error

/d2.sh: line 6: [: p: integer expression expected

1 Answer 1

2

You probably want $p instead of p:

if [ $p -eq 35 -o $p -eq 70 ]; then
    ...
Sign up to request clarification or add additional context in comments.

3 Comments

You can use variable names without $ only in (( ... )) arithmetic expressions.
@l0b0: No, [[ ]] still requires $ to expand variables. @choroba: Note that you need to use different operators inside (( )): ==, <, >, || etc instead of -eq, -lt, -gt, -o...
Thank you @GordonDavisson for your nice advice... as I am searching so many websites how can I get rid of this integer problem.

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.