Problem with using time check with if statments - BASHGet the source directory of a Bash script from within the script itselfHow to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How do I split a string on a delimiter in Bash?Extract filename and extension in BashHow to check if a variable is set in Bash?How to concatenate string variables in BashCheck existence of input argument in a Bash shell scriptEcho newline in Bash prints literal n

If Trump gets impeached, how long would Pence be president?

May a man marry the women with whom he committed adultery?

Where to find an interactive PDF or HTML version of the tex.web documentation?

If a 2019 UA artificer has the Repeating Shot infusion on two hand crossbows, can they use two-weapon fighting?

Aftermath of nuclear disaster at Three Mile Island

What do you call a flexible diving platform?

Request for a Latin phrase as motto "God is highest/supreme"

Vertical tennis ball into fancy new enumerate

Converting 8V AC to 8V DC - bridge rectifier gets very hot while idling

How do I explain an exponentially complex intuitively?

What does "see" in "the Holy See" mean?

What are the different qualities of the intervals?

Old French song lyrics with the word "baiser."

Word for showing a small part of something briefly to hint to its existence or beauty without fully uncovering it

Japanese reading of an integer

How did Mysterio have these drones?

Finding minimum time for vehicle to reach to its destination

Does a Rogue's Evasion work for spells?

Checking if an integer is a member of an integer list

Is it legal to use cash pulled from a credit card to pay the monthly payment on that credit card?

How to check what is edible on an alien world?

TSA asking to see cell phone

Suggestions for protecting jeans from saddle clamp bolt

Why does Canada require mandatory bilingualism in all government posts?



Problem with using time check with if statments - BASH


Get the source directory of a Bash script from within the script itselfHow to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How do I split a string on a delimiter in Bash?Extract filename and extension in BashHow to check if a variable is set in Bash?How to concatenate string variables in BashCheck existence of input argument in a Bash shell scriptEcho newline in Bash prints literal n






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am currently checking a .sh script just to do some basic things.



chmod +x catbash.sh

echo 'Hello, Please Enter your User Name'
echo
read VarUserName

currenttime=$(date +%H:%M)
if [[ $currenttime > 11:59 ]] || [[ $currenttime < 12:00 ]];
then echo 'Good Morning' $VarUserName'.'
fi

if [[ $currenttime > 12:00 ]] || [[ $currenttime < 16:59 ]];
then echo 'Good Afternoon' $VarUserName'.'
fi

if [[ $currenttime > 17:00 ]] || [[ $currenttime < 19:59 ]];
then echo 'Good Evening' $VarUserName'.'
fi

if [[ $currenttime > 20:00 ]] || [[ $currenttime < 23:59 ]];
then echo 'Good Night' $VarUserName'.'
fi


My issue is that i am trying to use the systems current time to be used in a if statement and depending on the time for a different output.



right now the script outputs all all of the "good...." echos and does not output a single echo depending on the time.



thank you for the help.










share|improve this question



















  • 2





    @el-teedee this is NOT a parsing issue .. This is straight up logic -- He needs AND instead of OR .. All if statement are being executed and are technically true .. So they all echo .. Another way to make this more correct would be the use of elif so that no more than one technically can print out ..

    – Zak
    Mar 26 at 18:59


















0















I am currently checking a .sh script just to do some basic things.



chmod +x catbash.sh

echo 'Hello, Please Enter your User Name'
echo
read VarUserName

currenttime=$(date +%H:%M)
if [[ $currenttime > 11:59 ]] || [[ $currenttime < 12:00 ]];
then echo 'Good Morning' $VarUserName'.'
fi

if [[ $currenttime > 12:00 ]] || [[ $currenttime < 16:59 ]];
then echo 'Good Afternoon' $VarUserName'.'
fi

if [[ $currenttime > 17:00 ]] || [[ $currenttime < 19:59 ]];
then echo 'Good Evening' $VarUserName'.'
fi

if [[ $currenttime > 20:00 ]] || [[ $currenttime < 23:59 ]];
then echo 'Good Night' $VarUserName'.'
fi


My issue is that i am trying to use the systems current time to be used in a if statement and depending on the time for a different output.



right now the script outputs all all of the "good...." echos and does not output a single echo depending on the time.



thank you for the help.










share|improve this question



















  • 2





    @el-teedee this is NOT a parsing issue .. This is straight up logic -- He needs AND instead of OR .. All if statement are being executed and are technically true .. So they all echo .. Another way to make this more correct would be the use of elif so that no more than one technically can print out ..

    – Zak
    Mar 26 at 18:59














0












0








0








I am currently checking a .sh script just to do some basic things.



chmod +x catbash.sh

echo 'Hello, Please Enter your User Name'
echo
read VarUserName

currenttime=$(date +%H:%M)
if [[ $currenttime > 11:59 ]] || [[ $currenttime < 12:00 ]];
then echo 'Good Morning' $VarUserName'.'
fi

if [[ $currenttime > 12:00 ]] || [[ $currenttime < 16:59 ]];
then echo 'Good Afternoon' $VarUserName'.'
fi

if [[ $currenttime > 17:00 ]] || [[ $currenttime < 19:59 ]];
then echo 'Good Evening' $VarUserName'.'
fi

if [[ $currenttime > 20:00 ]] || [[ $currenttime < 23:59 ]];
then echo 'Good Night' $VarUserName'.'
fi


My issue is that i am trying to use the systems current time to be used in a if statement and depending on the time for a different output.



right now the script outputs all all of the "good...." echos and does not output a single echo depending on the time.



thank you for the help.










share|improve this question
















I am currently checking a .sh script just to do some basic things.



chmod +x catbash.sh

echo 'Hello, Please Enter your User Name'
echo
read VarUserName

currenttime=$(date +%H:%M)
if [[ $currenttime > 11:59 ]] || [[ $currenttime < 12:00 ]];
then echo 'Good Morning' $VarUserName'.'
fi

if [[ $currenttime > 12:00 ]] || [[ $currenttime < 16:59 ]];
then echo 'Good Afternoon' $VarUserName'.'
fi

if [[ $currenttime > 17:00 ]] || [[ $currenttime < 19:59 ]];
then echo 'Good Evening' $VarUserName'.'
fi

if [[ $currenttime > 20:00 ]] || [[ $currenttime < 23:59 ]];
then echo 'Good Night' $VarUserName'.'
fi


My issue is that i am trying to use the systems current time to be used in a if statement and depending on the time for a different output.



right now the script outputs all all of the "good...." echos and does not output a single echo depending on the time.



thank you for the help.







bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 20:26









marc_s

598k135 gold badges1148 silver badges1284 bronze badges




598k135 gold badges1148 silver badges1284 bronze badges










asked Mar 26 at 18:47









dooddood

31 bronze badge




31 bronze badge







  • 2





    @el-teedee this is NOT a parsing issue .. This is straight up logic -- He needs AND instead of OR .. All if statement are being executed and are technically true .. So they all echo .. Another way to make this more correct would be the use of elif so that no more than one technically can print out ..

    – Zak
    Mar 26 at 18:59













  • 2





    @el-teedee this is NOT a parsing issue .. This is straight up logic -- He needs AND instead of OR .. All if statement are being executed and are technically true .. So they all echo .. Another way to make this more correct would be the use of elif so that no more than one technically can print out ..

    – Zak
    Mar 26 at 18:59








2




2





@el-teedee this is NOT a parsing issue .. This is straight up logic -- He needs AND instead of OR .. All if statement are being executed and are technically true .. So they all echo .. Another way to make this more correct would be the use of elif so that no more than one technically can print out ..

– Zak
Mar 26 at 18:59






@el-teedee this is NOT a parsing issue .. This is straight up logic -- He needs AND instead of OR .. All if statement are being executed and are technically true .. So they all echo .. Another way to make this more correct would be the use of elif so that no more than one technically can print out ..

– Zak
Mar 26 at 18:59













2 Answers
2






active

oldest

votes


















2














The problem is with your conditions, all of them permit any given value, did you maybe want to use && instead of ||?






share|improve this answer


















  • 1





    Another stylistic improvement would be to use elif instead of always closing the previous if and starting a new one.

    – tripleee
    Mar 26 at 19:03


















0














It would be much simpler if you would write it using the elif construction and start from the later times and work your way down.



chmod +x catbash.sh

currenttime=$(date +%H:%M)
if [[ "$currenttime" > "19:59" ]]; then echo "Good Night $USER"
elif [[ "$currenttime" > "16:59" ]]; then echo "Good Evening $USER"
elif [[ "$currenttime" > "11:59" ]]; then echo "Good Afternoon $USER"
elif [[ "$currenttime" > "05:59" ]]; then echo "Good Morning $USER"
else echo "Good Night $USER"





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2fstackoverflow.com%2fquestions%2f55364290%2fproblem-with-using-time-check-with-if-statments-bash%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









    2














    The problem is with your conditions, all of them permit any given value, did you maybe want to use && instead of ||?






    share|improve this answer


















    • 1





      Another stylistic improvement would be to use elif instead of always closing the previous if and starting a new one.

      – tripleee
      Mar 26 at 19:03















    2














    The problem is with your conditions, all of them permit any given value, did you maybe want to use && instead of ||?






    share|improve this answer


















    • 1





      Another stylistic improvement would be to use elif instead of always closing the previous if and starting a new one.

      – tripleee
      Mar 26 at 19:03













    2












    2








    2







    The problem is with your conditions, all of them permit any given value, did you maybe want to use && instead of ||?






    share|improve this answer













    The problem is with your conditions, all of them permit any given value, did you maybe want to use && instead of ||?







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 26 at 18:55









    joshbooksjoshbooks

    3491 silver badge7 bronze badges




    3491 silver badge7 bronze badges







    • 1





      Another stylistic improvement would be to use elif instead of always closing the previous if and starting a new one.

      – tripleee
      Mar 26 at 19:03












    • 1





      Another stylistic improvement would be to use elif instead of always closing the previous if and starting a new one.

      – tripleee
      Mar 26 at 19:03







    1




    1





    Another stylistic improvement would be to use elif instead of always closing the previous if and starting a new one.

    – tripleee
    Mar 26 at 19:03





    Another stylistic improvement would be to use elif instead of always closing the previous if and starting a new one.

    – tripleee
    Mar 26 at 19:03













    0














    It would be much simpler if you would write it using the elif construction and start from the later times and work your way down.



    chmod +x catbash.sh

    currenttime=$(date +%H:%M)
    if [[ "$currenttime" > "19:59" ]]; then echo "Good Night $USER"
    elif [[ "$currenttime" > "16:59" ]]; then echo "Good Evening $USER"
    elif [[ "$currenttime" > "11:59" ]]; then echo "Good Afternoon $USER"
    elif [[ "$currenttime" > "05:59" ]]; then echo "Good Morning $USER"
    else echo "Good Night $USER"





    share|improve this answer



























      0














      It would be much simpler if you would write it using the elif construction and start from the later times and work your way down.



      chmod +x catbash.sh

      currenttime=$(date +%H:%M)
      if [[ "$currenttime" > "19:59" ]]; then echo "Good Night $USER"
      elif [[ "$currenttime" > "16:59" ]]; then echo "Good Evening $USER"
      elif [[ "$currenttime" > "11:59" ]]; then echo "Good Afternoon $USER"
      elif [[ "$currenttime" > "05:59" ]]; then echo "Good Morning $USER"
      else echo "Good Night $USER"





      share|improve this answer

























        0












        0








        0







        It would be much simpler if you would write it using the elif construction and start from the later times and work your way down.



        chmod +x catbash.sh

        currenttime=$(date +%H:%M)
        if [[ "$currenttime" > "19:59" ]]; then echo "Good Night $USER"
        elif [[ "$currenttime" > "16:59" ]]; then echo "Good Evening $USER"
        elif [[ "$currenttime" > "11:59" ]]; then echo "Good Afternoon $USER"
        elif [[ "$currenttime" > "05:59" ]]; then echo "Good Morning $USER"
        else echo "Good Night $USER"





        share|improve this answer













        It would be much simpler if you would write it using the elif construction and start from the later times and work your way down.



        chmod +x catbash.sh

        currenttime=$(date +%H:%M)
        if [[ "$currenttime" > "19:59" ]]; then echo "Good Night $USER"
        elif [[ "$currenttime" > "16:59" ]]; then echo "Good Evening $USER"
        elif [[ "$currenttime" > "11:59" ]]; then echo "Good Afternoon $USER"
        elif [[ "$currenttime" > "05:59" ]]; then echo "Good Morning $USER"
        else echo "Good Night $USER"






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 22:44









        kvantourkvantour

        12.3k4 gold badges19 silver badges35 bronze badges




        12.3k4 gold badges19 silver badges35 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • 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%2fstackoverflow.com%2fquestions%2f55364290%2fproblem-with-using-time-check-with-if-statments-bash%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript