Error when running ((x++)) as rootWhich shell interpreter runs a script with no shebang?How to hinder root from running a scriptUnable to delete file, even when running as rootError when running X11 application as rootNginx Static Build - Run as root with a non-root userBash root to user. Best in same or separate script?Python imports working for root, but not specific userIs it possible to retain the union of user privileges and root privileges when using sudo?How to stop a script from running if it's not root (and echo “Not running as root! Exiting…”)How to run jhbuild as rootWhy different command scripts are used for the same command when run as a normal user and when run as a root user?

Of strange atmospheres - the survivable but unbreathable

Why does splatting create a tuple on the rhs but a list on the lhs?

How to determine if a hyphen (-) exists inside a column

Are there any German nonsense poems (Jabberwocky)?

Does an eye for an eye mean monetary compensation?

Burned out due to current job, Can I take a week of vacation between jobs?

Why does FOO=bar; export the variable into my environment

Need to read my home electrical Meter

Navigating a quick return to previous employer

How to melt snow without fire or using body heat?

Which European Languages are not Indo-European?

Where is Jon going?

Expected maximum number of unpaired socks

Why did other houses not demand this?

How does the Earth's center produce heat?

How to politely tell someone they did not hit reply all in email?

Is "vegetable base" a common term in English?

Why does Bran want to find Drogon?

What are nvme namespaces? How do they work?

What is the use case for non-breathable waterproof pants?

What were the Ethiopians doing in Xerxes' army?

First Program Tic-Tac-Toe

How to keep consistency across the application architecture as a team grows?

Why isn't 'chemically-strengthened glass' made with potassium carbonate? To begin with?



Error when running ((x++)) as root


Which shell interpreter runs a script with no shebang?How to hinder root from running a scriptUnable to delete file, even when running as rootError when running X11 application as rootNginx Static Build - Run as root with a non-root userBash root to user. Best in same or separate script?Python imports working for root, but not specific userIs it possible to retain the union of user privileges and root privileges when using sudo?How to stop a script from running if it's not root (and echo “Not running as root! Exiting…”)How to run jhbuild as rootWhy different command scripts are used for the same command when run as a normal user and when run as a root user?






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








5















I make bash script temp.sh with the following content:



age=0;
((age++));


When I run it as a normal user, it runs fine.



But when i run it as root I get error:



./temp.sh: 4: ./temp.sh: age++: not found



Why is that?










share|improve this question
























  • Are you using the same shell and settings for both users ? What's the output of echo $SHELL as non-root and as root ?

    – Httqm
    May 16 at 15:22











  • its /bin/bash both as normal user and as root. But Jesse answered.

    – Hermann Ingjaldsson
    May 16 at 17:00











  • The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be your root shell.

    – Isaac
    May 16 at 19:21

















5















I make bash script temp.sh with the following content:



age=0;
((age++));


When I run it as a normal user, it runs fine.



But when i run it as root I get error:



./temp.sh: 4: ./temp.sh: age++: not found



Why is that?










share|improve this question
























  • Are you using the same shell and settings for both users ? What's the output of echo $SHELL as non-root and as root ?

    – Httqm
    May 16 at 15:22











  • its /bin/bash both as normal user and as root. But Jesse answered.

    – Hermann Ingjaldsson
    May 16 at 17:00











  • The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be your root shell.

    – Isaac
    May 16 at 19:21













5












5








5








I make bash script temp.sh with the following content:



age=0;
((age++));


When I run it as a normal user, it runs fine.



But when i run it as root I get error:



./temp.sh: 4: ./temp.sh: age++: not found



Why is that?










share|improve this question
















I make bash script temp.sh with the following content:



age=0;
((age++));


When I run it as a normal user, it runs fine.



But when i run it as root I get error:



./temp.sh: 4: ./temp.sh: age++: not found



Why is that?







root






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 16 at 22:56







Hermann Ingjaldsson

















asked May 16 at 15:18









Hermann IngjaldssonHermann Ingjaldsson

81041630




81041630












  • Are you using the same shell and settings for both users ? What's the output of echo $SHELL as non-root and as root ?

    – Httqm
    May 16 at 15:22











  • its /bin/bash both as normal user and as root. But Jesse answered.

    – Hermann Ingjaldsson
    May 16 at 17:00











  • The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be your root shell.

    – Isaac
    May 16 at 19:21

















  • Are you using the same shell and settings for both users ? What's the output of echo $SHELL as non-root and as root ?

    – Httqm
    May 16 at 15:22











  • its /bin/bash both as normal user and as root. But Jesse answered.

    – Hermann Ingjaldsson
    May 16 at 17:00











  • The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be your root shell.

    – Isaac
    May 16 at 19:21
















Are you using the same shell and settings for both users ? What's the output of echo $SHELL as non-root and as root ?

– Httqm
May 16 at 15:22





Are you using the same shell and settings for both users ? What's the output of echo $SHELL as non-root and as root ?

– Httqm
May 16 at 15:22













its /bin/bash both as normal user and as root. But Jesse answered.

– Hermann Ingjaldsson
May 16 at 17:00





its /bin/bash both as normal user and as root. But Jesse answered.

– Hermann Ingjaldsson
May 16 at 17:00













The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be your root shell.

– Isaac
May 16 at 19:21





The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be your root shell.

– Isaac
May 16 at 19:21










2 Answers
2






active

oldest

votes


















12














In the absence of a hashbang, /bin/sh is likely being used. Some POSIX shells do support the ++ and -- operators, and ((...)) for arithmetic evaluations, but are not required to.



Since you have not included a hashbang in your example I will assume you are not using one and therefore your script is likely running in a POSIX shell that does not support said operator. Such a shell would interpret ((age++)) as the age++ command being run inside two nested sub-shells.



When you run it as a "normal" user it is likely being interpreted by bash or another shell that does support said operator and ((...)).



Related: Which shell interpreter runs a script with no shebang?



To fix this you can add a hashbang to your script:



#!/bin/bash
age=0
((age++))


Note: You do not need to terminate lines with ; in bash/shell.




To make your script portable to all POSIX shells you can use the following syntax:



age=$((age + 1))
age=$((age += 1))





share|improve this answer




















  • 4





    Or use the standard sh syntax: age=$((age + 1)), or : "$((age += 1))"

    – Stéphane Chazelas
    May 16 at 18:46






  • 2





    The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be the root shell.

    – Isaac
    May 16 at 19:19


















1














Another old time answer (or highly multiple platform compatible) is:



 age=`expr $age + 1`





share|improve this answer























    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',
    autoActivateHeartbeat: false,
    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%2f519310%2ferror-when-running-x-as-root%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









    12














    In the absence of a hashbang, /bin/sh is likely being used. Some POSIX shells do support the ++ and -- operators, and ((...)) for arithmetic evaluations, but are not required to.



    Since you have not included a hashbang in your example I will assume you are not using one and therefore your script is likely running in a POSIX shell that does not support said operator. Such a shell would interpret ((age++)) as the age++ command being run inside two nested sub-shells.



    When you run it as a "normal" user it is likely being interpreted by bash or another shell that does support said operator and ((...)).



    Related: Which shell interpreter runs a script with no shebang?



    To fix this you can add a hashbang to your script:



    #!/bin/bash
    age=0
    ((age++))


    Note: You do not need to terminate lines with ; in bash/shell.




    To make your script portable to all POSIX shells you can use the following syntax:



    age=$((age + 1))
    age=$((age += 1))





    share|improve this answer




















    • 4





      Or use the standard sh syntax: age=$((age + 1)), or : "$((age += 1))"

      – Stéphane Chazelas
      May 16 at 18:46






    • 2





      The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be the root shell.

      – Isaac
      May 16 at 19:19















    12














    In the absence of a hashbang, /bin/sh is likely being used. Some POSIX shells do support the ++ and -- operators, and ((...)) for arithmetic evaluations, but are not required to.



    Since you have not included a hashbang in your example I will assume you are not using one and therefore your script is likely running in a POSIX shell that does not support said operator. Such a shell would interpret ((age++)) as the age++ command being run inside two nested sub-shells.



    When you run it as a "normal" user it is likely being interpreted by bash or another shell that does support said operator and ((...)).



    Related: Which shell interpreter runs a script with no shebang?



    To fix this you can add a hashbang to your script:



    #!/bin/bash
    age=0
    ((age++))


    Note: You do not need to terminate lines with ; in bash/shell.




    To make your script portable to all POSIX shells you can use the following syntax:



    age=$((age + 1))
    age=$((age += 1))





    share|improve this answer




















    • 4





      Or use the standard sh syntax: age=$((age + 1)), or : "$((age += 1))"

      – Stéphane Chazelas
      May 16 at 18:46






    • 2





      The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be the root shell.

      – Isaac
      May 16 at 19:19













    12












    12








    12







    In the absence of a hashbang, /bin/sh is likely being used. Some POSIX shells do support the ++ and -- operators, and ((...)) for arithmetic evaluations, but are not required to.



    Since you have not included a hashbang in your example I will assume you are not using one and therefore your script is likely running in a POSIX shell that does not support said operator. Such a shell would interpret ((age++)) as the age++ command being run inside two nested sub-shells.



    When you run it as a "normal" user it is likely being interpreted by bash or another shell that does support said operator and ((...)).



    Related: Which shell interpreter runs a script with no shebang?



    To fix this you can add a hashbang to your script:



    #!/bin/bash
    age=0
    ((age++))


    Note: You do not need to terminate lines with ; in bash/shell.




    To make your script portable to all POSIX shells you can use the following syntax:



    age=$((age + 1))
    age=$((age += 1))





    share|improve this answer















    In the absence of a hashbang, /bin/sh is likely being used. Some POSIX shells do support the ++ and -- operators, and ((...)) for arithmetic evaluations, but are not required to.



    Since you have not included a hashbang in your example I will assume you are not using one and therefore your script is likely running in a POSIX shell that does not support said operator. Such a shell would interpret ((age++)) as the age++ command being run inside two nested sub-shells.



    When you run it as a "normal" user it is likely being interpreted by bash or another shell that does support said operator and ((...)).



    Related: Which shell interpreter runs a script with no shebang?



    To fix this you can add a hashbang to your script:



    #!/bin/bash
    age=0
    ((age++))


    Note: You do not need to terminate lines with ; in bash/shell.




    To make your script portable to all POSIX shells you can use the following syntax:



    age=$((age + 1))
    age=$((age += 1))






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 16 at 18:48

























    answered May 16 at 15:27









    Jesse_bJesse_b

    15.5k33776




    15.5k33776







    • 4





      Or use the standard sh syntax: age=$((age + 1)), or : "$((age += 1))"

      – Stéphane Chazelas
      May 16 at 18:46






    • 2





      The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be the root shell.

      – Isaac
      May 16 at 19:19












    • 4





      Or use the standard sh syntax: age=$((age + 1)), or : "$((age += 1))"

      – Stéphane Chazelas
      May 16 at 18:46






    • 2





      The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be the root shell.

      – Isaac
      May 16 at 19:19







    4




    4





    Or use the standard sh syntax: age=$((age + 1)), or : "$((age += 1))"

    – Stéphane Chazelas
    May 16 at 18:46





    Or use the standard sh syntax: age=$((age + 1)), or : "$((age += 1))"

    – Stéphane Chazelas
    May 16 at 18:46




    2




    2





    The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be the root shell.

    – Isaac
    May 16 at 19:19





    The exact output of ./temp.sh: 4: ./temp.sh: age++: not found is generated by dash running an script called as ./temp.sh. That seems to be the root shell.

    – Isaac
    May 16 at 19:19













    1














    Another old time answer (or highly multiple platform compatible) is:



     age=`expr $age + 1`





    share|improve this answer



























      1














      Another old time answer (or highly multiple platform compatible) is:



       age=`expr $age + 1`





      share|improve this answer

























        1












        1








        1







        Another old time answer (or highly multiple platform compatible) is:



         age=`expr $age + 1`





        share|improve this answer













        Another old time answer (or highly multiple platform compatible) is:



         age=`expr $age + 1`






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 16 at 23:20









        mdpcmdpc

        5,13621838




        5,13621838



























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f519310%2ferror-when-running-x-as-root%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

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?