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?Is 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 rootHow to Run Root Aliases being a non-root user?Why different command scripts are used for the same command when run as a normal user and when run as a root user?

Largest memory peripheral for Sinclair ZX81?

Former Employer just sent me an IP Agreement

Can ThermodynamicData be used with NSolve?

multicol package causes underfull hbox

Are there any symmetric cryptosystems based on computational complexity assumptions?

What color to choose as "danger" if the main color of my app is red

FIFO data structure in pure C

Are spiritual pleasures > carnal pleasures, according to Catholicism?

RegEx with d doesn’t work in if-else statement with [[

Taylor series leads to two different functions - why?

how to create an executable file for an AppleScript?

Why is Drogon so much better in battle than Rhaegal and Viserion?

Why does a table with a defined constant in its index compute 10X slower?

How would fantasy dwarves exist, realistically?

Windows reverting changes made by Linux to FAT32 partion

Will this series of events work to drown a tarrasque?

Failing students when it might cause them economic ruin

Driving a school bus in the USA

Have the writers and actors of GOT responded to its poor reception?

Cryptic crossword (printer's devilry edition)

I just found out that my recent promotion comes with an unexpected 24/7/365 on-call status

Can an airline pilot be prosecuted for killing an unruly passenger who could not be physically restrained?

mirror damper material

Why are there five extra turns in tournament Magic?



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?Is 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 rootHow to Run Root Aliases being a non-root user?Why 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;








3















I make the following bash script in file 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
    6 hours ago











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

    – Hermann Ingjaldsson
    5 hours ago











  • 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
    2 hours ago

















3















I make the following bash script in file 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
    6 hours ago











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

    – Hermann Ingjaldsson
    5 hours ago











  • 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
    2 hours ago













3












3








3








I make the following bash script in file 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 the following bash script in file 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 4 hours ago







Hermann Ingjaldsson

















asked 6 hours ago









Hermann IngjaldssonHermann Ingjaldsson

79741430




79741430












  • 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
    6 hours ago











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

    – Hermann Ingjaldsson
    5 hours ago











  • 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
    2 hours ago

















  • 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
    6 hours ago











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

    – Hermann Ingjaldsson
    5 hours ago











  • 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
    2 hours ago
















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
6 hours ago





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
6 hours ago













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

– Hermann Ingjaldsson
5 hours ago





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

– Hermann Ingjaldsson
5 hours ago













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
2 hours ago





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
2 hours ago










1 Answer
1






active

oldest

votes


















8














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
    3 hours ago






  • 1





    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
    2 hours ago











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

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









8














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
    3 hours ago






  • 1





    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
    2 hours ago















8














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
    3 hours ago






  • 1





    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
    2 hours ago













8












8








8







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 3 hours ago

























answered 6 hours ago









Jesse_bJesse_b

15.5k33675




15.5k33675







  • 4





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

    – Stéphane Chazelas
    3 hours ago






  • 1





    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
    2 hours ago












  • 4





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

    – Stéphane Chazelas
    3 hours ago






  • 1





    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
    2 hours ago







4




4





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

– Stéphane Chazelas
3 hours ago





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

– Stéphane Chazelas
3 hours ago




1




1





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
2 hours ago





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
2 hours ago

















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

Siegen Nawigatsjuun

Log på Navigationsmenu

Log på Navigationsmenu