Bash getting integer expression expected

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have following script to check disk usage



 #!/bin/bash

# set alert level 90% is default
ALERT=10

OIFS=$IFS
IFS=','

storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk ' print $5 " " $1 ')



for output in $storage ;

do
echo "---------------@@@@@@@@@ output started @@@@@@@@@@@@@@@@-----------"
echo $output
echo "---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------"

usep=$(echo $output | awk ' print $1' | cut -d'%' -f1 )
echo "---------------###### useo started ######-----------"
echo $usep
echo "---------------###### usep end ######-----------"

if [ $usep -ge $ALERT ]; then

echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done


But when i am running this code i am getting the integer expression expected error at if conditional statement, Here is the output of this script



 97% /dev/sda1
1% udev
0% none
2% none
---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------
---------------###### useo started ######-----------
97
1
0
2
---------------###### usep end ######-----------
./fordiskfor.sh: line 24: [: 97
1
0
2: integer expression expected









share|improve this question























  • $usep contains no integer.
    – Cyrus
    Nov 14 '14 at 6:12











  • what should i do
    – pushpendra chauhan
    Nov 14 '14 at 6:19














up vote
0
down vote

favorite












I have following script to check disk usage



 #!/bin/bash

# set alert level 90% is default
ALERT=10

OIFS=$IFS
IFS=','

storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk ' print $5 " " $1 ')



for output in $storage ;

do
echo "---------------@@@@@@@@@ output started @@@@@@@@@@@@@@@@-----------"
echo $output
echo "---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------"

usep=$(echo $output | awk ' print $1' | cut -d'%' -f1 )
echo "---------------###### useo started ######-----------"
echo $usep
echo "---------------###### usep end ######-----------"

if [ $usep -ge $ALERT ]; then

echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done


But when i am running this code i am getting the integer expression expected error at if conditional statement, Here is the output of this script



 97% /dev/sda1
1% udev
0% none
2% none
---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------
---------------###### useo started ######-----------
97
1
0
2
---------------###### usep end ######-----------
./fordiskfor.sh: line 24: [: 97
1
0
2: integer expression expected









share|improve this question























  • $usep contains no integer.
    – Cyrus
    Nov 14 '14 at 6:12











  • what should i do
    – pushpendra chauhan
    Nov 14 '14 at 6:19












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have following script to check disk usage



 #!/bin/bash

# set alert level 90% is default
ALERT=10

OIFS=$IFS
IFS=','

storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk ' print $5 " " $1 ')



for output in $storage ;

do
echo "---------------@@@@@@@@@ output started @@@@@@@@@@@@@@@@-----------"
echo $output
echo "---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------"

usep=$(echo $output | awk ' print $1' | cut -d'%' -f1 )
echo "---------------###### useo started ######-----------"
echo $usep
echo "---------------###### usep end ######-----------"

if [ $usep -ge $ALERT ]; then

echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done


But when i am running this code i am getting the integer expression expected error at if conditional statement, Here is the output of this script



 97% /dev/sda1
1% udev
0% none
2% none
---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------
---------------###### useo started ######-----------
97
1
0
2
---------------###### usep end ######-----------
./fordiskfor.sh: line 24: [: 97
1
0
2: integer expression expected









share|improve this question















I have following script to check disk usage



 #!/bin/bash

# set alert level 90% is default
ALERT=10

OIFS=$IFS
IFS=','

storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk ' print $5 " " $1 ')



for output in $storage ;

do
echo "---------------@@@@@@@@@ output started @@@@@@@@@@@@@@@@-----------"
echo $output
echo "---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------"

usep=$(echo $output | awk ' print $1' | cut -d'%' -f1 )
echo "---------------###### useo started ######-----------"
echo $usep
echo "---------------###### usep end ######-----------"

if [ $usep -ge $ALERT ]; then

echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done


But when i am running this code i am getting the integer expression expected error at if conditional statement, Here is the output of this script



 97% /dev/sda1
1% udev
0% none
2% none
---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------
---------------###### useo started ######-----------
97
1
0
2
---------------###### usep end ######-----------
./fordiskfor.sh: line 24: [: 97
1
0
2: integer expression expected






bash shell shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 at 14:42









Rui F Ribeiro

38.3k1476127




38.3k1476127










asked Nov 14 '14 at 6:07









pushpendra chauhan

101




101











  • $usep contains no integer.
    – Cyrus
    Nov 14 '14 at 6:12











  • what should i do
    – pushpendra chauhan
    Nov 14 '14 at 6:19
















  • $usep contains no integer.
    – Cyrus
    Nov 14 '14 at 6:12











  • what should i do
    – pushpendra chauhan
    Nov 14 '14 at 6:19















$usep contains no integer.
– Cyrus
Nov 14 '14 at 6:12





$usep contains no integer.
– Cyrus
Nov 14 '14 at 6:12













what should i do
– pushpendra chauhan
Nov 14 '14 at 6:19




what should i do
– pushpendra chauhan
Nov 14 '14 at 6:19










2 Answers
2






active

oldest

votes

















up vote
2
down vote













The problem is there:



if [ $usep -ge $ALERT ]; then
...
fi


$usep contains multiple lines of digits. To cycle trough all of them use somthing like this instead of that part:



for $space in $usep;
do
if [ $space -ge $ALERT ]; then
echo "Running out of space..."
fi
done





share|improve this answer



























    up vote
    0
    down vote













    The value stored in the variable $storage comprises of multiple lines. As a result, $output will also contain multiple lines, and so will $usep.



    You can extract and compare all values stored in $usep, one by one, using another for loop as mentioned in this answer. Or you can use while statement as follows:



    echo $storage | while read output
    do
    ...
    ...

    if [ $usep -ge $ALERT ]; then
    echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
    fi
    done





    share|improve this answer






















    • Is this anything other than a repost of the question?
      – jasonwryan
      Nov 14 '14 at 7:06










    • I used while, whereas question contains for loop.
      – Mandar Shinde
      Nov 14 '14 at 7:37










    • Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
      – jasonwryan
      Nov 14 '14 at 7:40










    • I am very poor at explaining things. You could edit my answer if you wish to.
      – Mandar Shinde
      Nov 14 '14 at 7:42










    • @jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
      – Mandar Shinde
      Nov 14 '14 at 8:18










    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f167907%2fbash-getting-integer-expression-expected%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    The problem is there:



    if [ $usep -ge $ALERT ]; then
    ...
    fi


    $usep contains multiple lines of digits. To cycle trough all of them use somthing like this instead of that part:



    for $space in $usep;
    do
    if [ $space -ge $ALERT ]; then
    echo "Running out of space..."
    fi
    done





    share|improve this answer
























      up vote
      2
      down vote













      The problem is there:



      if [ $usep -ge $ALERT ]; then
      ...
      fi


      $usep contains multiple lines of digits. To cycle trough all of them use somthing like this instead of that part:



      for $space in $usep;
      do
      if [ $space -ge $ALERT ]; then
      echo "Running out of space..."
      fi
      done





      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        The problem is there:



        if [ $usep -ge $ALERT ]; then
        ...
        fi


        $usep contains multiple lines of digits. To cycle trough all of them use somthing like this instead of that part:



        for $space in $usep;
        do
        if [ $space -ge $ALERT ]; then
        echo "Running out of space..."
        fi
        done





        share|improve this answer












        The problem is there:



        if [ $usep -ge $ALERT ]; then
        ...
        fi


        $usep contains multiple lines of digits. To cycle trough all of them use somthing like this instead of that part:



        for $space in $usep;
        do
        if [ $space -ge $ALERT ]; then
        echo "Running out of space..."
        fi
        done






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '14 at 6:56









        chaos

        34.8k773115




        34.8k773115






















            up vote
            0
            down vote













            The value stored in the variable $storage comprises of multiple lines. As a result, $output will also contain multiple lines, and so will $usep.



            You can extract and compare all values stored in $usep, one by one, using another for loop as mentioned in this answer. Or you can use while statement as follows:



            echo $storage | while read output
            do
            ...
            ...

            if [ $usep -ge $ALERT ]; then
            echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
            fi
            done





            share|improve this answer






















            • Is this anything other than a repost of the question?
              – jasonwryan
              Nov 14 '14 at 7:06










            • I used while, whereas question contains for loop.
              – Mandar Shinde
              Nov 14 '14 at 7:37










            • Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
              – jasonwryan
              Nov 14 '14 at 7:40










            • I am very poor at explaining things. You could edit my answer if you wish to.
              – Mandar Shinde
              Nov 14 '14 at 7:42










            • @jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
              – Mandar Shinde
              Nov 14 '14 at 8:18














            up vote
            0
            down vote













            The value stored in the variable $storage comprises of multiple lines. As a result, $output will also contain multiple lines, and so will $usep.



            You can extract and compare all values stored in $usep, one by one, using another for loop as mentioned in this answer. Or you can use while statement as follows:



            echo $storage | while read output
            do
            ...
            ...

            if [ $usep -ge $ALERT ]; then
            echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
            fi
            done





            share|improve this answer






















            • Is this anything other than a repost of the question?
              – jasonwryan
              Nov 14 '14 at 7:06










            • I used while, whereas question contains for loop.
              – Mandar Shinde
              Nov 14 '14 at 7:37










            • Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
              – jasonwryan
              Nov 14 '14 at 7:40










            • I am very poor at explaining things. You could edit my answer if you wish to.
              – Mandar Shinde
              Nov 14 '14 at 7:42










            • @jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
              – Mandar Shinde
              Nov 14 '14 at 8:18












            up vote
            0
            down vote










            up vote
            0
            down vote









            The value stored in the variable $storage comprises of multiple lines. As a result, $output will also contain multiple lines, and so will $usep.



            You can extract and compare all values stored in $usep, one by one, using another for loop as mentioned in this answer. Or you can use while statement as follows:



            echo $storage | while read output
            do
            ...
            ...

            if [ $usep -ge $ALERT ]; then
            echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
            fi
            done





            share|improve this answer














            The value stored in the variable $storage comprises of multiple lines. As a result, $output will also contain multiple lines, and so will $usep.



            You can extract and compare all values stored in $usep, one by one, using another for loop as mentioned in this answer. Or you can use while statement as follows:



            echo $storage | while read output
            do
            ...
            ...

            if [ $usep -ge $ALERT ]; then
            echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
            fi
            done






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 13 '17 at 12:36









            Community

            1




            1










            answered Nov 14 '14 at 6:56









            Mandar Shinde

            1,40782747




            1,40782747











            • Is this anything other than a repost of the question?
              – jasonwryan
              Nov 14 '14 at 7:06










            • I used while, whereas question contains for loop.
              – Mandar Shinde
              Nov 14 '14 at 7:37










            • Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
              – jasonwryan
              Nov 14 '14 at 7:40










            • I am very poor at explaining things. You could edit my answer if you wish to.
              – Mandar Shinde
              Nov 14 '14 at 7:42










            • @jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
              – Mandar Shinde
              Nov 14 '14 at 8:18
















            • Is this anything other than a repost of the question?
              – jasonwryan
              Nov 14 '14 at 7:06










            • I used while, whereas question contains for loop.
              – Mandar Shinde
              Nov 14 '14 at 7:37










            • Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
              – jasonwryan
              Nov 14 '14 at 7:40










            • I am very poor at explaining things. You could edit my answer if you wish to.
              – Mandar Shinde
              Nov 14 '14 at 7:42










            • @jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
              – Mandar Shinde
              Nov 14 '14 at 8:18















            Is this anything other than a repost of the question?
            – jasonwryan
            Nov 14 '14 at 7:06




            Is this anything other than a repost of the question?
            – jasonwryan
            Nov 14 '14 at 7:06












            I used while, whereas question contains for loop.
            – Mandar Shinde
            Nov 14 '14 at 7:37




            I used while, whereas question contains for loop.
            – Mandar Shinde
            Nov 14 '14 at 7:37












            Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
            – jasonwryan
            Nov 14 '14 at 7:40




            Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
            – jasonwryan
            Nov 14 '14 at 7:40












            I am very poor at explaining things. You could edit my answer if you wish to.
            – Mandar Shinde
            Nov 14 '14 at 7:42




            I am very poor at explaining things. You could edit my answer if you wish to.
            – Mandar Shinde
            Nov 14 '14 at 7:42












            @jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
            – Mandar Shinde
            Nov 14 '14 at 8:18




            @jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
            – Mandar Shinde
            Nov 14 '14 at 8:18

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f167907%2fbash-getting-integer-expression-expected%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay