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

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

            Get RecordId in LWC From Community PageLWC Community recordId undefinedhow to get Personal Access Token from my integrated application LWC. I am using js onlylwc quick action from Opportunity page(aura:component) and not getting @api recordIdLWC Community recordId undefinedLWC - How to get label name of buttonsLWC: Add a region in custom community themeVisual force page redirection from lightning communityLWC NavigationMixin does not work in CommunityInvoking LWC component from a plain URL - Read URL Parameter inside LWCLWC download PDF fileLWC Get Pick-list Field Values